feat(submit): add user media library
This commit is contained in:
@@ -821,59 +821,6 @@ if (!function_exists('aksrt_can_access_content')) {
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('aksrt_can_download')) {
|
||||
/**
|
||||
* 下载授权门禁 —— 单一合同。
|
||||
*
|
||||
* 实际判定交给 \AKSRT\Content\Visibility::can_download_resource()。
|
||||
* 不再使用 download_credit 做按次扣积分门禁。
|
||||
*
|
||||
* @param int|WP_Post|null $post
|
||||
* @param int $user_id 0 表示当前用户
|
||||
* @return true|WP_Error
|
||||
*/
|
||||
function aksrt_can_download($post = null, int $user_id = 0) {
|
||||
if (class_exists('\AKSRT\Content\Visibility')) {
|
||||
return \AKSRT\Content\Visibility::can_download_resource($post, $user_id);
|
||||
}
|
||||
|
||||
$p = get_post($post);
|
||||
if (!($p instanceof WP_Post)) {
|
||||
return new WP_Error('aksrt_invalid', __('无效内容。', 'aksrt'));
|
||||
}
|
||||
|
||||
$meta = aksrt_get_pay_meta($p);
|
||||
if (($meta['pay_type'] ?? '') !== AKSRT_PAY_TYPE_DOWNLOAD) {
|
||||
return new WP_Error('aksrt_not_downloadable', __('该内容不是可下载资源。', 'aksrt'));
|
||||
}
|
||||
|
||||
$uid = $user_id > 0 ? $user_id : get_current_user_id();
|
||||
if (!function_exists('aksrt_user_can') || !aksrt_user_can('resource_download', $uid, (int) $p->ID)) {
|
||||
$login_url = wp_login_url(get_permalink($p));
|
||||
return new WP_Error('aksrt_need_login', __('请先登录。', 'aksrt'), ['login_url' => $login_url]);
|
||||
}
|
||||
|
||||
if ($uid > 0 && function_exists('aksrt_has_paid_access') && aksrt_has_paid_access($p, $uid)) {
|
||||
return true;
|
||||
}
|
||||
if ($uid > 0 && function_exists('aksrt_is_vip_exempt') && aksrt_is_vip_exempt($uid)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Fallback without Content_Visibility: require purchase when priced.
|
||||
$cost = function_exists('aksrt_get_download_cost') ? aksrt_get_download_cost($p) : 0;
|
||||
if ($cost > 0) {
|
||||
return new WP_Error('aksrt_need_purchase', __('请先购买后再下载。', 'aksrt'), [
|
||||
'status' => 402,
|
||||
'cost' => $cost,
|
||||
'post_id'=> (int) $p->ID,
|
||||
]);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('aksrt_get_download_cost')) {
|
||||
function aksrt_get_download_cost($post = null): int {
|
||||
if (function_exists('aksrt_resource_download_cost')) {
|
||||
|
||||
Reference in New Issue
Block a user