进行了一些小修复

This commit is contained in:
2026-08-26 23:52:23 +08:00
parent fff1590a43
commit 02d456b00b
3 changed files with 23 additions and 49 deletions
-2
View File
@@ -175,8 +175,6 @@ class FrontSubmit {
$attachment_id = (int) $attachment_id;
wp_update_post(['ID' => $attachment_id, 'post_author' => $user_id]);
update_post_meta($attachment_id, '_aksrt_front_submit_upload_type', $kind);
update_post_meta($attachment_id, '_aksrt_front_submit_upload_user_id', $user_id);
$url = wp_get_attachment_url($attachment_id);
if (!$url) {
+1 -47
View File
@@ -48,7 +48,7 @@ trait FrontSubmitPay {
$pay_type = DomainModel::PAY_TYPE_READING;
}
$downloads = $this->normalize_front_downloads($raw['downloads'] ?? [], $user_id);
$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;
$meta['downloads'] = $downloads;
@@ -202,52 +202,6 @@ trait FrontSubmitPay {
return $this->parse_front_points((string) $matches[1]) ?? 0;
}
/**
* @param mixed $raw
* @return array<int, array<string, string>>
*/
private function normalize_front_downloads($raw, int $user_id): array {
if (!is_array($raw)) {
return [];
}
$out = [];
foreach ($raw as $row) {
if (!is_array($row)) {
continue;
}
$url = (string) ($row['url'] ?? '');
$url = esc_url_raw(trim($url));
if ($url === '') {
continue;
}
$attachment_id = attachment_url_to_postid($url);
if ($attachment_id > 0 && !$this->can_use_front_submit_resource($attachment_id, $user_id)) {
continue;
}
$out[] = [
'label' => sanitize_text_field((string) ($row['label'] ?? '')),
'url' => $url,
'type' => $attachment_id > 0 ? 'direct' : 'external',
'extract_code' => sanitize_text_field((string) ($row['extract_code'] ?? '')),
'copy_key' => sanitize_text_field((string) ($row['copy_key'] ?? '')),
'copy_val' => sanitize_text_field((string) ($row['copy_val'] ?? '')),
'class' => sanitize_key((string) ($row['class'] ?? '')),
];
}
return DomainModel::sanitize_downloads($out);
}
private function can_use_front_submit_resource(int $attachment_id, int $user_id): bool {
if ($attachment_id <= 0 || !$this->user_can_cap('upload_resource_attachment', $user_id)) {
return false;
}
$attachment = get_post($attachment_id);
return $attachment instanceof \WP_Post
&& $attachment->post_type === 'attachment'
&& (int) $attachment->post_author === $user_id
&& get_post_meta($attachment_id, '_aksrt_front_submit_upload_type', true) === 'resource';
}
/**
* @param array<string, mixed> $meta
*/