From 408bf173fc57a90dea8df9405a849c82ca27a9b3 Mon Sep 17 00:00:00 2001 From: liaoxin Date: Sat, 16 May 2026 22:36:09 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E7=94=A8=E6=88=B7=E8=B5=84=E6=96=99?= =?UTF-8?q?=E9=A1=B5=E6=B7=BB=E5=8A=A0=E6=9C=AC=E5=9C=B0=E5=A4=B4=E5=83=8F?= =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- functions.php | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/functions.php b/functions.php index bcb74ab..dc390fd 100644 --- a/functions.php +++ b/functions.php @@ -147,6 +147,60 @@ add_action('template_include', function($template) { +// ── 本地头像:用户资料页上传 ───────────────────── +add_action('show_user_profile', 'kjweji_avatar_field'); +add_action('edit_user_profile', 'kjweji_avatar_field'); +function kjweji_avatar_field($user) { + $att_id = get_user_meta($user->ID, 'custom_avatar', true); + $preview = $att_id ? wp_get_attachment_image_url($att_id, 'medium') : ''; + wp_nonce_field('kjweji_avatar_nonce', 'kjweji_avatar_nonce_field'); + echo '

自定义头像

'; + echo '
'; + echo ''; + echo '
'; + if ($preview) echo ''; + echo '
'; + echo ''; + echo ''; + echo '
'; + echo ''; +} +add_action('personal_options_update', 'kjweji_save_avatar'); +add_action('edit_user_profile_update', 'kjweji_save_avatar'); +function kjweji_save_avatar($user_id) { + if (!current_user_can('edit_user', $user_id)) return; + if (!isset($_POST['kjweji_avatar_nonce_field']) || !wp_verify_nonce($_POST['kjweji_avatar_nonce_field'], 'kjweji_avatar_nonce')) return; + if (isset($_POST['custom_avatar'])) { + $att_id = intval($_POST['custom_avatar']); + if ($att_id) { + update_user_meta($user_id, 'custom_avatar', $att_id); + } else { + delete_user_meta($user_id, 'custom_avatar'); + } + } +} + // 本地头像(团队证件照) add_filter('get_avatar', function($avatar, $id_or_email, $size, $default, $alt) { $uid = 0;