更改主机后,缺少参数1 for give_profile_name()错误

时间:2016-08-30 14:02:56

标签: php wordpress web wordpress-theming

我最近改变了主人。在此之后我发现了一个错误。我在Displaying Logged-In User Name in Wordpress Menu使用了一段代码 显示用户名而不是“个人资料页面”。它在前一个主机上运行正常。复制完所有内容和数据后,我在菜单栏上看到此错误。用户在登录时会看到此内容。请建议补救措施。

enter image description here

以下是我使用的代码。它与我发布的stackoverflow链接上给出的完全相同。我已经在链接中提到了#profile_name#页面。

function give_profile_name($atts){
$user=wp_get_current_user();
$name=$user->user_firstname .' '. $user->user_lastname ; 
return $name;
}

add_shortcode('profile_name', 'give_profile_name');

add_filter( 'wp_nav_menu_objects', 'my_dynamic_menu_items' );
function my_dynamic_menu_items( $menu_items ) {
foreach ( $menu_items as $menu_item ) {
    if ( '#profile_name#' == $menu_item->title ) {
        global $shortcode_tags;
        if ( isset( $shortcode_tags['profile_name'] ) ) {
            // Or do_shortcode(), if you must.
            $menu_item->title = call_user_func( $shortcode_tags['profile_name'] );
        }    
    }
}

return $menu_items;
} 

1 个答案:

答案 0 :(得分:1)

不确定你是否仍然对此作出答案,但我想我仍会回复,因为我在尝试将用户的名字添加到导航菜单时遇到了同样的错误和相同的代码片段。我注意到它仍然在工作,尽管有错误,所以在玩完之后,我只是从函数中删除了$atts。所以代码的第一部分是:

function give_profile_name(){
$user=wp_get_current_user();
$name=$user->user_firstname .' '. $user->user_lastname ; 
return $name;
}