wordpress 使用本地头像

时间 : 15-07-19 栏目 : 网站架构 作者 : 老薛 评论 : 0 点击 : 1,121 次

WordPress默认的头像是读取gravatar.com上的图片的,对于国内用户来说会使网页打开速度变慢,严重者甚至无法访问,笔者也是感同身受。工作之余,细细研读代码,找到一个解决办法,供大家参考:

#后台管理界面右上角26×26的图片 显示

[root@bdkyr www.bdkyr.com]# vim wp-includes/admin-bar.php

function wp_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;

        //$avatar = get_avatar( $user_id, 26 );

        //将网站域名和模板名字更换为你自己的

        $avatar = "<img alt='' src='http://网站域名/wp-content/themes/模板名字/images/admin_logo.jpg' class='avatar ava
tar-26 photo' height='26' width='26' />";
        $howdy  = sprintf( __('Howdy, %1$s'), $current_user->display_name );
        $class  = empty( $avatar ) ? '' : 'with-avatar';

        $wp_admin_bar->add_menu( array(
                'id'        => 'my-account',
                'parent'    => 'top-secondary',
                'title'     => $howdy . $avatar,
                'href'      => $profile_url,
                'meta'      => array(
                        'class'     => $class,
                        'title'     => __('My Account'),
                ),

        ) );
}

#后台管理界面右上角64×64的图片 显示

function wp_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  = get_avatar( $user_id, 64 );
        $user_info = "<img alt='' src='http://www.bdkyr.com/wp-content/themes/muchun/images/admin_logo_64.jpg' class='avat
ar avatar-64 photo' height='64' width='64' />";
        $user_info .= "<span class='display-name'>{$current_user->display_name}</span>";

        if ( $current_user->display_name !== $current_user->user_login )
                $user_info .= "<span class='username'>{$current_user->user_login}</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(),
        ) );

}

修改完毕,保存,刷新页面,期待已久的头像终于出来了。

本文标签

除非注明,文章均为( 老薛 )原创,转载请保留链接: http://www.bdkyr.com/architecture/830.html

博主微信号,很高兴为您提供帮助

随便看看

为您推荐

0