fix(user): repair phone binding and profile fields
This commit is contained in:
1 parent
0cf4639d95
commit
f646fa8573
15 files changed
+627
-162
No files matched your search
@@ -12,7 +12,7 @@ if (!function_exists('aksrt_get_user_profile_details')) {
|
||||
* Read the fixed profile details. Social fields are deliberately kept in one
|
||||
* structured meta value so public rendering can filter them server-side.
|
||||
*
|
||||
* @return array{privacy:string,gender:string,website:string,qq:string,wechat:string,github:string}
|
||||
* @return array{privacy:string,gender:string,website:string,qq:string,wechat:string,weibo:string,github:string,address:string}
|
||||
*/
|
||||
function aksrt_get_user_profile_details(int $user_id): array {
|
||||
$raw = get_user_meta($user_id, 'aksrt_profile_details', true);
|
||||
@@ -32,13 +32,15 @@ if (!function_exists('aksrt_get_user_profile_details')) {
|
||||
'website' => esc_url_raw((string) ($raw['website'] ?? '')),
|
||||
'qq' => sanitize_text_field((string) ($raw['qq'] ?? '')),
|
||||
'wechat' => sanitize_text_field((string) ($raw['wechat'] ?? '')),
|
||||
'weibo' => esc_url_raw((string) ($raw['weibo'] ?? '')),
|
||||
'github' => esc_url_raw((string) ($raw['github'] ?? '')),
|
||||
'address' => sanitize_text_field((string) ($raw['address'] ?? '')),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('aksrt_get_visible_user_profile_details')) {
|
||||
/** @return array{gender:string,website:string,qq:string,wechat:string,github:string} */
|
||||
/** @return array{gender:string,website:string,qq:string,wechat:string,weibo:string,github:string,address:string} */
|
||||
function aksrt_get_visible_user_profile_details(int $user_id, int $viewer_id = 0): array {
|
||||
$details = aksrt_get_user_profile_details($user_id);
|
||||
$visible = $viewer_id === $user_id || $details['privacy'] === 'public' || ($details['privacy'] === 'members' && $viewer_id > 0);
|
||||
@@ -47,7 +49,9 @@ if (!function_exists('aksrt_get_visible_user_profile_details')) {
|
||||
'website' => $visible ? $details['website'] : '',
|
||||
'qq' => $visible ? $details['qq'] : '',
|
||||
'wechat' => $visible ? $details['wechat'] : '',
|
||||
'weibo' => $visible ? $details['weibo'] : '',
|
||||
'github' => $visible ? $details['github'] : '',
|
||||
'address' => $visible ? $details['address'] : '',
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -86,28 +90,32 @@ if (!function_exists('aksrt_save_user_center_profile')) {
|
||||
}
|
||||
}
|
||||
|
||||
$privacy = isset($input['privacy']) ? sanitize_key(wp_unslash($input['privacy'])) : 'private';
|
||||
$existing_details = aksrt_get_user_profile_details($user_id);
|
||||
$privacy = isset($input['privacy']) ? sanitize_key(wp_unslash($input['privacy'])) : $existing_details['privacy'];
|
||||
if (!in_array($privacy, ['private', 'public', 'members'], true)) {
|
||||
$errors[] = __('无效的隐私设置。', 'aksrt');
|
||||
}
|
||||
$gender = isset($input['gender']) ? sanitize_key(wp_unslash($input['gender'])) : 'secret';
|
||||
$gender = isset($input['gender']) ? sanitize_key(wp_unslash($input['gender'])) : $existing_details['gender'];
|
||||
if (!in_array($gender, ['secret', 'male', 'female'], true)) {
|
||||
$errors[] = __('无效的性别设置。', 'aksrt');
|
||||
}
|
||||
$details = [
|
||||
'privacy' => $privacy,
|
||||
'gender' => $gender,
|
||||
'website' => isset($input['website']) ? esc_url_raw(wp_unslash($input['website'])) : '',
|
||||
'qq' => isset($input['qq']) ? sanitize_text_field(wp_unslash($input['qq'])) : '',
|
||||
'wechat' => isset($input['wechat']) ? sanitize_text_field(wp_unslash($input['wechat'])) : '',
|
||||
'github' => isset($input['github']) ? esc_url_raw(wp_unslash($input['github'])) : '',
|
||||
'website' => isset($input['website']) ? esc_url_raw(wp_unslash($input['website'])) : $existing_details['website'],
|
||||
'qq' => isset($input['qq']) ? sanitize_text_field(wp_unslash($input['qq'])) : $existing_details['qq'],
|
||||
'wechat' => isset($input['wechat']) ? sanitize_text_field(wp_unslash($input['wechat'])) : $existing_details['wechat'],
|
||||
'weibo' => isset($input['weibo']) ? esc_url_raw(wp_unslash($input['weibo'])) : $existing_details['weibo'],
|
||||
'github' => isset($input['github']) ? esc_url_raw(wp_unslash($input['github'])) : $existing_details['github'],
|
||||
'address' => isset($input['address']) ? sanitize_text_field(wp_unslash($input['address'])) : $existing_details['address'],
|
||||
];
|
||||
foreach (['website', 'github'] as $field) {
|
||||
foreach (['website', 'weibo', 'github'] as $field) {
|
||||
if (!empty($input[$field]) && $details[$field] === '') {
|
||||
$errors[] = sprintf(__('无效的%s链接。', 'aksrt'), $field === 'website' ? __('个人网站', 'aksrt') : 'GitHub');
|
||||
$field_label = ['website' => __('个人网站', 'aksrt'), 'weibo' => __('微博', 'aksrt'), 'github' => 'GitHub'][$field];
|
||||
$errors[] = sprintf(__('无效的%s链接。', 'aksrt'), $field_label);
|
||||
}
|
||||
}
|
||||
if (mb_strlen($details['qq']) > 50 || mb_strlen($details['wechat']) > 100) {
|
||||
if (mb_strlen($details['qq']) > 50 || mb_strlen($details['wechat']) > 100 || mb_strlen($details['address']) > 200) {
|
||||
$errors[] = __('社交资料长度超过限制。', 'aksrt');
|
||||
}
|
||||
if ($errors) {
|
||||
|
||||
Reference in new issue
Block a user