Merge pull request 'feat(user-center): upgrade posts panel to creator center' (#396) from worktree-user-creator-center-zibll-prd into main

Reviewed-on: CYL/wordpress-theme-aksrt#396
This commit is contained in:
kate522 committed 2026-08-06 16:30:21 +08:00
commit c42b680397
7 files changed
+123 -36

No files matched your search

+23
View File
@@ -479,6 +479,29 @@
padding-bottom: 12px; padding-bottom: 12px;
border-bottom: 2px solid var(--color-primary-50); border-bottom: 2px solid var(--color-primary-50);
} }
.creator-center-header {
align-items: flex-start;
}
.creator-center-heading {
min-width: 220px;
}
.creator-center-heading__summary {
margin: 4px 0 0;
color: var(--color-ink-4);
font-size: 12px;
}
.creator-center-actions {
display: flex;
flex-wrap: wrap;
align-items: center;
justify-content: flex-end;
gap: 10px;
}
.creator-center-actions .profile-status-filter {
justify-content: flex-end;
}
.widget-title--inline { .widget-title--inline {
margin: 0; margin: 0;
padding: 0; padding: 0;
+34 -1
View File
@@ -16,6 +16,7 @@
var ajaxUrl = cfg.ajaxUrl || ''; var ajaxUrl = cfg.ajaxUrl || '';
var publicNonce = cfg.publicNonce || ''; var publicNonce = cfg.publicNonce || '';
var settingsNonce = cfg.settingsNonce || ''; var settingsNonce = cfg.settingsNonce || '';
var submitNonce = cfg.submitNonce || '';
var userId = cfg.userId || 0; var userId = cfg.userId || 0;
var i18n = cfg.i18n || {}; var i18n = cfg.i18n || {};
var tabAliases = cfg.tabAliases || {}; var tabAliases = cfg.tabAliases || {};
@@ -698,13 +699,44 @@
}); });
} }
/* ==================== 初始化 ==================== */ /* ==================== 创作中心文章操作 ==================== */
function initCreatorPostActions() {
document.addEventListener('click', function(e) {
var btn = e.target.closest('[data-action="delete-post"]');
if (!btn || btn.disabled) return;
if (!confirm(i18n.confirmDeletePost || '确定删除这篇文章?')) return;
var postId = btn.getAttribute('data-post-id');
var nonce = btn.getAttribute('data-nonce') || submitNonce;
if (!postId || !nonce) return;
btn.disabled = true;
var body = new URLSearchParams();
body.set('action', 'aksrt_delete_post');
body.set('id', postId);
body.set('_nonce', nonce);
fetch(ajaxUrl, { method: 'POST', headers: { 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8' }, credentials: 'same-origin', body: body.toString() })
.then(function(r) { return r.json(); })
.then(function(res) {
if (res && res.success) {
var item = btn.closest('.profile-list-item');
if (item) item.remove();
showToast((res.data && res.data.message) || '文章已经删除');
} else {
btn.disabled = false;
showToast((res && res.data && res.data.message) || i18n.operationFailed || '操作失败');
}
})
.catch(function() { btn.disabled = false; showToast(i18n.networkError || '网络错误'); });
});
}
if (document.readyState === 'loading') { if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', function() { document.addEventListener('DOMContentLoaded', function() {
initDashboardNavigation(); initDashboardNavigation();
initProfileForm(); initProfileForm();
initAuthForm(); initAuthForm();
initUnfavorite(); initUnfavorite();
initCreatorPostActions();
initNotifications(); initNotifications();
initSettings(); initSettings();
}); });
@@ -713,6 +745,7 @@
initProfileForm(); initProfileForm();
initAuthForm(); initAuthForm();
initUnfavorite(); initUnfavorite();
initCreatorPostActions();
initNotifications(); initNotifications();
initSettings(); initSettings();
} }
+1
View File
@@ -344,6 +344,7 @@ if (!function_exists('aksrt_user_center_runtime_config')) {
'userId' => $user_id, 'userId' => $user_id,
'restUrl' => rest_url('aksrt/v1'), 'restUrl' => rest_url('aksrt/v1'),
'restNonce' => wp_create_nonce('wp_rest'), 'restNonce' => wp_create_nonce('wp_rest'),
'submitNonce' => wp_create_nonce('aksrt_submit'),
'defaultTab' => $default_tab, 'defaultTab' => $default_tab,
'activeTab' => $active_tab, 'activeTab' => $active_tab,
'tabAliases' => [ 'tabAliases' => [
@@ -21,27 +21,37 @@ $ps_args = [
'update_post_term_cache' => true, 'update_post_term_cache' => true,
]; ];
$q = new WP_Query($ps_args); $q = new WP_Query($ps_args);
$front_submit = class_exists('\\AKSRT\\Core\\FrontSubmit') ? \AKSRT\Core\FrontSubmit::get_instance() : null;
if ($q->have_posts()) : if ($q->have_posts()) :
?> ?>
<div class="profile-list"> <div class="profile-list creator-center-post-list">
<?php <?php
while ($q->have_posts()) : while ($q->have_posts()) :
$q->the_post(); $q->the_post();
$st = get_post_status(); $st = get_post_status();
$status_label = ''; $status_map = [
if ('publish' !== $st) { 'publish' => __('已发布', 'aksrt'),
$st_map = [ 'draft' => __('草稿', 'aksrt'),
'draft' => __('草稿', 'aksrt'), 'pending' => __('待审', 'aksrt'),
'pending' => __('待审', 'aksrt'), 'private' => __('私密', 'aksrt'),
'private' => __('私密', 'aksrt'), 'future' => __('定时', 'aksrt'),
'future' => __('定时', 'aksrt'), ];
]; $status_label = $status_map[$st] ?? $st;
$status_label = $st_map[$st] ?? $st; $can_delete = $front_submit && $front_submit->can_delete_post(get_the_ID(), (int) $user_id);
} $edit_link = $front_submit && $front_submit->can_edit_post(get_the_ID(), (int) $user_id)
$edit_link = get_edit_post_link(); ? aksrt_get_new_post_url(get_the_ID())
: '';
$view_link = get_permalink();
$action = $edit_link
? ['type' => 'edit', 'url' => $edit_link, 'label' => __('编辑', 'aksrt')]
: ('publish' === $st && $view_link ? ['type' => 'view', 'url' => $view_link, 'label' => __('预览', 'aksrt')] : []);
get_template_part('templates/parts/content', 'profile-list-item', [ get_template_part('templates/parts/content', 'profile-list-item', [
'action' => $edit_link ? ['type' => 'edit', 'url' => $edit_link, 'label' => __('编辑', 'aksrt')] : [], 'action' => $action,
'status' => $status_label, 'status' => $status_label,
'delete_action' => [
'enabled' => $can_delete,
'nonce' => wp_create_nonce('aksrt_submit'),
],
]); ]);
endwhile; endwhile;
?> ?>
@@ -54,7 +64,7 @@ else :
$svg_empty_post, $svg_empty_post,
__('还没有文章', 'aksrt'), __('还没有文章', 'aksrt'),
__('试试发布你的第一篇文章吧。', 'aksrt'), __('试试发布你的第一篇文章吧。', 'aksrt'),
admin_url('post-new.php'), !empty($new_post_url) ? $new_post_url : '',
__('写文章', 'aksrt') __('写文章', 'aksrt')
); );
endif; endif;
@@ -9,16 +9,29 @@ defined('ABSPATH') || exit;
$context = is_array($args['context'] ?? null) ? $args['context'] : []; $context = is_array($args['context'] ?? null) ? $args['context'] : [];
extract($context, EXTR_SKIP); // phpcs:ignore WordPress.PHP.DontExtract.extract_extract extract($context, EXTR_SKIP); // phpcs:ignore WordPress.PHP.DontExtract.extract_extract
$can_submit_posts = class_exists('\\AKSRT\\Core\\FrontSubmit')
&& \AKSRT\Core\FrontSubmit::get_instance()->can_submit((int) $user_id);
?> ?>
<div class="widget-card"> <div class="widget-card">
<div class="profile-list-header"> <div class="profile-list-header creator-center-header">
<h3 class="widget-title widget-title--inline"> <div class="creator-center-heading">
<?php <h2 class="widget-title widget-title--inline"><?php esc_html_e('创作中心', 'aksrt'); ?></h2>
/* translators: %d: post count */ <p class="creator-center-heading__summary">
printf(esc_html__('我的文章(%d 篇)', 'aksrt'), $post_count); <?php
?> /* translators: %d: total post count */
</h3> printf(esc_html__('管理你的文章、草稿和审核状态(共 %d 篇)', 'aksrt'), $post_count);
<?php require __DIR__ . '/posts-status-filter.php'; ?> ?>
</p>
</div>
<div class="creator-center-actions">
<?php if (!empty($new_post_url) && $can_submit_posts) : ?>
<a class="btn-primary btn-sm" href="<?php echo esc_url($new_post_url); ?>">
<span aria-hidden="true">+</span>
<?php esc_html_e('新建文章', 'aksrt'); ?>
</a>
<?php endif; ?>
<?php require __DIR__ . '/posts-status-filter.php'; ?>
</div>
</div> </div>
<?php require __DIR__ . '/posts-list.php'; ?> <?php require __DIR__ . '/posts-list.php'; ?>
</div> </div>
+1 -1
View File
@@ -128,7 +128,7 @@ class Center {
'type' => 'panel', 'type' => 'panel',
], ],
'posts' => [ 'posts' => [
'label' => __('我的文章', 'aksrt'), 'label' => __('创作中心', 'aksrt'),
'icon' => 'file-alt', 'icon' => 'file-alt',
'priority' => 20, 'priority' => 20,
'type' => 'panel', 'type' => 'panel',
+18 -11
View File
@@ -21,20 +21,21 @@ if (!is_array($action)) {
$action_type = isset($action['type']) ? (string) $action['type'] : ''; $action_type = isset($action['type']) ? (string) $action['type'] : '';
$action_url = isset($action['url']) ? (string) $action['url'] : ''; $action_url = isset($action['url']) ? (string) $action['url'] : '';
$action_label = isset($action['label']) ? (string) $action['label'] : ''; $action_label = isset($action['label']) ? (string) $action['label'] : '';
$delete_action = isset($args['delete_action']) && is_array($args['delete_action']) ? $args['delete_action'] : [];
$status_label = isset($args['status']) ? (string) $args['status'] : (string) get_query_var('aksrt_profile_item_status', ''); $status_label = isset($args['status']) ? (string) $args['status'] : (string) get_query_var('aksrt_profile_item_status', '');
$post_id = get_the_ID(); $post_id = get_the_ID();
$permalink = get_permalink(); $permalink = get_permalink();
$title = get_the_title(); $title = get_the_title();
$date_iso = get_the_date('c'); $date_iso = get_the_date('c');
$date_label = get_the_date(); $date_label = get_the_date();
$excerpt = wp_trim_words(get_the_excerpt(), 30, '…'); $excerpt = wp_trim_words(get_the_excerpt(), 30, '…');
$comment_count = (int) get_comments_number(); $comment_count = (int) get_comments_number();
$categories = get_the_category() ?: []; $categories = get_the_category() ?: [];
$tags = get_the_tags() ?: []; $tags = get_the_tags() ?: [];
?> ?>
<article <?php post_class('profile-list-item'); ?>> <article <?php post_class('profile-list-item'); ?> data-post-id="<?php echo esc_attr((string) $post_id); ?>">
<div class="profile-list-item__main"> <div class="profile-list-item__main">
<div class="profile-list-item__head"> <div class="profile-list-item__head">
<h3 class="profile-list-item__title"> <h3 class="profile-list-item__title">
@@ -89,7 +90,7 @@ $tags = get_the_tags() ?: [];
break; break;
} }
if ('unfavorite' === $action_type) : if ('unfavorite' === $action_type) :
?> ?>
<button type="button" class="<?php echo esc_attr($action_class); ?>" data-post-id="<?php echo esc_attr((string) $post_id); ?>" data-action="unfavorite" title="<?php echo esc_attr($action_label); ?>"> <button type="button" class="<?php echo esc_attr($action_class); ?>" data-post-id="<?php echo esc_attr((string) $post_id); ?>" data-action="unfavorite" title="<?php echo esc_attr($action_label); ?>">
<span class="profile-list-item__action-icon"><?php echo $icon_svg; // phpcs:ignore ?></span> <span class="profile-list-item__action-icon"><?php echo $icon_svg; // phpcs:ignore ?></span>
<span class="profile-list-item__action-label"><?php echo esc_html($action_label); ?></span> <span class="profile-list-item__action-label"><?php echo esc_html($action_label); ?></span>
@@ -101,6 +102,12 @@ $tags = get_the_tags() ?: [];
</a> </a>
<?php endif; ?> <?php endif; ?>
<?php endif; ?> <?php endif; ?>
<?php if (!empty($delete_action['enabled'])) : ?>
<button type="button" class="profile-list-item__action profile-list-item__action--delete" data-action="delete-post" data-post-id="<?php echo esc_attr((string) $post_id); ?>" data-nonce="<?php echo esc_attr((string) ($delete_action['nonce'] ?? '')); ?>">
<span class="profile-list-item__action-label"><?php esc_html_e('删除', 'aksrt'); ?></span>
</button>
<?php endif; ?>
</div> </div>
</div> </div>
</article> </article>