麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 網(wǎng)站 > 建站經(jīng)驗(yàn) > 正文

為wordpress添加本地頭像功能代替Gravatar

2024-04-25 20:39:13
字體:
供稿:網(wǎng)友

目前wordpress網(wǎng)站幾乎都是使用Gravatar全球通頭像來關(guān)聯(lián)用戶頭像的,但是由于Gravatar的服務(wù)器是在國外,國內(nèi)經(jīng)常由于某些XXX原因而連接不上,今天就來教大家使用代碼將Gravatar頭像半本地化,那么什么是半本地化呢?也就是通過用戶的郵箱判斷用戶是否擁有Gravatar頭像,如果擁有則使用Gravatar頭像,當(dāng)用戶擁有本地頭像且擁有Gravatar頭像時(shí),則優(yōu)先使用本地頭像。

<?php

class Simple_Local_Avatars {

private $user_id_being_edited;

public function __construct() {

add_filter( 'get_avatar', array( $this, 'get_avatar' ), 10, 5 );

add_action( 'admin_init', array( $this, 'admin_init' ) );

add_action( 'show_user_profile', array( $this, 'edit_user_profile' ) );

add_action( 'edit_user_profile', array( $this, 'edit_user_profile' ) );

add_action( 'personal_options_update', array( $this, 'edit_user_profile_update' ) );

add_action( 'edit_user_profile_update', array( $this, 'edit_user_profile_update' ) );

add_filter( 'avatar_defaults', array( $this, 'avatar_defaults' ) );

}

public function get_avatar( $avatar = '', $id_or_email, $size = 96, $default = '', $alt = false ) {

if ( is_numeric($id_or_email) )

$user_id = (int) $id_or_email;

elseif ( is_string( $id_or_email ) && ( $user = get_user_by( 'email', $id_or_email ) ) )

$user_id = $user->ID;

elseif ( is_object( $id_or_email ) && ! emptyempty( $id_or_email->user_id ) )

$user_id = (int) $id_or_email->user_id;

if ( emptyempty( $user_id ) )

return $avatar;

$local_avatars = get_user_meta( $user_id, 'simple_local_avatar', true );

if ( emptyempty( $local_avatars ) || emptyempty( $local_avatars['full'] ) )

return $avatar;

$size = (int) $size;

if ( emptyempty( $alt ) )

$alt = get_the_author_meta( 'display_name', $user_id );

// generate a new size

if ( emptyempty( $local_avatars[$size] ) ) {

$upload_path = wp_upload_dir();

$avatar_full_path = str_replace( $upload_path['baseurl'], $upload_path['basedir'], $local_avatars['full'] );

$image_sized = image_resize( $avatar_full_path, $size, $size, true );

// deal with original being >= to original image (or lack of sizing ability)

$local_avatars[$size] = is_wp_error($image_sized) ? $local_avatars[$size] = $local_avatars['full'] : str_replace( $upload_path['basedir'], $upload_path['baseurl'], $image_sized );

// save updated avatar sizes

update_user_meta( $user_id, 'simple_local_avatar', $local_avatars );

} elseif ( substr( $local_avatars[$size], 0, 4 ) != 'http' ) {

$local_avatars[$size] = home_url( $local_avatars[$size] );

}

$author_class = is_author( $user_id ) ? ' current-author' : '' ;

$avatar = "<img alt='" . esc_attr( $alt ) . "' src='" . $local_avatars[$size] . "' class='avatar avatar-{$size}{$author_class} photo' height='{$size}' width='{$size}' />";

return apply_filters( 'simple_local_avatar', $avatar );

}

public function admin_init() {

//load_plugin_textdomain( 'simple-local-avatars', false, dirname( plugin_basename( __FILE__ ) ) . '/localization/' );

register_setting( 'discussion', 'simple_local_avatars_caps', array( $this, 'sanitize_options' ) );

add_settings_field( 'simple-local-avatars-caps', __('Local Avatar Permissions','simple-local-avatars'), array( $this, 'avatar_settings_field' ), 'discussion', 'avatars' );

}

public function sanitize_options( $input ) {

$new_input['simple_local_avatars_caps'] = emptyempty( $input['simple_local_avatars_caps'] ) ? 0 : 1;

return $new_input;

}

public function avatar_settings_field( $args ) {

$options = get_option('simple_local_avatars_caps');

echo '

<label for="simple_local_avatars_caps">

<input type="checkbox" name="simple_local_avatars_caps" id="simple_local_avatars_caps" value="1" ' . @checked( $options['simple_local_avatars_caps'], 1, false ) . ' />

' . __('僅具有頭像上傳權(quán)限的用戶具有設(shè)置本地頭像權(quán)限(作者及更高等級(jí)角色)。','simple-local-avatars') . '

</label>

';

}

public function edit_user_profile( $profileuser ) {

?>

<h3><?php _e( '頭像','simple-local-avatars' ); ?></h3>

<table class="form-table">

<tr>

<th><label for="simple-local-avatar"><?php _e('上傳頭像','simple-local-avatars'); ?></label></th>

<td style="width: 50px;" valign="top">

<?php echo get_avatar( $profileuser->ID ); ?>

</td>

<td>

<?php

$options = get_option('simple_local_avatars_caps');

if ( emptyempty($options['simple_local_avatars_caps']) || current_user_can('upload_files') ) {

do_action( 'simple_local_avatar_notices' );

wp_nonce_field( 'simple_local_avatar_nonce', '_simple_local_avatar_nonce', false );

?>

<input type="file" name="simple-local-avatar" id="simple-local-avatar" /><br />

<?php

if ( emptyempty( $profileuser->simple_local_avatar ) )

echo '<span class="description">' . __('尚未設(shè)置本地頭像,請點(diǎn)擊“瀏覽”按鈕上傳本地頭像。','simple-local-avatars') . '</span>';

else

echo '

<input type="checkbox" name="simple-local-avatar-erase" value="1" /> ' . __('移除本地頭像','simple-local-avatars') . '<br />

<span class="description">' . __('如需要修改本地頭像,請重新上傳新頭像。如需要移除本地頭像,請選中上方的“移除本地頭像”復(fù)選框并更新個(gè)人資料即可。<br/>移除本地頭像后,將恢復(fù)使用 Gravatar 頭像。','simple-local-avatars') . '</span>

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 亚洲人成中文字幕在线观看 | 毛片大全 | 亚洲午夜电影 | 免费啪视频在线观看 | 国产免费大片视频 | 狠狠ri| 日日草夜夜操 | 5a级毛片 | 懂色粉嫩av久婷啪 | 久艹在线视频 | 国产毛片在线高清视频 | 欧美性生活久久久 | 国产日韩欧美 | 成人h精品动漫一区二区三区 | 久久草在线观看视频 | 久久久成人一区二区免费影院 | 中文字幕一区二区三区四区 | 特黄一区二区三区 | 国产精品视频免费网站 | 亚洲男人的天堂在线视频 | 怦然心动50免费完整版 | 中文字幕激情视频 | 99精品视频在线观看免费 | 国产一区二区三区四 | 欧美三级欧美成人高清www | 国产电影av在线 | av在线官网 | 色吧综合网 | 免费毛片播放 | 久草导航 | 国产免费资源 | 一级美女大片 | 狠狠干91 | 女人叉开腿让男人桶 | 久久成年网站 | 亚洲免费视频一区二区 | 天天草夜夜爽 | 黄色一级片在线观看 | 成人免费网站在线观看视频 | 91 在线免费观看 | 精品国产乱码一区二区 |