2016-01-12 47 views
-3

在我的WordPress網站中有兩個管理員角色,但我需要隱藏管理面板中選定管理角色的一些頁面,所以我只是在尋找隱藏某些頁面的方式WordPress管理部分。但某些角色可能需要顯示隱藏頁面。如何從WordPress管理端隱藏頁面

我只是添加一個示例圖像來獲得關於此的一個想法。 根據圖像我想隱藏接觸從ABC管理角色在管理面板的頁面,它應該是在管理面板XYZ管理員的角色可見。希望你們能幫忙。

Sample Image

回答

1

對於角色明智的嘗試在陣列這段代碼 使用頁面ID。

add_action('pre_get_posts' ,'exclude_this_page'); 
function exclude_this_page($query) { 

global $pagenow; 
global $current_user; 
$user_roles = $current_user->roles; 

if($user_roles[0] == 'administrator'){ 
    return $query; 
} 

if($user_roles[0] == 'editor'){ 
    if('edit.php' == $pagenow && 'page' == get_query_var('post_type') ) 
     $query->set('post__not_in', array(20,25)); 
} 
return $query; 
} 
0

將這個代碼在你function.php文件

add_action('pre_get_posts' ,'exclude_this_page'); 
function exclude_this_page($query) { 
$user_id = get_current_user_id(); 
     // If XYZ admin id is 23 
     if($user_id != 23) 
       return $query; 
     global $pagenow; 

     if('edit.php' == $pagenow && (get_query_var('post_type') && 'page' == get_query_var('post_type'))) 
       $query->set('post__not_in', array(10,14)); // array page ids(contact us and abous us page ids) 
     return $query; 
} 
0

請試試這個代碼..只能插入排除頁面,管理員ID從 ADD_ACTION排除( 'pre_get_posts', 'exclude_this_page');

function exclude_this_page($query) { 
     //current user ID 
     $user_id = get_current_user_id(); 

     //Ids of users to exclude 
     $excluded_users = array(1,2,3); 

     //Ids of pages to be excluded 
     $excluded_pages = array(10,20,30); 

     global $pagenow; 

     if('edit.php' == $pagenow && (get_query_var('post_type') && 'page' == get_query_var('post_type'))){ 

       if(in_array($user_id,$excluded_users)){ 
        $query->set('post__not_in', $excluded_pages); 
       } 
     } 
     return $query; 

    } 
相關問題