我使用以下代码在wordpress中创建了自定义角色。
// register project custom post type
function custom_post_project() {
$args = array(
'label' => 'project',
'public' => true,
'show_ui' => true,
'publicly_queryable' => true,
'capability_type' => 'post',
'hierarchical' => false,
'rewrite' => array('slug' => 'project'),
'query_var' => true,
'menu_icon' => 'dashicons-welcome-learn-more',
'taxonomies' => array('category'),
'supports' => array(
'title',
'editor',
'revisions',
'thumbnail',
),
'capability_type' => array('project', 'projects'),
'map_meta_cap' => true,
);
register_post_type( 'project', $args );
}
add_action( 'init', 'custom_post_project' );
// Add the project_manager role
add_role(
'project_manager',
'Project Manager',
array(
'read' => true,
'edit_posts' => false,
'delete_posts' => false,
'publish_posts' => false,
'upload_files' => true,
)
);
// add capabilities to the role
add_action('admin_init', 'rw_add_project_role_caps', 999);
function rw_add_project_role_caps()
{
// Add the roles you'd like to administer the custom post types
$roles = array('project_manager');
// Loop through each role and assign capabilities
foreach ($roles as $the_role) {
$role = get_role($the_role);
$role->add_cap('read');
$role->add_cap('read_project');
$role->add_cap('read_private_projects');
$role->add_cap('edit_project');
$role->add_cap('edit_projects');
$role->add_cap('edit_others_projects');
$role->add_cap('edit_published_projects');
$role->add_cap('publish_projects');
$role->add_cap('delete_others_projects');
$role->add_cap('delete_private_projects');
$role->add_cap('delete_published_projects');
}
}
当woocommerce
插件未激活时,它可以正常工作。但是当我激活woocommerce
插件时。管理员用户仪表板工作正常。但是角色为project_manager
的用户的worpdress仪表板不起作用。它显示空白页面,没有错误,也没有日志。我不明白是什么打破了project_manager
角色用户的代码。
我也试过User Role Editor WordPress plugin
。这个插件也有同样的问题。
如果您对此有任何疑问,请指导。感谢