feat(user-center): upgrade posts panel to creator center
This commit is contained in:
@@ -479,6 +479,29 @@
|
||||
padding-bottom: 12px;
|
||||
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 {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
var ajaxUrl = cfg.ajaxUrl || '';
|
||||
var publicNonce = cfg.publicNonce || '';
|
||||
var settingsNonce = cfg.settingsNonce || '';
|
||||
var submitNonce = cfg.submitNonce || '';
|
||||
var userId = cfg.userId || 0;
|
||||
var i18n = cfg.i18n || {};
|
||||
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') {
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
initDashboardNavigation();
|
||||
initProfileForm();
|
||||
initAuthForm();
|
||||
initUnfavorite();
|
||||
initCreatorPostActions();
|
||||
initNotifications();
|
||||
initSettings();
|
||||
});
|
||||
@@ -713,6 +745,7 @@
|
||||
initProfileForm();
|
||||
initAuthForm();
|
||||
initUnfavorite();
|
||||
initCreatorPostActions();
|
||||
initNotifications();
|
||||
initSettings();
|
||||
}
|
||||
|
||||
@@ -344,6 +344,7 @@ if (!function_exists('aksrt_user_center_runtime_config')) {
|
||||
'userId' => $user_id,
|
||||
'restUrl' => rest_url('aksrt/v1'),
|
||||
'restNonce' => wp_create_nonce('wp_rest'),
|
||||
'submitNonce' => wp_create_nonce('aksrt_submit'),
|
||||
'defaultTab' => $default_tab,
|
||||
'activeTab' => $active_tab,
|
||||
'tabAliases' => [
|
||||
|
||||
@@ -21,27 +21,37 @@ $ps_args = [
|
||||
'update_post_term_cache' => true,
|
||||
];
|
||||
$q = new WP_Query($ps_args);
|
||||
$front_submit = class_exists('\\AKSRT\\Core\\FrontSubmit') ? \AKSRT\Core\FrontSubmit::get_instance() : null;
|
||||
if ($q->have_posts()) :
|
||||
?>
|
||||
<div class="profile-list">
|
||||
<div class="profile-list creator-center-post-list">
|
||||
<?php
|
||||
while ($q->have_posts()) :
|
||||
$q->the_post();
|
||||
$st = get_post_status();
|
||||
$status_label = '';
|
||||
if ('publish' !== $st) {
|
||||
$st_map = [
|
||||
$status_map = [
|
||||
'publish' => __('已发布', 'aksrt'),
|
||||
'draft' => __('草稿', 'aksrt'),
|
||||
'pending' => __('待审', 'aksrt'),
|
||||
'private' => __('私密', 'aksrt'),
|
||||
'future' => __('定时', 'aksrt'),
|
||||
];
|
||||
$status_label = $st_map[$st] ?? $st;
|
||||
}
|
||||
$edit_link = get_edit_post_link();
|
||||
$status_label = $status_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)
|
||||
? 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', [
|
||||
'action' => $edit_link ? ['type' => 'edit', 'url' => $edit_link, 'label' => __('编辑', 'aksrt')] : [],
|
||||
'action' => $action,
|
||||
'status' => $status_label,
|
||||
'delete_action' => [
|
||||
'enabled' => $can_delete,
|
||||
'nonce' => wp_create_nonce('aksrt_submit'),
|
||||
],
|
||||
]);
|
||||
endwhile;
|
||||
?>
|
||||
@@ -54,7 +64,7 @@ else :
|
||||
$svg_empty_post,
|
||||
__('还没有文章', 'aksrt'),
|
||||
__('试试发布你的第一篇文章吧。', 'aksrt'),
|
||||
admin_url('post-new.php'),
|
||||
!empty($new_post_url) ? $new_post_url : '',
|
||||
__('写文章', 'aksrt')
|
||||
);
|
||||
endif;
|
||||
|
||||
@@ -9,16 +9,29 @@ defined('ABSPATH') || exit;
|
||||
|
||||
$context = is_array($args['context'] ?? null) ? $args['context'] : [];
|
||||
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="profile-list-header">
|
||||
<h3 class="widget-title widget-title--inline">
|
||||
<div class="profile-list-header creator-center-header">
|
||||
<div class="creator-center-heading">
|
||||
<h2 class="widget-title widget-title--inline"><?php esc_html_e('创作中心', 'aksrt'); ?></h2>
|
||||
<p class="creator-center-heading__summary">
|
||||
<?php
|
||||
/* translators: %d: post count */
|
||||
printf(esc_html__('我的文章(%d 篇)', 'aksrt'), $post_count);
|
||||
/* translators: %d: total post count */
|
||||
printf(esc_html__('管理你的文章、草稿和审核状态(共 %d 篇)', 'aksrt'), $post_count);
|
||||
?>
|
||||
</h3>
|
||||
</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>
|
||||
<?php require __DIR__ . '/posts-list.php'; ?>
|
||||
</div>
|
||||
|
||||
+1
-1
@@ -128,7 +128,7 @@ class Center {
|
||||
'type' => 'panel',
|
||||
],
|
||||
'posts' => [
|
||||
'label' => __('我的文章', 'aksrt'),
|
||||
'label' => __('创作中心', 'aksrt'),
|
||||
'icon' => 'file-alt',
|
||||
'priority' => 20,
|
||||
'type' => 'panel',
|
||||
|
||||
@@ -21,6 +21,7 @@ if (!is_array($action)) {
|
||||
$action_type = isset($action['type']) ? (string) $action['type'] : '';
|
||||
$action_url = isset($action['url']) ? (string) $action['url'] : '';
|
||||
$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', '');
|
||||
|
||||
@@ -34,7 +35,7 @@ $comment_count = (int) get_comments_number();
|
||||
$categories = get_the_category() ?: [];
|
||||
$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__head">
|
||||
<h3 class="profile-list-item__title">
|
||||
@@ -101,6 +102,12 @@ $tags = get_the_tags() ?: [];
|
||||
</a>
|
||||
<?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>
|
||||
</article>
|
||||
|
||||
Reference in New Issue
Block a user