Allowing users to edit only their page and nobody else’s

We currently have about 50 pages, each of which I want a user (eg, bob, rob, smith) to be able to edit only 1 page. For example, bob & smith each have their own page. I do not want bob to be able to edit smith’s page. I want bob to ONLY be able to edit bob’s page. I don’t care if he can see other pages.
Looking through the user roles, I don’t see a way to currently to do this- I only see how to allow restrict access on a global scale.

Are their any plugins to help restrict edit access per user, or roles restricted to editing specific pages and I can just add 1 user per role? Or was there a way to do this with default settings I missed.

Related posts

Leave a Reply

4 comments

  1. You can add this to your functions.php file in your template to allow the user to edit pages that they have created and manage media. Just specify their $user_id (i.e. 27):

    function add_theme_caps() {
        // to add capability to $user_id
        $user = new WP_User( $user_id );
        $user->add_cap( 'edit_pages' );
        $user->add_cap( 'edit_published_pages' );
        $user->add_cap( 'upload_files' );
    }
    add_action( 'admin_init', 'add_theme_caps' );
    

    You can find a specific user’s $user_id from the URL when you edit a specific user from the WordPress admin page.

    See the full list of WordPress capabilities.

    If you’d rather modify the built in role contributor to allow all users with the contributor role to modify the pages they created:

    function add_theme_caps() {
        // to add capability to the role `contributor`
        $role = get_role( 'contributor' );
        $role->add_cap( 'edit_pages' );
        $role->add_cap( 'edit_published_pages' );
        $role->add_cap( 'upload_files' );
    }
    add_action( 'admin_init', 'add_theme_caps' );
    
  2. Role Scope is very powerful, but I think it’s overkill for this. If you set Bob and Smith to have the role of Author (one of the default roles), they’ll only be able to edit their own posts.

  3. You can also just edit the WP table. Seemed like phpAdmin was going to be a quicker way to go.

    The table is

    wp_usermeta
    

    Search for the user_id, change the value for

    wp_capabilities
    

    and set it to something like

    a:4:{s:11:"contributor";b:1;b:1;s:10:"edit_pages";b:1;s:20:"edit_published_pages";b:1;s:12:"upload_files";b:1;}
    

    I found http://www.unserialize.me/ to be a help in making sure I had the serialization correct (and I expect there are other sites as well)