好的,我已经做到了。
阅读有关角色和功能的信息:http://codex.wordpress.org/Roles_and_Capabilities
为每个角色预先分配了一组默认功能,但可以使用add\\u cap()和remove\\u cap()函数分配或删除其他功能。可以使用add\\u role()和remove\\u role()函数引入或删除新角色。
添加功能:http://codex.wordpress.org/Function_Reference/add_cap
如果要添加具有功能的新角色,只需在使用add\\u role();添加角色时添加这些功能即可;。
阅读有关添加菜单的信息:http://codex.wordpress.org/Function_Reference/add_menu_page
$capability(string)(必选)向用户显示此菜单所需的功能。
Step 1: Register an activation hook to create a new user role
register_activation_hook( __FILE__, \'plugin_newuserrole\' );
function plugin_newuserrole() {
global $wp_roles;
$result = add_role(
\'user_dj\',
__( \'DJ\' ),
array(
\'read\' => true, // true allows this capability
)
);
/* if ( null !== $result ) {
echo \'Yay! New role created!\';
}
else {
echo \'Oh... the user_dj role already exists.\';
} */
}
Step 2: Add a capability to the role
function plugin_caps() {
// gets the new role made earlier
$role = get_role( \'user_dj\' );
// This only works, because it accesses the class instance.
// would allow the author to edit others\' posts for current theme only
$role->add_cap( \'dj_hk_user\' );
}
add_action( \'admin_init\', \'plugin_caps\');
Step 3: Change capability options in menu and submenu
function add_your_menu() {
add_menu_page( \'Title\', \'Menu Label\', \'dj_hk_user\', \'plugin-slug.php\', \'\', \'dashicons-microphone\');
add_submenu_page( \'plugin-slug.php\', \'Overview\', \'Overview\', \'dj_hk_user\', \'plugin-slug.php\', \'function_of_overview\' );
add_submenu_page( \'plugin-slug.php\', \'Sample Edit Title\', \'Sample Edit Label\', \'dj_hk_user\', \'sample_slug\', \'function_of_page1\' );
}
add_action(\'admin_menu\', \'add_your_menu\');