2015-10-06 100 views
-2

我使用的是用戶角色附帶的主題(wordpress)。如果我用admin角色登錄,wp-admin中的所有菜單都會顯示,這是正確的。但是當我從角色訂閱管理員登錄所有管理菜單都隱藏。 我有搜索functions.php但沒有隱藏菜單的代碼。花費大量時間搜索隱藏代碼後,沒有結果。如何獲取菜單隱藏在wordpress中的代碼

有人可以告訴哪些文件可能存在隱藏代碼嗎?搜索代碼花費了大量的時間。

function my_function_admin_bar(){ 
    echo "Access";exit; 
    return true; 
} 
add_filter('show_admin_bar' , 'my_function_admin_bar'); 

updted的functions.php

<?php 
    @ob_start(); 



    define('velocity_FUNCTIONS', get_template_directory() . '/functions/'); 
    define('velocity_THEME', get_template_directory_uri()); 
    define('velocity_JAVASCRIPT', get_template_directory_uri() . '/js'); 
    define('velocity_CSS', get_template_directory_uri() . '/css'); 
    define('velocity_TYPE', get_template_directory_uri() . '/type'); 
    $result = add_role('CustomP', __(

    'Customp'), 

    array(

    'read' => true, // true allows this capability 
    'edit_posts' => true, // Allows user to edit their own posts 
    'edit_pages' => true, // Allows user to edit pages 
    'edit_others_posts' => true, // Allows user to edit others posts not just their own 
    'create_posts' => true, // Allows user to create new posts 
    'manage_categories' => true, // Allows user to manage post categories 
    'publish_posts' => true, // Allows the user to publish, otherwise posts stays in draft mode 
    'edit_themes' => false, // false denies this capability. User can’t edit your theme 
    'install_plugins' => false, // User cant add new plugins 
    'update_plugin' => false, // User can’t update any plugins 
    'update_core' => false // user cant perform core updates 

    ) 

    ); 



    /* Admin Functionality */ 
    if (is_admin()){ 

    function my_function_admin_bar(){ 
     echo "Access";exit; 
     return true; 
    } 
    add_filter('show_admin_bar' , 'my_function_admin_bar'); 
     require_once(velocity_FUNCTIONS . '/page_options/theme_page_options.php'); 
     require_once(velocity_FUNCTIONS . '/theme_options/theme_settings.php'); 
     if(function_exists("wpb_map")){ 
      require_once(velocity_FUNCTIONS . '/theme_builder.php'); 
     } 
     require_once(velocity_FUNCTIONS . '/thundercodes/thundericons.php'); 
     if(get_option('velocity_first_import')!="on"){ 
      require_once(velocity_FUNCTIONS . '/theme_activate.php'); 
     } 
     require_once(velocity_FUNCTIONS . '/theme_plugins.php'); 
     require_once(velocity_FUNCTIONS . '/theme_startmessage.php'); 
     require_once(velocity_FUNCTIONS . '/theme_featured_image_preview.php'); 
     require_once(velocity_FUNCTIONS . '/theme_docu.php'); 
    } 

    require_once(velocity_FUNCTIONS . '/navigation/sweet-custom-menu.php'); 

    /* Theme Functionality */ 
    require_once(velocity_FUNCTIONS . '/theme_support.php'); 
    require_once(velocity_FUNCTIONS . '/aq_resize.php'); 
    require_once(velocity_FUNCTIONS . '/theme_functions.php'); 
    require_once(velocity_FUNCTIONS . '/theme_pagination.php'); 
    require_once(velocity_FUNCTIONS . '/theme_javascriptcss.php'); 
    require_once(velocity_FUNCTIONS . '/theme_widgets.php'); 
    require_once(velocity_FUNCTIONS . '/theme_sidebars.php'); 
    require_once(velocity_FUNCTIONS . '/theme_post_comments.php'); 
    require_once(velocity_FUNCTIONS . '/theme_breadcrumbs.php'); 

    if(!is_admin()){ 

    require_once(velocity_FUNCTIONS . '/theme_options/theme_style_generate.php'); 
    } 

    /* Theme Language */ 
    require_once(velocity_FUNCTIONS . '/theme_language.php'); 

    /* Media Box */ 
    function load_media_box(){ 
    if(function_exists(wp_enqueue_media())) wp_enqueue_media(); 
    } 
    add_action('admin_enqueue_scripts', 'load_media_box'); 
    ?> 
    <?php 


    function my_login_redirect($redirect_to, $request) { 
    $redirect_url = get_bloginfo('url') . '/wp-admin/'; 

    return $redirect_url; 
    } 
    add_filter("login_redirect", "my_login_redirect", 10, 3); 



    /* new code */ 
     /* 
     global $wp_roles; 
     foreach ($wp_roles->role_names as $role => $name) : 
     if (current_user_can($role)) 
       echo 'This user has a role of ' . $role; 
     endforeach;*/ 

    ?> 
+0

是菜單代碼「水漲船高」 /不是在頁面可言,或者它只是隱藏的CSS?打開瀏覽器的控制檯/使用它查看代碼並找出答案。 – Epodax

+0

可能重複的[爲什麼menubar藏在WordPress的管理員](http://stackoverflow.com/questions/32951357/why-menubar-is-hiding-in-wordpress-admin) – cgee

+0

我也檢查代碼,但沒有得到任何線索 – raj

回答

1

這是要隱藏來自特定用戶/用戶組管理菜單中的選項。您可以啓用/通過編輯用戶禁用該功能,選中/取消:

顯示工具欄瀏覽網站的時候


UPDATE或者,你可以使用show_admin_bar(true)來在主題中顯示functions.php的管理欄。

if(is_admin()) { 
    show_admin_bar(true); 
} 

參考:https://codex.wordpress.org/Function_Reference/show_admin_bar

+0

我不想改變用戶角色。哪裏可以隱藏菜單的代碼 – raj

+0

你不必這樣做。這是每個用戶的權限。 – Raptor

+0

我可以更改使用php代碼的權限,而不是手動更改 – raj

相關問題