[英]add, edit, delete pages capability in custom user role
嘗試在Wordpress自定義用戶角色中添加“ 添加,編輯和刪除頁面 ”功能。
我在下面創建一個自定義用戶角色,即“ sub admin ”。 我正在嘗試授予對所有“頁面”功能的訪問權限; 但即使識別出以下內容,也無法正常工作。 (無“添加頁面,顯示當前編輯頁面標簽”)。
也可能需要注意; 我正在嘗試從自定義子主題的/function.php
文件進行此操作。 該角色在下面的代碼(即Sub Admin)之后顯示在WP儀表板中,但是我一直無法成功訪問頁面。
add_role(
'sub_admin',
__( 'Sub Admin' ),
array(
'read' => true,
'edit_posts' => true,
'publish_posts' => true,
'edit_pages' => true,
'edit_others_pages' => true,
'publish_page' => true,
'edit_pages'=>true,
'edit_published_pages'=>true,
'publish_pages'=>true,
'delete_pages'=>true,
'delete_others_pages'=>true,
'delete_published_pages'=>true,
)
);
請嘗試通過以下方法解決您的問題
請確保從add_role
獲取結果已創建您的角色
$result = add_role(/*your args*/);
if ( null !== $result ) {
echo 'Yay! New role created!';
}
else {
echo 'Oh... the basic_contributor role already exists.';
}
如果不行。 請確保在嘗試編輯頁面時具有此sub_admin角色
如果問題仍然存在,請注意Wordpress開發人員指南通知
在第一次調用add_role()之后,角色及其功能將存儲在數據庫中!
順序調用將無濟於事:包括更改功能列表,這可能不是您期望的行為。
也許您需要remove_role()
,然后再次add_role
。 也許您是第一次創建角色但沒有某些功能。
另外,請嘗試使用init操作添加角色
function wporg_simple_role()
{
remove_role('sub_admin');
// or add_role('sub_admin');
}
add_action('init', 'wporg_simple_role');
也許沒有編輯角色,所有管理員功能都是
activate_plugins
delete_others_pages
delete_others_posts
delete_pages
delete_posts
delete_private_pages
delete_private_posts
delete_published_pages
delete_published_posts
edit_dashboard
edit_others_pages
edit_others_posts
edit_pages
edit_posts
edit_private_pages
edit_private_posts
edit_published_pages
edit_published_posts
edit_theme_options
export
import
list_users
manage_categories
manage_links
manage_options
moderate_comments
promote_users
publish_pages
publish_posts
read_private_pages
read_private_posts
read
remove_users
switch_themes
upload_files
customize
delete_site
也許管理欄也取決於manage_options。 您可以通過非管理員頁面來刪除manage_options功能
function change_role() {
global $wp_roles;
if ( ! is_admin() ) {
return;
}
// if not admin page - you could temporary remove manage capabilities from
// sub_admin role
}
add_action('wp', 'change_role');
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.