Wordpress - Restrict access to plugin only

2019-05-21 13:08发布

问题:

I have created a plugin using Wordpress and I would like to create a user account that ONLY has access to this plugin.

In other words when the user logs in to the wordpress admin panel this plugin is the only thing they see.

回答1:

You can make the menu of the plugin available to the user level's capability. As you can see in WordPress codex,

add_options_page('My Plugin Options', 'My Plugin', 'manage_options', 'my-unique-identifier', 'my_plugin_options');

'manage_options' is a capability of an administrator. A subscriber's capability is 'read', so replace 'manage_options' with 'read' and you'll give access to the subscriber.

This not only works with add_option_page, but also with add_menu_page, add_plugins_page, etc.

Here's a complete list of capabilities.