Advertisement
helgatheviki

Limit Edit.php to display only author's posts

May 2nd, 2014
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.19 KB | None | 0 0
  1. /*
  2.  * Modify query approach approach
  3.  * Based on Sarah Gooding's post
  4.  * http://premium.wpmudev.org/blog/how-to-limit-the-wordpres-posts-screen-to-only-show-authors-their-own-posts/
  5.  */
  6. function mypo_parse_query_useronly( $wp_query ) {
  7.     if ( strpos( $_SERVER[ 'REQUEST_URI' ], '/wp-admin/edit.php' ) !== false ) {
  8.         if ( ! current_user_can( 'edit_others_sebamembers' ) ) {
  9.             global $current_user;
  10.             $wp_query->set( 'author', $current_user->ID );
  11.  
  12.             add_filter('views_edit-seba_members', 'fix_post_counts');
  13.         }
  14.     }
  15. }
  16. add_filter( 'pre_get_posts', 'mypo_parse_query_useronly' );
  17.  
  18.  
  19. /*********************************** OR **********************************************/
  20.  
  21. /*
  22.  * Add query arg approach
  23.  * Based on Kailey Lampert's answer:
  24.  * http://wordpress.stackexchange.com/a/37629/6477
  25.  */
  26. function posts_for_current_author() {
  27.     if ( ! current_user_can( 'edit_others_sebamembers' ) ) {
  28.         global $user_ID;
  29.  
  30.         add_filter('views_edit-seba_members', 'fix_post_counts');
  31.  
  32.         if ( ! isset( $_GET['author'] ) ) {
  33.             wp_redirect( add_query_arg( 'author', $user_ID ) );
  34.             exit;
  35.         }
  36.  
  37.     }
  38. }
  39. add_action( 'load-edit.php', 'posts_for_current_author' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement