admin管理员组文章数量:1122832
i'm trying to create a custom role, very similar to admin but without the capabilities to edit/delete plugins. Since i don't wont to use plugin for that i've edited the functions.php file adding something like this:
// Add a custom user role
$result = add_role( 'new_role', __(
'New Role' ),
array(
'edit_posts' => true, // Allows user to edit their own posts
'edit_pages' => true, // Allows user to edit pages
'edit_others_posts' => true, // Allows user to edit others posts not just their own
'create_posts' => true, // Allows user to create new posts
'manage_categories' => true, // Allows user to manage post categories
'publish_posts' => true, // Allows the user to publish, otherwise posts stays in draft mode
'edit_themes' => true, // false denies this capability. User can’t edit your theme
'install_plugins' => false, // User cant add new plugins
'update_plugin' => true, // User can’t update any plugins
'update_core' => false // user cant perform core updates
)
);
After that i can create with my admin profile a new user and assign him the role i just created. All good untill the moment i log in with the new user when i have only access to the front page of the website.
I tried to add /wp-admin after the url but i get the message:
Sorry, you are not allowed to access this page.
I've tried to add this line in the array above
'manage_options' => true, //not sure about that
but without success, the block remains
Question: How i can, without installing plugins, make a custom user role access the control panel?
Thanks, y'all
i'm trying to create a custom role, very similar to admin but without the capabilities to edit/delete plugins. Since i don't wont to use plugin for that i've edited the functions.php file adding something like this:
// Add a custom user role
$result = add_role( 'new_role', __(
'New Role' ),
array(
'edit_posts' => true, // Allows user to edit their own posts
'edit_pages' => true, // Allows user to edit pages
'edit_others_posts' => true, // Allows user to edit others posts not just their own
'create_posts' => true, // Allows user to create new posts
'manage_categories' => true, // Allows user to manage post categories
'publish_posts' => true, // Allows the user to publish, otherwise posts stays in draft mode
'edit_themes' => true, // false denies this capability. User can’t edit your theme
'install_plugins' => false, // User cant add new plugins
'update_plugin' => true, // User can’t update any plugins
'update_core' => false // user cant perform core updates
)
);
After that i can create with my admin profile a new user and assign him the role i just created. All good untill the moment i log in with the new user when i have only access to the front page of the website.
I tried to add /wp-admin after the url but i get the message:
Sorry, you are not allowed to access this page.
I've tried to add this line in the array above
'manage_options' => true, //not sure about that
but without success, the block remains
Question: How i can, without installing plugins, make a custom user role access the control panel?
Thanks, y'all
Share Improve this question asked Nov 7, 2020 at 19:25 JackJack 211 bronze badge1 Answer
Reset to default 0With help of following code you can make a custom user role access the control panel. Following code works on hooks admin_init
or init
add_action( 'admin_init', 'my_custom_function' );
function my_custom_function() {
add_role( 'new_role', 'New Role' );
$role = get_role( 'new_role' );
$role->add_cap( 'edit_posts' );
$role->add_cap( 'edit_pages' );
$role->add_cap( 'edit_others_posts' );
$role->add_cap( 'create_posts' );
$role->add_cap( 'manage_categories' );
$role->add_cap( 'publish_posts' );
$role->add_cap( 'edit_themes' );
$role->add_cap( 'install_plugins', false );
$role->add_cap( 'update_plugin' );
$role->add_cap( 'update_core', false );
// add more capabilities as per you requirements
}
本文标签: functionsCustom roles can39t access to wpadmin
版权声明:本文标题:functions - Custom roles can't access to wp-admin 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736299277a1930414.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论