問題描述

如何在”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 輔助翻譯的英文資料結果。如果您對結果不滿意,可以加入我們改善翻譯效果:薇曉朵技術論壇。