2017-07-17 74 views
0

我試圖爲「編輯器」角色顯示我的插件菜單/選項頁面,但它不顯示。如何解決這個問題?謝謝。如何在WordPress中顯示編輯器用戶角色的WP插件菜單

這裏是我的代碼:

function jowct_add_plugin_for_editors(){ 
 
    if (!current_user_can('manage_options')) { 
 
    add_menu_page(
 
\t \t \t 'Menu Page Title', 
 
\t \t \t 'Menu Title', 
 
\t \t \t 'delete_others_pages', 
 
\t \t \t 'jowct-wpplugin-menu', 
 
\t \t \t 'jowct_menu_option_page', 
 
\t \t \t 'dashicons-admin-generic', 
 
\t \t \t '3', 
 
\t \t); 
 
    } 
 
} 
 
if(is_admin()) { 
 
    add_action('admin_menu', 'jowct_add_plugin_for_editors'); 
 
}

回答

0

可以刪除if完全。 (雙方) 你不需要太多檢查manage_options因爲你已經檢查delete_others_pages
更多信息https://codex.wordpress.org/Roles_and_Capabilities

function jowct_add_plugin_for_editors(){ 
    add_menu_page(
      'Menu Page Title', 
      'Menu Title', 
      'delete_others_pages', //this will restrict access 
      'jowct-wpplugin-menu', 
      'jowct_menu_option_page', 
      'dashicons-admin-generic', 
      '3' // this comma was incorrect syntax 
     ); 
} 
// action admin_menu will only trigger in the admin, no need for the if. 
add_action('admin_menu', 'jowct_add_plugin_for_editors'); 
+0

感謝您花時間查看我的代碼和您的反饋意見。我試圖實現你的代碼,但它沒有奏效。當我刪除if時,它在管理員角色admin區域創建了一個新菜單。菜單仍然不顯示在編輯角色管理區域中。 – jojoi

0

謝謝大家,我只是解決了這個問題。 在這種情況下,我想將插件主菜單&子菜單顯示爲管理員角色。編輯角色只能訪問主菜單。 關鍵是將主菜單功能設置爲編輯功能,例如「moderate_comments」,這樣管理員和編輯人員都可以訪問此主菜單。

對於子菜單,將能力設置爲「manage_options」。這樣,只有管理員才能看到這個子菜單。 查看此表格: https://codex.wordpress.org/Roles_and_Capabilities

相關問題