feat(users): govern profiles and access
Normalize fixed profile fields, profile actions, and the five-column capability matrix for comments, uploads, and downloads.
This commit is contained in:
@@ -91,6 +91,15 @@ class Download {
|
||||
}
|
||||
|
||||
public function check_rest_nonce(\WP_REST_Request $request) {
|
||||
// The capability matrix can explicitly allow resource downloads for
|
||||
// everyone. A WordPress REST nonce only exists for authenticated
|
||||
// sessions, so requiring one from visitors would make the "all"
|
||||
// column ineffective. Anonymous requests still pass the unified
|
||||
// download gate (capability, payment and captcha) in rest_request().
|
||||
if (get_current_user_id() <= 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$nonce = $request->get_header('x-wp-nonce');
|
||||
if (!$nonce) {
|
||||
return new \WP_Error('aksrt_rest_no_nonce', __('缺少安全令牌', 'aksrt'), ['status' => 403]);
|
||||
@@ -109,7 +118,6 @@ class Download {
|
||||
}
|
||||
|
||||
$meta = function_exists('aksrt_get_download_box_meta') ? aksrt_get_download_box_meta($post) : [];
|
||||
$paid_settings = \AKSRT\Settings\Settings::get_paid_content_settings();
|
||||
$cost = aksrt_resource_download_cost($post);
|
||||
$uid = get_current_user_id();
|
||||
$priced = function_exists('aksrt_get_user_pay_price') ? aksrt_get_user_pay_price($post, $uid) : null;
|
||||
@@ -122,10 +130,7 @@ class Download {
|
||||
? Visibility::get_post_access_state($post, $uid)
|
||||
: [];
|
||||
|
||||
$need_captcha = !empty($paid_settings['download_captcha']) || !empty($meta['require_captcha']);
|
||||
if ($need_captcha && function_exists('aksrt_is_captcha_enabled_for') && !aksrt_is_captcha_enabled_for('download')) {
|
||||
$need_captcha = false;
|
||||
}
|
||||
$need_captcha = function_exists('aksrt_is_captcha_enabled_for') && aksrt_is_captcha_enabled_for('download');
|
||||
|
||||
return new \WP_REST_Response([
|
||||
'post_id' => $post_id,
|
||||
@@ -134,7 +139,7 @@ class Download {
|
||||
'pay_modo' => $pay_modo,
|
||||
'pay_limit' => (int) ($meta['pay_limit'] ?? 0),
|
||||
'cost' => $cost,
|
||||
'require_login' => !empty($paid_settings['download_login']) || !empty($meta['require_login']) || (!empty($paid_settings['free_logged_show']) && $cost <= 0 && $display_price <= 0),
|
||||
'require_login' => !empty($access['need_login']),
|
||||
'require_captcha' => $need_captcha,
|
||||
'logged_in' => $uid > 0,
|
||||
'balance' => $uid > 0 && class_exists('\AKSRT\Credits\Credits') ? \AKSRT\Credits\Credits::balance($uid) : 0,
|
||||
@@ -181,7 +186,6 @@ class Download {
|
||||
$gate = aksrt_can_download($post);
|
||||
if (is_wp_error($gate)) return $gate;
|
||||
|
||||
$paid_settings = \AKSRT\Settings\Settings::get_paid_content_settings();
|
||||
$uid = get_current_user_id();
|
||||
$cost = aksrt_resource_download_cost($post);
|
||||
|
||||
@@ -193,8 +197,7 @@ class Download {
|
||||
}
|
||||
}
|
||||
|
||||
$need_captcha = !empty($paid_settings['download_captcha']) || !empty($meta['require_captcha']);
|
||||
// 下载双开关:cms_features.download_captcha(或单资源强制)且场景未停用。
|
||||
$need_captcha = function_exists('aksrt_is_captcha_enabled_for') && aksrt_is_captcha_enabled_for('download');
|
||||
if ($need_captcha && function_exists('aksrt_require_captcha')) {
|
||||
$cap_payload = isset($params['captcha']) && is_array($params['captcha']) ? $params['captcha'] : [];
|
||||
// 场景未启用时 require 直接放行;启用时强制校验 token。
|
||||
|
||||
Reference in New Issue
Block a user