事实上,从你的问题来看,并不完全清楚你想要实现什么。但是,wordpress为您提供了创建自定义角色和功能的选项。
如果您遵循本机wordpress路径,则不应担心安全性。
检查角色是否存在如果不添加角色和功能,请确保将功能也传递给管理员
function role_exists( $role ) {
if( ! empty( $role ) ) {
return $GLOBALS[\'wp_roles\']->is_role( $role );
}
return false;
}
二
if( !role_exists( \'customRole\' ) ) {
// $adm = $wp_roles->get_role(\'administrator\');
add_role(\'Role\', __(\'DisplayName\'),
array(
\'read\' => true, // Allows a user to read
\'create_posts\' => false, // Allows user to create new posts
\'edit_posts\' => false, // Allows user to edit their own posts
\'edit_others_posts\' => false, // Allows user to edit others posts too
\'publish_posts\' => false, // Allows the user to publish posts
\'manage_categories\' => false, // Allows user to manage post categories
\'create_pages\' => true,
\'edit_pages\' => true,
\'edit_others_pages\' => true, // Allows user to edit others posts too
\'custom_capibility\' => true,
)
);
}
三
if (role_exists(\'customRole\')){
$administrator = get_role(\'administrator\');
$administrator->add_cap(\'custom_capibilities\');
}
add_role
add cap