问题
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
回答1:
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
回答2:
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 );
来源:https://stackoverflow.com/questions/58628846/remove-the-add-new-page-with-no-plugins