Advertisement
bcworkz

Restrict WP Post Content

Feb 7th, 2014
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.94 KB | None | 0 0
  1. <?php
  2. /*
  3. Plugin Name: restrict-post-content
  4. Plugin URI: http://wordpress.org/support/topic/only-admins-and-the-post-author-can-view-a-post-is-it-possible
  5. Description: Restrict display of post content to logged in users with email matching the order.
  6. Version: 0.10 beta
  7. Author: bcworkz
  8. Author URI: http://wordpress.org/support/profile/bcworkz
  9. License: GPL2
  10. */
  11. add_filter('the_content', 'rpc_restrict');
  12. function rpc_restrict( $content ) {
  13.     if ( is_user_logged_in() ) {
  14.         global $current_user;
  15.         get_currentuserinfo();
  16.         if ( $current_user->user_email == get_post_meta( get_the_ID(), 'order_email', true ) ||
  17.             current_user_can('edit_others_posts')) $msg = $content;
  18.             else $msg = 'Your <a href="' . admin_url('profile.php') . '" title="Profile Page">profile</a> email must match your order email';
  19.     } else {
  20.         $msg = 'Please <a href="' . wp_login_url( get_permalink() ) . '" title="Login Page">Login</a> to see the order';
  21.     }
  22.     return $msg;
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement