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

Asked

Viewed 3,926 times

2

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

Example:

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

inserir a descrição da imagem aqui


As far as I know wordpress does not offer something like default. I tried to use some plug-ins like the Allow and the Members, but in both the lock is made only for the post-type "pages" ie just block access to all pages by hiding the page field from the left menu for blocked users, example:

inserir a descrição da imagem aqui

adminimize panel - "pages" field next to the left add menu for blocked users.


Take into account the following questions:

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

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

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

1 answer

2


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

I advise you to use a plugin to do this. Doing it at hand will take a lot of work. O Role Scoper allows you to allow permissions for pages according to the role (scroll) of the user. It creates several fields where you select users or group of users who can read and/or edit posts/pages.

There is also the User Specific Content, which is more about content than about posts and pages themselves. This may not answer your question, but it’s always good to know that it exists.

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

With the method add_role(). Of 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.';
}

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

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.