feat(submit): add user media library
This commit is contained in:
@@ -69,6 +69,7 @@ class DomainModel {
|
||||
'cover_image' => '',
|
||||
'featured_slide' => '',
|
||||
'featured_video' => '',
|
||||
'featured_video_attachment_id' => 0,
|
||||
'featured_video_title' => '',
|
||||
'featured_video_episode' => [],
|
||||
'subtitle' => '',
|
||||
@@ -173,7 +174,7 @@ class DomainModel {
|
||||
|
||||
/**
|
||||
* @param mixed $value
|
||||
* @return array<int, array<string, string>>
|
||||
* @return array<int, array{label:string,url:string,type:string,extract_code:string,copy_key:string,copy_val:string,class:string,attachment_id:int}>
|
||||
*/
|
||||
public static function sanitize_downloads($value): array {
|
||||
if (!is_array($value)) {
|
||||
@@ -237,10 +238,11 @@ class DomainModel {
|
||||
'type' => $type,
|
||||
'extract_code' => $extract_code,
|
||||
'copy_key' => isset($row['copy_key']) ? sanitize_text_field((string) $row['copy_key']) : '',
|
||||
'copy_val' => isset($row['copy_val']) ? sanitize_text_field((string) $row['copy_val']) : '',
|
||||
'class' => isset($row['class']) && in_array($row['class'], $allowed_classes, true)
|
||||
? (string) $row['class']
|
||||
: '',
|
||||
'copy_val' => isset($row['copy_val']) ? sanitize_text_field((string) $row['copy_val']) : '',
|
||||
'class' => isset($row['class']) && in_array($row['class'], $allowed_classes, true)
|
||||
? (string) $row['class']
|
||||
: '',
|
||||
'attachment_id' => is_scalar($row['attachment_id'] ?? null) ? max(0, (int) $row['attachment_id']) : 0,
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
+47
-13
@@ -16,6 +16,7 @@ class FrontSubmit {
|
||||
use FrontSubmitSave;
|
||||
use FrontSubmitPay;
|
||||
use FrontSubmitFeatured;
|
||||
use FrontSubmitMedia;
|
||||
|
||||
private static $instance = null;
|
||||
|
||||
@@ -37,6 +38,8 @@ class FrontSubmit {
|
||||
add_action('wp_ajax_nopriv_aksrt_submit_post', [$this, 'ajax_submit_post']);
|
||||
|
||||
add_action('rest_api_init', [$this, 'register_rest_routes']);
|
||||
add_action('aksrt_new_add_posts', [$this, 'sync_post_attachments']);
|
||||
add_action('aksrt_new_edit_posts', [$this, 'sync_post_attachments']);
|
||||
|
||||
add_filter('body_class', [$this, 'body_class']);
|
||||
add_filter('wp_robots', [$this, 'robots_noindex']);
|
||||
@@ -45,6 +48,38 @@ class FrontSubmit {
|
||||
}
|
||||
|
||||
public function register_rest_routes(): void {
|
||||
register_rest_route('aksrt/v1', '/front-submit/media/(?P<type>image|video|file)', [
|
||||
'methods' => \WP_REST_Server::READABLE,
|
||||
'callback' => [$this, 'rest_list_attachments'],
|
||||
'permission_callback' => [$this, 'can_list_attachments'],
|
||||
'args' => [
|
||||
'type' => [
|
||||
'validate_callback' => static function ($value): bool {
|
||||
return in_array((string) $value, ['image', 'video', 'file'], true);
|
||||
},
|
||||
],
|
||||
'post_id' => [
|
||||
'default' => 0,
|
||||
'sanitize_callback' => 'absint',
|
||||
],
|
||||
'paged' => [
|
||||
'default' => 1,
|
||||
'sanitize_callback' => 'absint',
|
||||
'validate_callback' => static function ($value): bool {
|
||||
return absint($value) > 0;
|
||||
},
|
||||
],
|
||||
'search' => [
|
||||
'default' => '',
|
||||
'sanitize_callback' => 'sanitize_text_field',
|
||||
],
|
||||
'exclude' => [
|
||||
'default' => [],
|
||||
'sanitize_callback' => [$this, 'sanitize_attachment_ids'],
|
||||
],
|
||||
],
|
||||
]);
|
||||
|
||||
register_rest_route('aksrt/v1', '/front-submit/upload/(?P<kind>image|video|resource)', [
|
||||
'methods' => 'POST',
|
||||
'callback' => [$this, 'rest_upload_attachment'],
|
||||
@@ -55,6 +90,10 @@ class FrontSubmit {
|
||||
return in_array((string) $value, ['image', 'video', 'resource'], true);
|
||||
},
|
||||
],
|
||||
'post_id' => [
|
||||
'default' => 0,
|
||||
'sanitize_callback' => 'absint',
|
||||
],
|
||||
],
|
||||
]);
|
||||
}
|
||||
@@ -64,7 +103,7 @@ class FrontSubmit {
|
||||
if ($user_id <= 0) {
|
||||
return false;
|
||||
}
|
||||
if (!$this->can_submit($user_id)) {
|
||||
if (!$this->can_use_media($request, $user_id)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -173,23 +212,18 @@ class FrontSubmit {
|
||||
return new \WP_Error('aksrt_upload_failed', $attachment_id->get_error_message(), ['status' => 400]);
|
||||
}
|
||||
|
||||
$attachment_id = (int) $attachment_id;
|
||||
wp_update_post(['ID' => $attachment_id, 'post_author' => $user_id]);
|
||||
$attachment_id = (int) $attachment_id;
|
||||
wp_update_post(['ID' => $attachment_id, 'post_author' => $user_id]);
|
||||
update_post_meta($attachment_id, '_aksrt_front_submit_media', $kind);
|
||||
|
||||
$url = wp_get_attachment_url($attachment_id);
|
||||
if (!$url) {
|
||||
$attachment = $this->prepare_attachment_response($attachment_id);
|
||||
if ($attachment === null) {
|
||||
wp_delete_attachment($attachment_id, true);
|
||||
return new \WP_Error('aksrt_upload_failed', __('上传后无法读取文件。', 'aksrt'), ['status' => 500]);
|
||||
}
|
||||
|
||||
return new \WP_REST_Response([
|
||||
'success' => true,
|
||||
'attachment_id' => $attachment_id,
|
||||
'url' => $url,
|
||||
'name' => get_the_title($attachment_id),
|
||||
'filename' => wp_basename((string) get_attached_file($attachment_id)),
|
||||
'mime' => $mime,
|
||||
], 201);
|
||||
$attachment['success'] = true;
|
||||
return new \WP_REST_Response($attachment, 201);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -44,12 +44,20 @@ trait FrontSubmitFeatured {
|
||||
return;
|
||||
}
|
||||
$video = esc_url_raw((string) ($payload['url'] ?? ''));
|
||||
$video_id = absint($payload['id'] ?? 0);
|
||||
if ($video_id > 0 && !$this->can_use_front_submit_video($video_id, $user_id)) {
|
||||
$video_id = 0;
|
||||
}
|
||||
$pic = esc_url_raw((string) ($payload['pic'] ?? ''));
|
||||
if ($pic !== '' && !$this->user_can_cap('upload_submit_image', $user_id)) {
|
||||
$pic = '';
|
||||
}
|
||||
$post_meta['featured_video'] = $video;
|
||||
$post_meta['featured_video_attachment_id'] = $video_id;
|
||||
$post_meta['featured_slide'] = '';
|
||||
$post_meta['thumbnail_url'] = '';
|
||||
$post_meta['cover_image'] = '';
|
||||
delete_post_thumbnail($post_id);
|
||||
if ($pic !== '' && $this->can_use_front_submit_image_url($pic, $user_id)) {
|
||||
$post_meta['thumbnail_url'] = $pic;
|
||||
$post_meta['cover_image'] = $pic;
|
||||
@@ -100,6 +108,10 @@ trait FrontSubmitFeatured {
|
||||
}
|
||||
$post_meta['featured_slide'] = implode(',', array_values(array_unique($attachment_ids)));
|
||||
$post_meta['featured_video'] = '';
|
||||
$post_meta['featured_video_attachment_id'] = 0;
|
||||
$post_meta['thumbnail_url'] = '';
|
||||
$post_meta['cover_image'] = '';
|
||||
delete_post_thumbnail($post_id);
|
||||
if (!empty($urls[0]) && $this->can_use_front_submit_image_url((string) $urls[0], $user_id)) {
|
||||
$post_meta['thumbnail_url'] = $urls[0];
|
||||
$post_meta['cover_image'] = $urls[0];
|
||||
@@ -123,6 +135,7 @@ trait FrontSubmitFeatured {
|
||||
}
|
||||
}
|
||||
$post_meta['featured_video'] = '';
|
||||
$post_meta['featured_video_attachment_id'] = 0;
|
||||
$post_meta['featured_slide'] = '';
|
||||
if ($url !== '' && $this->can_use_front_submit_image_url($url, $user_id)) {
|
||||
$post_meta['thumbnail_url'] = $url;
|
||||
@@ -139,6 +152,7 @@ trait FrontSubmitFeatured {
|
||||
case 'none':
|
||||
case 'clear':
|
||||
$post_meta['featured_video'] = '';
|
||||
$post_meta['featured_video_attachment_id'] = 0;
|
||||
$post_meta['featured_slide'] = '';
|
||||
$post_meta['thumbnail_url'] = '';
|
||||
$post_meta['cover_image'] = '';
|
||||
@@ -181,4 +195,16 @@ trait FrontSubmitFeatured {
|
||||
$attachment_id = attachment_url_to_postid($url);
|
||||
return $attachment_id > 0 && $this->can_use_front_submit_image($attachment_id, $user_id);
|
||||
}
|
||||
|
||||
private function can_use_front_submit_video(int $attachment_id, int $user_id): bool {
|
||||
if ($attachment_id <= 0 || !$this->user_can_cap('new_post_video_cover', $user_id)) {
|
||||
return false;
|
||||
}
|
||||
$attachment = get_post($attachment_id);
|
||||
return $attachment instanceof \WP_Post
|
||||
&& $attachment->post_type === 'attachment'
|
||||
&& (int) $attachment->post_author === $user_id
|
||||
&& in_array($attachment->post_status, ['inherit', 'private'], true)
|
||||
&& strpos((string) $attachment->post_mime_type, 'video/') === 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,294 @@
|
||||
<?php
|
||||
/**
|
||||
* @package AKSRT
|
||||
*/
|
||||
|
||||
namespace AKSRT\Core;
|
||||
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
/**
|
||||
* Front-submit media library, attachment normalization, and post relations.
|
||||
*/
|
||||
trait FrontSubmitMedia {
|
||||
|
||||
/**
|
||||
* Check whether the current user may browse their front-submit media.
|
||||
*/
|
||||
public function can_list_attachments(\WP_REST_Request $request): bool {
|
||||
$user_id = get_current_user_id();
|
||||
return $user_id > 0 && $this->can_use_media($request, $user_id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether a user may use the submit media routes for this post.
|
||||
*/
|
||||
private function can_use_media(\WP_REST_Request $request, int $user_id): bool {
|
||||
$post_id = absint($request->get_param('post_id'));
|
||||
if ($post_id > 0) {
|
||||
return $this->can_edit_post($post_id, $user_id);
|
||||
}
|
||||
return $this->can_submit($user_id);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sanitize a REST attachment exclusion list.
|
||||
*
|
||||
* @param mixed $value Comma-separated or array attachment IDs.
|
||||
* @return int[]
|
||||
*/
|
||||
public function sanitize_attachment_ids($value): array {
|
||||
if (!is_array($value)) {
|
||||
$value = preg_split('/[,\s]+/', (string) $value) ?: [];
|
||||
}
|
||||
return array_values(array_unique(array_filter(array_map(static function ($id): int {
|
||||
return is_scalar($id) ? absint($id) : 0;
|
||||
}, $value))));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the current user's front-submit attachments.
|
||||
*/
|
||||
public function rest_list_attachments(\WP_REST_Request $request): \WP_REST_Response {
|
||||
$user_id = get_current_user_id();
|
||||
$type = sanitize_key((string) $request->get_param('type'));
|
||||
$page = max(1, absint($request->get_param('paged')));
|
||||
$search = sanitize_text_field((string) $request->get_param('search'));
|
||||
$exclude = $this->sanitize_attachment_ids($request->get_param('exclude'));
|
||||
|
||||
if ($user_id <= 0 || !in_array($type, ['image', 'video', 'file'], true)) {
|
||||
return new \WP_REST_Response([
|
||||
'items' => [],
|
||||
'total' => 0,
|
||||
'total_pages' => 0,
|
||||
'page' => $page,
|
||||
'per_page' => 48,
|
||||
], 200);
|
||||
}
|
||||
|
||||
$args = [
|
||||
'post_type' => 'attachment',
|
||||
'post_status' => ['inherit', 'private'],
|
||||
'author' => $user_id,
|
||||
'posts_per_page' => 48,
|
||||
'paged' => $page,
|
||||
'orderby' => 'ID',
|
||||
'order' => 'DESC',
|
||||
'no_found_rows' => false,
|
||||
];
|
||||
if ($type === 'image') {
|
||||
$args['post_mime_type'] = 'image';
|
||||
} elseif ($type === 'video') {
|
||||
$args['post_mime_type'] = 'video';
|
||||
}
|
||||
if ($exclude !== []) {
|
||||
$args['post__not_in'] = $exclude;
|
||||
}
|
||||
|
||||
if ($search !== '') {
|
||||
$args['s'] = $search;
|
||||
add_filter('wp_allow_query_attachment_by_filename', '__return_true');
|
||||
}
|
||||
|
||||
$query = new \WP_Query($args);
|
||||
if ($search !== '') {
|
||||
remove_filter('wp_allow_query_attachment_by_filename', '__return_true');
|
||||
}
|
||||
$items = [];
|
||||
foreach ($query->posts as $attachment) {
|
||||
$prepared = $this->prepare_attachment_response($attachment);
|
||||
if ($prepared !== null) {
|
||||
$items[] = $prepared;
|
||||
}
|
||||
}
|
||||
|
||||
$total = (int) $query->found_posts;
|
||||
return new \WP_REST_Response([
|
||||
'items' => $items,
|
||||
'total' => $total,
|
||||
'total_pages' => $total > 0 ? (int) ceil($total / 48) : 0,
|
||||
'page' => $page,
|
||||
'per_page' => 48,
|
||||
], 200);
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalize an attachment with WordPress's media response model.
|
||||
*
|
||||
* Only fields needed by the front-submit picker are returned. In
|
||||
* particular, admin links, icons, nonces, and author data are omitted.
|
||||
*
|
||||
* @param int|\WP_Post $attachment Attachment object or ID.
|
||||
* @return array<string, mixed>|null
|
||||
*/
|
||||
private function prepare_attachment_response($attachment): ?array {
|
||||
$attachment = $attachment instanceof \WP_Post ? $attachment : get_post(absint($attachment));
|
||||
if (!$attachment || $attachment->post_type !== 'attachment') {
|
||||
return null;
|
||||
}
|
||||
if (!function_exists('wp_prepare_attachment_for_js')) {
|
||||
require_once ABSPATH . 'wp-admin/includes/media.php';
|
||||
}
|
||||
$data = wp_prepare_attachment_for_js($attachment->ID);
|
||||
if (!is_array($data)) {
|
||||
return null;
|
||||
}
|
||||
$sizes = is_array($data['sizes'] ?? null) ? $data['sizes'] : [];
|
||||
$size_url = static function (array $sizes, string $size, string $fallback): string {
|
||||
return !empty($sizes[$size]['url']) ? (string) $sizes[$size]['url'] : $fallback;
|
||||
};
|
||||
$url = (string) ($data['url'] ?? wp_get_attachment_url($attachment->ID) ?? '');
|
||||
$filename = (string) ($data['filename'] ?? wp_basename((string) get_attached_file($attachment->ID)));
|
||||
$mime = (string) ($data['mime'] ?? get_post_mime_type($attachment->ID));
|
||||
return [
|
||||
'attachment_id' => (int) $attachment->ID,
|
||||
'id' => (int) $attachment->ID,
|
||||
'title' => (string) ($data['title'] ?? get_the_title($attachment->ID)),
|
||||
'name' => (string) ($data['name'] ?? $filename),
|
||||
'filename' => $filename,
|
||||
'type' => (string) ($data['type'] ?? (strpos($mime, '/') !== false ? strtok($mime, '/') : '')),
|
||||
'subtype' => (string) ($data['subtype'] ?? (strpos($mime, '/') !== false ? substr($mime, strpos($mime, '/') + 1) : '')),
|
||||
'url' => $url,
|
||||
'large_url' => $size_url($sizes, 'large', $url),
|
||||
'medium_url' => $size_url($sizes, 'medium', $url),
|
||||
'thumbnail_url' => $size_url($sizes, 'thumbnail', $url),
|
||||
'filesizeInBytes' => (int) ($data['filesizeInBytes'] ?? (@filesize((string) get_attached_file($attachment->ID)) ?: 0)),
|
||||
'mime' => $mime,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Attach IDs referenced by a saved submission to that post.
|
||||
*
|
||||
* @param mixed $post Saved post passed by the existing submission hooks.
|
||||
*/
|
||||
public function sync_post_attachments($post): void {
|
||||
if (!$post instanceof \WP_Post || $post->post_type !== 'post') {
|
||||
return;
|
||||
}
|
||||
$user_id = get_current_user_id();
|
||||
$post_id = (int) $post->ID;
|
||||
if ($user_id <= 0 || (int) $post->post_author !== $user_id) {
|
||||
return;
|
||||
}
|
||||
|
||||
$image_ids = $this->extract_attachment_ids((string) $post->post_content, 'image');
|
||||
$video_ids = $this->extract_attachment_ids((string) $post->post_content, 'video');
|
||||
$file_ids = $this->extract_attachment_ids((string) $post->post_content, 'file');
|
||||
$desired = [];
|
||||
foreach ($image_ids as $id) {
|
||||
if ($this->attachment_can_attach($id, $user_id, $post_id, 'image')) {
|
||||
$desired[$id] = 'image';
|
||||
}
|
||||
}
|
||||
foreach ($video_ids as $id) {
|
||||
if ($this->attachment_can_attach($id, $user_id, $post_id, 'video')) {
|
||||
$desired[$id] = 'video';
|
||||
}
|
||||
}
|
||||
foreach ($file_ids as $id) {
|
||||
if ($this->attachment_can_attach($id, $user_id, $post_id, 'file')) {
|
||||
$desired[$id] = 'file';
|
||||
}
|
||||
}
|
||||
|
||||
$pay_meta = function_exists('aksrt_get_pay_meta')
|
||||
? aksrt_get_pay_meta($post_id)
|
||||
: get_post_meta($post_id, DomainModel::PAY_META_KEY, true);
|
||||
$pay_meta = is_array($pay_meta) ? $pay_meta : [];
|
||||
foreach (is_array($pay_meta['downloads'] ?? null) ? $pay_meta['downloads'] : [] as $download) {
|
||||
$id = absint($download['attachment_id'] ?? 0);
|
||||
if ($id > 0 && $this->attachment_can_attach($id, $user_id, $post_id, 'file')) {
|
||||
$desired[$id] = 'file';
|
||||
}
|
||||
}
|
||||
|
||||
$post_meta = get_post_meta($post_id, DomainModel::POST_META_KEY, true);
|
||||
$post_meta = is_array($post_meta) ? $post_meta : [];
|
||||
$featured_ids = [];
|
||||
$video_id = absint($post_meta['featured_video_attachment_id'] ?? 0);
|
||||
if ($video_id > 0 && $this->attachment_can_attach($video_id, $user_id, $post_id, 'video')) {
|
||||
$desired[$video_id] = 'video';
|
||||
}
|
||||
$thumb_id = get_post_thumbnail_id($post_id);
|
||||
if ($thumb_id > 0) {
|
||||
$featured_ids[] = $thumb_id;
|
||||
}
|
||||
foreach (preg_split('/[\\s,]+/', (string) ($post_meta['featured_slide'] ?? '')) ?: [] as $token) {
|
||||
$id = absint($token);
|
||||
if ($id > 0) $featured_ids[] = $id;
|
||||
}
|
||||
foreach ($featured_ids as $id) {
|
||||
if ($this->attachment_can_attach($id, $user_id, $post_id, 'image')) {
|
||||
$desired[$id] = 'image';
|
||||
}
|
||||
}
|
||||
|
||||
global $wpdb;
|
||||
$existing = get_posts([
|
||||
'post_type' => 'attachment',
|
||||
'post_status' => ['inherit', 'private'],
|
||||
'post_parent' => $post_id,
|
||||
'author' => $user_id,
|
||||
'posts_per_page' => -1,
|
||||
'fields' => 'ids',
|
||||
'no_found_rows' => true,
|
||||
'meta_key' => '_aksrt_front_submit_media',
|
||||
]);
|
||||
foreach (array_map('absint', $existing) as $attachment_id) {
|
||||
if (!isset($desired[$attachment_id])) {
|
||||
$wpdb->update($wpdb->posts, ['post_parent' => 0], ['ID' => $attachment_id], ['%d'], ['%d']);
|
||||
clean_post_cache($attachment_id);
|
||||
delete_post_meta($attachment_id, '_aksrt_front_submit_media');
|
||||
}
|
||||
}
|
||||
foreach ($desired as $attachment_id => $kind) {
|
||||
$attachment_id = (int) $attachment_id;
|
||||
update_post_meta($attachment_id, '_aksrt_front_submit_media', $kind);
|
||||
$wpdb->update($wpdb->posts, ['post_parent' => $post_id], ['ID' => $attachment_id], ['%d'], ['%d']);
|
||||
clean_post_cache($attachment_id);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract IDs from image/video edit markers or attachment relation markers.
|
||||
*
|
||||
* @return int[]
|
||||
*/
|
||||
private function extract_attachment_ids(string $content, string $type): array {
|
||||
$ids = [];
|
||||
if ($type === 'file') {
|
||||
preg_match_all('/data-aksrt-file-id\s*=\s*["\']([^"\']+)["\']/i', $content, $matches);
|
||||
} elseif ($type === 'image') {
|
||||
preg_match_all('/<img\b[^>]*data-edit-file-id\s*=\s*["\']([^"\']+)["\'][^>]*>/i', $content, $matches);
|
||||
} else {
|
||||
preg_match_all('/<(?:div|video)\b[^>]*data-edit-file-id\s*=\s*["\']([^"\']+)["\'][^>]*data-video-url[^>]*>/i', $content, $matches);
|
||||
if (empty($matches[1])) {
|
||||
preg_match_all('/<(?:div|video)\b[^>]*data-video-url[^>]*data-edit-file-id\s*=\s*["\']([^"\']+)["\'][^>]*>/i', $content, $matches);
|
||||
}
|
||||
}
|
||||
return array_values(array_unique(array_filter(array_map('absint', $matches[1] ?? []))));
|
||||
}
|
||||
|
||||
private function attachment_can_attach(int $attachment_id, int $user_id, int $post_id, string $type): bool {
|
||||
$attachment = get_post($attachment_id);
|
||||
if (!$attachment || $attachment->post_type !== 'attachment' || (int) $attachment->post_author !== $user_id) {
|
||||
return false;
|
||||
}
|
||||
if (!in_array($attachment->post_status, ['inherit', 'private'], true)) {
|
||||
return false;
|
||||
}
|
||||
if ((int) $attachment->post_parent !== 0 && (int) $attachment->post_parent !== $post_id) {
|
||||
return false;
|
||||
}
|
||||
$mime = (string) $attachment->post_mime_type;
|
||||
if ($type === 'image') {
|
||||
return wp_attachment_is_image($attachment_id);
|
||||
}
|
||||
if ($type === 'video') {
|
||||
return strpos($mime, 'video/') === 0;
|
||||
}
|
||||
return $mime !== '';
|
||||
}
|
||||
}
|
||||
@@ -49,10 +49,14 @@ trait FrontSubmitPay {
|
||||
}
|
||||
|
||||
$downloads = DomainModel::sanitize_downloads($raw['downloads'] ?? []);
|
||||
if (!empty($downloads) && $this->user_can_cap('new_post_pay_download', $user_id)) {
|
||||
$pay_type = DomainModel::PAY_TYPE_DOWNLOAD;
|
||||
if ($this->user_can_cap('new_post_pay_download', $user_id)) {
|
||||
$meta['downloads'] = $downloads;
|
||||
} elseif ($pay_type === DomainModel::PAY_TYPE_DOWNLOAD && !$this->user_can_cap('new_post_pay_download', $user_id)) {
|
||||
if ($downloads !== []) {
|
||||
$pay_type = DomainModel::PAY_TYPE_DOWNLOAD;
|
||||
} elseif ($pay_type === DomainModel::PAY_TYPE_DOWNLOAD) {
|
||||
$pay_type = DomainModel::PAY_TYPE_READING;
|
||||
}
|
||||
} elseif ($pay_type === DomainModel::PAY_TYPE_DOWNLOAD) {
|
||||
$pay_type = DomainModel::PAY_TYPE_READING;
|
||||
$meta['downloads'] = [];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user