belloli

WordPress: Accessible only by author of the post

Oct 16th, 2011
362
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.10 KB | None | 0 0
  1. <?php
  2. /*
  3.  ********************************************************************************
  4.  *                                      *
  5.  * WordPress: Accessible only by author of the post             *
  6.  * Author: Lucas S. B. Mastella <lucas[at]bello[dot]li>             *
  7.  * Site: www.bello.li                               *
  8.  * Date: 15/10/2011                             *
  9.  *                                      *
  10.  ********************************************************************************
  11.  *                                      *
  12.  * When the user accesses the post, it checks if is logged.         *
  13.  * Check if this is the author of the post, otherwise returns notice.       *
  14.  *                                      *
  15.  ********************************************************************************
  16.  *                                      *
  17.  * This program is free software: you can redistribute it and/or modify     *
  18.  * it under the terms of the GNU General Public License as published by     *
  19.  * the Free Software Foundation, either version 3 of the License, or        *
  20.  * (at your option) any later version.                      *
  21.  *                                      *
  22.  * This program is distributed in the hope that it will be useful.      *
  23.  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
  24.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
  25.  * GNU General Public License for more details.                 *
  26.  *                                      *
  27.  * You should have received a copy of the GNU General Public License        *
  28.  * along with this program.  If not, see <http://www.gnu.org/licenses/>.    *
  29.  *                                      *
  30.  ********************************************************************************
  31.  *
  32.  */
  33. ?>
  34. <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
  35. <?php if ( !is_user_logged_in() ) { ?>
  36.       <!-- # Link -> Login -> Return to same page -->
  37.       <p>If you are the author of this page: <a href="<?php echo wp_login_url( get_permalink() ); ?>" title="Login">Login</a></p>
  38. <?php
  39.    }
  40.    elseif ( $user_ID == get_post($post_id)->post_author ) {
  41.     echo "Is author of this post";
  42.       // Code to show the post
  43.       // See an example: http://codex.wordpress.org/The_Loop#Loop_Examples
  44.    }
  45.    else echo 'You are not the author of this post';
  46. ?>
  47. <?php endwhile; else: ?>
  48. <p>Sorry, no posts matched your criteria.</p>
  49. <?php endif; ?>
Add Comment
Please, Sign In to add comment