feat(identity): tip QR upload, metrics engine, comment moderate caps
Close identity 1:1 gaps after p1: user-center weixin/alipay tip QR upload+save, AKSRT_User_Metrics counters for medal get_type and level XP bridges, forum/revenue/signin hooks, comment moderate via user_caps, and clearer free-task deep links/status CTAs.
This commit is contained in:
@@ -942,6 +942,59 @@ add_action('wp_ajax_aksrt_save_profile', function () {
|
||||
wp_send_json_success(['message' => __('保存成功!', 'aksrt')]);
|
||||
});
|
||||
|
||||
// ============================================================
|
||||
// AJAX: 上传打赏收款码
|
||||
// ============================================================
|
||||
add_action('wp_ajax_aksrt_upload_reward_qr', function () {
|
||||
if (!isset($_POST['_profile_nonce']) || !wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['_profile_nonce'])), 'aksrt_profile_save')) {
|
||||
wp_send_json_error(['message' => __('安全验证失败,请刷新页面重试', 'aksrt')]);
|
||||
}
|
||||
$user_id = get_current_user_id();
|
||||
if ($user_id <= 0) {
|
||||
wp_send_json_error(['message' => __('请先登录', 'aksrt')]);
|
||||
}
|
||||
if (function_exists('aksrt_rewards_enabled') && !aksrt_rewards_enabled()) {
|
||||
wp_send_json_error(['message' => __('打赏功能未启用', 'aksrt')]);
|
||||
}
|
||||
$kind = isset($_POST['kind']) ? sanitize_key((string) $_POST['kind']) : '';
|
||||
if (!in_array($kind, ['weixin', 'alipay'], true)) {
|
||||
wp_send_json_error(['message' => __('无效类型', 'aksrt')]);
|
||||
}
|
||||
if (empty($_FILES['file']['name'])) {
|
||||
wp_send_json_error(['message' => __('请选择图片', 'aksrt')]);
|
||||
}
|
||||
|
||||
require_once ABSPATH . 'wp-admin/includes/file.php';
|
||||
require_once ABSPATH . 'wp-admin/includes/media.php';
|
||||
require_once ABSPATH . 'wp-admin/includes/image.php';
|
||||
|
||||
$file = $_FILES['file'];
|
||||
$check = wp_check_filetype_and_ext($file['tmp_name'], $file['name']);
|
||||
$allowed = ['image/jpeg', 'image/png', 'image/gif', 'image/webp'];
|
||||
$mime = (string) ($check['type'] ?? $file['type'] ?? '');
|
||||
if ($mime === '' || !in_array($mime, $allowed, true)) {
|
||||
wp_send_json_error(['message' => __('仅支持 JPG/PNG/GIF/WebP 图片', 'aksrt')]);
|
||||
}
|
||||
if (!empty($file['size']) && (int) $file['size'] > 2 * 1024 * 1024) {
|
||||
wp_send_json_error(['message' => __('图片不能超过 2MB', 'aksrt')]);
|
||||
}
|
||||
|
||||
$attachment_id = media_handle_upload('file', 0);
|
||||
if (is_wp_error($attachment_id)) {
|
||||
wp_send_json_error(['message' => $attachment_id->get_error_message()]);
|
||||
}
|
||||
$meta = $kind === 'weixin' ? 'aksrt_rewards_weixin' : 'aksrt_rewards_alipay';
|
||||
update_user_meta($user_id, $meta, (int) $attachment_id);
|
||||
$url = wp_get_attachment_image_url((int) $attachment_id, 'full');
|
||||
wp_send_json_success([
|
||||
'message' => __('上传成功', 'aksrt'),
|
||||
'id' => (int) $attachment_id,
|
||||
'url' => is_string($url) ? $url : '',
|
||||
'kind' => $kind,
|
||||
]);
|
||||
});
|
||||
|
||||
|
||||
// ============================================================
|
||||
// AJAX: 发送邮箱验证码(修改密码/更改邮箱通用)
|
||||
// ============================================================
|
||||
|
||||
Reference in New Issue
Block a user