Limit WordPress user to edit only his own pages

倖福魔咒の 提交于 2019-12-24 17:43:32

问题


I'm looking for the simplest way to limit a WordPress user to edit only his own pages (that is pages he is author of). I've read about some users manager plugins but for my needs they seems overkill and so I wonder if it is possible to obtain the same result adding some code lines to functions.php or something similar.


回答1:


you can do this by adding a new role like so :

<?php add_role( $role, $display_name, $capabilities ); ?> 

This setting is saved to the database (in table wp_options, field wp_user_roles), so it might be better to run this on theme/plugin activation

Returns a WP_Role object on success, null if that role already exists.

Example

Create a new "Basic Contributor" role.

$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.';
}

add_role() is located in wp-includes/capabilities.php.

for more clarification look in this article



来源:https://stackoverflow.com/questions/27679040/limit-wordpress-user-to-edit-only-his-own-pages

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!