User capability of create page/new page

I am working with the Role and Capabilities API for the first time today and making use of the the excellent Members plugin. Having tinkered around for some time I notice that the “edit pages” capability does two things:

  1. Allow the user to create a new page
  2. Allow the user to edit existing pages

I am trying to split this capability into two. I want my user to:

Read More
  1. Not be able to create any new pages
  2. Allow the user to edit existing pages

I am looking to write some code for my theme that allows this to happen. I can create a new capability very easily. The challenge is then getting WordPress to respond accordingly to it.

Any thoughts would be appreciated.

Related posts

Leave a Reply

2 comments

  1. Hi I have been researching this for a while, came up with the following hack.
    In wp-admin/new_post.php add the following, after the wp_die line:

    wp_die( __('Invalid post type') );
    

    if ( !current_user_can( 'manage_options' ) and $post_type == 'page') {
        echo "To create new pages please ask site admin";
        exit;
    } //if user is not admin, a warning is issued and script terminated
    

    then in wp-admin/menu, add a conditional for showing the add page submenu in admin. The line is normally there but not included within the if statement

    if ( current_user_can( 'manage_options' )) { //if user is admin, show submenu for creating new pages, else no luck
       $submenu['edit.php?post_type=page'][10] = array( _x('Add New', 'page'), get_post_type_object( 'page' )->cap->create_posts, 'post-new.php?post_type=page' );
    }
    

    I still have to figure out how to remove the add new button in the edit pages, however users with publish rights can now edit existing pages but not create new pages. If they press the new page button they get a warning and cannot proceed further. Posts are not affected. The same code could easily be applied to prevent the creation of new posts aswell with just little editing.

    Hope this helps – Ackab