3

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

5

Please 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' );`

Refer my tutorial for further explanation. http://www.pearlbells.co.uk/user-role-editor-access-wordpress-plugins/

3

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

3
  • I tried your suggestion but did not worked for me. Can you give more details of how to accoplish that?, please – Alejo_Blue Jun 19 '18 at 16:35
  • Okay, do you need a sample Plugin code snippet on Github? That should work – user123451 Jun 20 '18 at 17:30
  • exactly ! it works like a charm thanks a lot – Youssef May 15 '20 at 3:56
0

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');
0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.