我可以使用下面的代码将菜单添加到仪表板,管理员可以查看它。以作者或订阅者身份登录时,不会显示该菜单。如何确保每个用户都可以查看自定义添加的菜单。
//Add Menu Page
add_action( \'admin_menu\', \'register_my_custom_menu_page\' );
function register_my_custom_menu_page(){
add_dashboard_page( \'custom menu title\', \'Test\', \'manage_options\', \'custompage\', \'my_custom_menu_page\', plugins_url( \'test/images/icon.png\' ), 6 );
}
function my_custom_menu_page(){
echo \'<div class="wrap"><div id="icon-tools" class="icon32"></div>\';
echo \'<h2>Test</h2>\';
echo \'Test\';
echo \'</div>\';
}
最合适的回答,由SO网友:tfrommen 整理而成
你必须使用正确的capability 为了这个。您选择了manage_options
, 默认情况下,只有具有Administrator 用户角色具有。
因此,将其更改为read
或exist
, 例如,以及every 用户将能够查看和访问菜单。
add_dashboard_page( \'custom menu title\', \'Test\', \'read\', \'custompage\', \'my_custom_menu_page\', plugins_url( \'test/images/icon.png\' ), 6 );