Advertisement
Guest User

Untitled

a guest
Jan 27th, 2017
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.90 KB | None | 0 0
  1. /*
  2. Plugin Name: Exclude pages from admin
  3. Plugin URI: https://www.johnparris.com/
  4. Description: Removes pages from admin that shouldn't be edited.
  5. Version: 1.0
  6. Author: John Parris
  7. Author URI: https://www.johnparris.com/
  8. License: GPLv2
  9. */
  10.  
  11. function jp_exclude_pages_from_admin($query) {
  12.  
  13. $blogpage = get_page_by_title( 'Blog' );
  14.  
  15.   if ( ! is_admin() )
  16.     return $query;
  17.  
  18.   global $pagenow, $post_type;
  19.  
  20.   if ( $pagenow == 'edit.php' && $post_type == 'page' )
  21.     $query->query_vars['post__not_in'] = array($blogpage->ID); // Enter your page IDs here
  22. }
  23.  
  24. add_filter( 'parse_query', 'jp_exclude_pages_from_admin' );
  25.  
  26. // Remove the Edit link from the admin bar
  27. function jp_remove_admin_bar_edit_link() {
  28.  
  29.   if( is_page('blog')) {
  30.      
  31.     global $wp_admin_bar;
  32.     $wp_admin_bar->remove_menu( 'edit' );
  33.   }
  34. }
  35. add_action( 'wp_before_admin_bar_render', 'jp_remove_admin_bar_edit_link' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement