Want more features on Pastebin? Sign Up, it's FREE!
Guest

Restrict WP Post Content

By: bcworkz on Feb 7th, 2014  |  syntax: PHP  |  size: 0.94 KB  |  views: 50  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  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. }
clone this paste RAW Paste Data