feat(submit): add user media library

This commit is contained in:
kate522 committed 2026-09-04 22:53:33 +08:00
1 parent 44e165d34e
commit f3fcfe45da
23 files changed
+1321 -945

No files matched your search

+26
View File
@@ -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;
}
}