',$avatar); return $avatar; } if (git_get_option('git_avater') == 'git_avatar_qn') { add_filter('get_avatar', 'get_ssl_avatar', 10, 3); } //随机头像 function local_random_avatar($avatar) { $avatarsrc = 'https://cdn.jsdelivr.net/gh/yunluo/GitCafeApi/avatar/' . mt_rand(1, 1999) . '.jpg'; $avatar = ""; return $avatar; } if (git_get_option('git_avater') == 'git_avatar_rand') { add_filter('get_avatar', 'local_random_avatar', 1, 5); } //本地头像 class simple_local_avatars { private $user_id_being_edited; public function __construct() { 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('get_avatar', array( $this, 'get_avatar' ) , 10, 5); add_filter('avatar_defaults', array( $this, 'avatar_defaults' )); } public function admin_init() { register_setting('discussion', 'simple_local_avatars_caps', array( $this, 'sanitize_options' )); add_settings_field('basic-user-avatars-caps', '本地上传头像权限管理', array( $this, 'avatar_settings_field' ) , 'discussion', 'avatars'); } public function avatar_settings_field($args) { $options = get_option('simple_local_avatars_caps'); ?> ID; elseif (is_object($id_or_email) && !empty($id_or_email->user_id)) $user_id = (int)$id_or_email->user_id; if (empty($user_id)) return $avatar; $local_avatars = get_user_meta($user_id, 'simple_local_avatar', true); if (empty($local_avatars) || empty($local_avatars['full'])) return $avatar; $size = (int)$size; if (empty($alt)) $alt = get_the_author_meta('display_name', $user_id); if (empty($local_avatars[$size])) { $upload_path = wp_upload_dir(); $avatar_full_path = str_replace($upload_path['baseurl'], $upload_path['basedir'], $local_avatars['full']); $image = wp_get_image_editor($avatar_full_path); if (!is_wp_error($image)) { $image->resize($size, $size, true); $image_sized = $image->save(); } $local_avatars[$size] = is_wp_error($image_sized) ? $local_avatars[$size] = $local_avatars['full'] : str_replace($upload_path['basedir'], $upload_path['baseurl'], $image_sized['path']); 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 = ""; return apply_filters('simple_local_avatar', $avatar); } public function edit_user_profile($profileuser) { ?>
ID); ?> |
'; if (empty($profileuser->simple_local_avatar)) { echo '尚未设置本地头像,请点击“浏览”按钮上传本地头像'; } else { echo '移除本地头像 '; echo '如需要修改本地头像,请重新上传新头像。如需要移除本地头像,请选中上方的“移除本地头像”复选框并更新个人资料即可。 移除本地头像后,将恢复使用 Gravatar 头像'; } } else { if (empty($profileuser->simple_local_avatar)) { echo '尚未设置本地头像,请在 Gravatar.com 网站设置头像'; } else { echo '你没有头像上传权限,如需要修改本地头像,请联系站点管理员'; } } ?> |