How to restrict access to a particular page in the admin panel. of wordpress?

2

Inside the wordpress administrative panel, I need to create about 10 pages, where each user only has access to the page that corresponds to him.

Example:

User X would only have access to the admin panel of page X and user Y would only have access to the admin panel of page Y.

AsfarasIknow,wordpressdoesnotprovidesomethinglikedefault.I'vetriedusingsomeplug-inslike Adminimize and Members , but in both the blocking is done only for the post-type "pages" ie they only block the access of all the pages hiding the left-field pages field for blocked users, for example:

Adminimizepanel-"Pages" field on the left side menu for blocked users.

Consider the following questions:

  • How can I create other types of users besides the wordpress default (admin, publisher, subscriber ...)?

NOTE: There is no problem if the proposed solution has to use "post" instead of "pages".

    
asked by anonymous 23.10.2015 / 21:01

1 answer

2
  

How can I create a control similar to that of adminimize but only releasing one page for each user (like the example of the first image)?

I would advise you to use a plugin to do this. Doing on the hand will give a lot of work. The Role Scoper allows you to permissions to pages according to the role (role) of the user. It creates several fields where you select users or groups of users who can read and / or edit posts / pages.

There is also User Specific Content , which is geared more towards content than to posts and pages themselves. This one may not answer your question, but it's always good to know it exists.

  

How can I create other types of users besides the wordpress default (admin, publisher, subscriber ...)?

With the method add_role() . From the documentation itself

$result = add_role(
    'basic_contributor',
    __( 'Basic Contributor' ),
    array(
        'read'         => true,  // true allows this capability
        'edit_posts'   => true,
        'delete_posts' => false, // Use false to explicitly deny
    )
);
if ( null !== $result ) {
    echo 'Yay! New role created!';
}
else {
    echo 'Oh... the basic_contributor role already exists.';
}

Create role Basic Contributor , which has a number of permissions and capabilities. You can see the various roles here .

If you put this method directly in functions.php , for example, the way it is there, you may have problems because this code will always run. The documentation suggests (and I also do) that you create a plugin, which creates the role once, only when the plugin is started. For this you use the hook Register Activation

    
23.10.2015 / 21:20