Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Remove Gravatar on Admin Bar (Hintergründe: http://talkpress.de/artikel/wordpress-admin-bar-datenkrake-missbrauch)
<?php
/**
* Plugin Name: Remove Gravatar on Admin Bar
* Plugin URI: http://talkpress.de/artikel/wordpress-admin-bar-datenkrake-missbrauch
* Description: Remove Gravatar on Admin Bar
* Version: 1.0.0
* Author: Frank Bültge
* Author URI: http://bueltge.de
* License: GPLv3
*/
// This file is not called from WordPress. We don't like that.
! defined( 'ABSPATH' ) and exit;
// If the function exists this file is called as comments template.
// We don't do anything then.
if ( ! function_exists( 'fb_admin_bar_init' ) ) {
add_action( 'init', 'fb_admin_bar_init' );
function fb_admin_bar_init() {
remove_action( 'admin_bar_menu', 'wp_admin_bar_my_account_menu', 0 );
remove_action( 'admin_bar_menu', 'wp_admin_bar_my_account_item', 7 );
add_action( 'admin_bar_menu', 'fb_admin_bar_my_account_menu', 0 );
add_action( 'admin_bar_menu', 'fb_admin_bar_my_account_item', 7 );
}
function fb_admin_bar_my_account_menu( $wp_admin_bar ) {
$user_id = get_current_user_id();
$current_user = wp_get_current_user();
$profile_url = get_edit_profile_url( $user_id );
if ( ! $user_id )
return;
$wp_admin_bar->add_group( array(
'parent' => 'my-account',
'id' => 'user-actions',
) );
$user_info = "<span class='display-name'>{$current_user->display_name}</span>";
if ( $current_user->display_name !== $current_user->user_nicename )
$user_info .= "<span class='username'>{$current_user->user_nicename}</span>";
$wp_admin_bar->add_menu( array(
'parent' => 'user-actions',
'id' => 'user-info',
'title' => $user_info,
'href' => $profile_url,
'meta' => array(
'tabindex' => -1,
),
) );
$wp_admin_bar->add_menu( array(
'parent' => 'user-actions',
'id' => 'edit-profile',
'title' => __( 'Edit My Profile' ),
'href' => $profile_url,
) );
$wp_admin_bar->add_menu( array(
'parent' => 'user-actions',
'id' => 'logout',
'title' => __( 'Log Out' ),
'href' => wp_logout_url(),
) );
}
function fb_admin_bar_my_account_item( $wp_admin_bar ) {
$user_id = get_current_user_id();
$current_user = wp_get_current_user();
$profile_url = get_edit_profile_url( $user_id );
if ( ! $user_id )
return;
$howdy = sprintf( __('Howdy, %1$s'), $current_user->display_name );
$wp_admin_bar->add_menu( array(
'id' => 'my-account',
'parent' => 'top-secondary',
'title' => $howdy,
'href' => $profile_url,
'meta' => array(
'title' => __('My Account'),
),
) );
}
} // end if
@ocean90

This comment has been minimized.

Copy link

ocean90 commented Feb 2, 2012

@bueltge

This comment has been minimized.

Copy link
Owner Author

bueltge commented Feb 2, 2012

@kmvan

This comment has been minimized.

Copy link

kmvan commented Feb 25, 2020

What's the fb_ means?

@kmvan

This comment has been minimized.

Copy link

kmvan commented Feb 25, 2020

Looks like not working in version 5.3.2.

@bueltge

This comment has been minimized.

Copy link
Owner Author

bueltge commented Feb 25, 2020

What's the fb_ means?

That's only a prefix for clear namespace to remove problems with other functions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.