admin管理员组文章数量:1122832
I created a custom plugin which i want Users who are Editors to be able to use the plugin.
I found a link here to allow access for editors to allow editors to edit menusallow editors to edit menus?
using this code.
$role_object = get_role( 'editor' );
// add $cap capability to this role object
$role_object->add_cap( 'edit_theme_options' );
So, is there a possible way i can allow Editors access to my custom added plugins
I created a custom plugin which i want Users who are Editors to be able to use the plugin.
I found a link here to allow access for editors to allow editors to edit menusallow editors to edit menus?
using this code.
$role_object = get_role( 'editor' );
// add $cap capability to this role object
$role_object->add_cap( 'edit_theme_options' );
So, is there a possible way i can allow Editors access to my custom added plugins
Share Improve this question edited Apr 13, 2017 at 12:37 CommunityBot 1 asked Mar 30, 2015 at 13:18 user123451user123451 1731 gold badge1 silver badge8 bronze badges4 Answers
Reset to default 3Please add the following code.
function activate_plugin_name() {
$role = get_role( 'editor' );
$role->add_cap( 'manage_options' ); // capability
}
// Register our activation hook
register_activation_hook( __FILE__, 'activate_plugin_name' );
function deactivate_plugin_name() {
$role = get_role( 'editor' );
$role->remove_cap( 'manage_options' ); // capability
}
// Register our de-activation hook
register_deactivation_hook( __FILE__, 'deactivate_plugin_name' );`
After a quick search, i got my answer here
https://wordpress.org/support/topic/how-to-allow-non-admins-editors-authors-to-use-certain-wordpress-plugins
By changing all occurances of 'manage_options' to 'edit_pages' in my Plugins files.
Editors are allowed to use plugins with Edit_pages
This is just a use case of a need to activate a plugin for "editor" user role. The plugin is called bulk images to posts. This plugin is active only for admin role. So to activate it for "editor" role, you have to go through the "bulk-images-to-posts.php" file and search for big_create_menu() function (responsible of creating a menu in the left admin bar) Now if you replace "manage_options" by "edit_pages" you will see that in "editor" role admin menu, the plugin becomes active. Again this is just an example of 1 use case to show the effect of "edit_pages"
Here is a code snippet showing this:
// create new top-level menu
global $bip_admin_page;
$bip_admin_page = add_menu_page(__('Bulk Images to Posts Uploader','bulk-images-to-posts'), __('Bulk','bulk-images-to-posts'), 'edit_pages', 'bulk-images-to-post','bip_upload_page','dashicons-images-alt2');
// create submenu pages
add_submenu_page( 'bulk-images-to-post', __('Bulk Images to Post - Upload','bulk-images-to-posts'), __('Uploader','bulk-images-to-posts'), 'edit_pages', 'bulk-images-to-post');
Thanks Liz Eipe for your solution, but unfortunately that did not work for me. What did work for me, was changing the 'capability' for all the add_menu_page() and the add_submenu_page() hooks.
Basically the capability value you set, corresponds to access for different types and combinations of users. You can view all the possible capabilities and their access here.
I choose 'publish_posts' as value, which gives Super Admin, Admin, Editor and Author access to the admin page you register with your hooks.
This was my code before:
add_menu_page(
'My Menu Title',
'custom menu',
'administrator', // Only a admin access
'myplugin/myplugin-admin.php',
'',
plugins_url( 'myplugin/images/icon.png' ),
3
);
And now with Admin, Editor and Author access it's changed to:
add_menu_page(
'My Menu Title',
'custom menu',
'publish_posts', // Admin, Editor, Author access
'myplugin/myplugin-admin.php',
'',
plugins_url( 'myplugin/images/icon.png' ),
3
);
One last small note; do not forget to change this for all the plugin admin pages you want other users to have access to, like all the submenu pages.
本文标签: user rolesAllow editors access to added plugins
版权声明:本文标题:user roles - Allow editors access to added plugins 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736309405a1934009.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论