問題描述
如何在”my-account-with-avatar” 管理員選單欄下刪除 「編輯您的個人資料」 子選單,同時仍然保持頭像和登出?
最佳解決辦法
管理選單欄中有一個 remove_menu 鉤子。
你想掛接到 $wp_admin_bar 的類,你可以在這裡看到 remove 功能,因為沒有檔案 (第 86 行),它應該使用子選單 ID 。
http://core.trac.wordpress.org/browser/tags/3.2.1/wp-includes/class-wp-admin-bar.php
既然你似乎不相信我這裡是程式碼………
function ya_do_it_admin_bar_remove() {
global $wp_admin_bar;
/* **edit-profile is the ID** */
$wp_admin_bar->remove_menu('edit-profile');
}
add_action('wp_before_admin_bar_render', 'ya_do_it_admin_bar_remove', 0);
次佳解決辦法
WordPress 推出了新的 stufs(節點) 。
我正在搜尋完全刪除 「使用者帳戶」 框,並新增一個簡單的登出:
//http://codex.wordpress.org/Function_Reference/get_nodes
//http://codex.wordpress.org/Function_Reference/add_node
add_action( 'admin_bar_menu', 'remove_my_account', 999 );
function remove_my_account( $wp_admin_bar ) {
$wp_admin_bar->remove_node( 'my-account' );
}
add_action( 'admin_bar_menu', 'add_logout', 999 );
function add_logout( $wp_admin_bar ) {
$args = array(
'id' => 'logout', // id of the existing child node (New > Post)
'title' => 'Se déconnecter', // alter the title of existing node
'parent' => 'top-secondary', // set parent
);
$wp_admin_bar->add_node( $args );
}
參考文獻
注:本文內容整合自 Google/Baidu/Bing 輔助翻譯的英文資料結果。如果您對結果不滿意,可以加入我們改善翻譯效果:薇曉朵技術論壇。