Reputation: 63
i want to remove users the ability to add new pages in wordpress. but sill can edit them.
im using Members plugin but for them its all or nothing. i can hide all of the Pages (including the edit and reading capabilities). i have tried a few more big plugins how do the same. so i want to write my on code.
i have found some help but for only part of the problem
for example this code remove only the sidemen but dont remove the add new button in the wp-admin/edit.php?post_type=page page or in the upper menu
function disable_new_pages() {
// Hide sidebar link
global $submenu;
unset($submenu['edit.php?post_type=page'][10]);
// Hide link on listing page
if (isset($_GET['post_type']) && $_GET['post_type'] == 'page') {
echo '<style type="text/css">
#favorite-actions, .add-new-h2, .tablenav { display:none; }
</style>';
}
}
add_action('admin_menu', 'disable_new_pages');
how can i remove this completely
Upvotes: 0
Views: 1688
Reputation: 1271
function hide_add_new_page_button(){
echo ('<style>a[href~="post-new.php?post_type=page"], .page-title-action { display: none !important; }</style>');
}
add_action('admin_head','hide_add_new_page_button');
Upvotes: 0
Reputation: 63
After a long search, I found a solution that help me. And I redirect unwanted users from the page. Simpler than anything (in my opinion)
function my_restrict_access() {
global $pagenow;
if( current_user_can('client') && $pagenow == 'post-new.php' && ! current_user_can( 'publish_posts' ) )
wp_redirect( admin_url() .'/edit.php?post_type=page' );
}
add_action( 'admin_init', 'my_restrict_access', 0 );
Upvotes: 1
Reputation: 79
There are a lot of ways to do that, but lets do it in the easiest/best one :
go to wp-includes/post.php and search for 'capability_type' => 'page',
and add
'capabilities' => array(
'create_posts' => false,
),
It will look like this:
'capability_type' => 'page',
'capabilities' => array(
'create_posts' => false,
),
'map_meta_cap' => true,
'menu_position' => 20,
'map_meta_cap' => true,
// With this set to true, users will still be able to edit & delete posts
Upvotes: 0