我想在WP管理面板上添加一个新的项目,这个项目应该只有我一个人可见--拥有特定电子邮件地址的管理员。我在客户网站上使用了两个不同的电子邮件地址。
$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 );
这样做很好,但其他管理员用户得到这个错误。
Warning: call_user_func_array() expects parameter 1 to be a valid callback, function 'custom_toolbar_link' not found or invalid function name in data5e5e7d2c4b-ecb-4661-b60c-fad9d09a505dexample.comwebwp-includesclass-wp-hook.php on line 287.
该行与 add_action
应在 if
语句,因为函数 custom_toolbar_link
只为某些用户定义。