Reputation: 518
I'm trying to add a new item to WP admin panel which should be visible only for me - admin with a specific email address. I'm using on client sites two different email addresses:
$current_user = wp_get_current_user();
$current_user_email = $current_user->user_email;
if ( current_user_can( 'administrator' ) && $current_user_email == '[email protected]' || $current_user_email == '[email protected]' ) {
function custom_toolbar_link( $wp_admin_bar ) {
$url = esc_url( admin_url( '/theme-editor.php' ) );
$args = array(
'id' => 'theme-editor',
'title' => 'EDITOR',
'href' => $url
);
$wp_admin_bar->add_node( $args );
}
}
add_action( 'admin_bar_menu', 'custom_toolbar_link', 999 );
This is working good, but other admin users are getting this error:
Warning: call_user_func_array() expects parameter 1 to be a valid callback, function 'custom_toolbar_link' not found or invalid function name in /data/5/e/5e7d2c4b-ecbe-4661-b60c-fad9d09a505d/example.com/web/wp-includes/class-wp-hook.php on line 287
Upvotes: 1
Views: 147
Reputation: 3254
The line with add_action
should be inside the if
statement, because the function custom_toolbar_link
is only defined for certain users.
Upvotes: 1