进行了一些小优化
This commit is contained in:
1 parent
4a4009133c
commit
11f1c23fa7
12 files changed
+463
-10
No files matched your search
@@ -178,6 +178,7 @@ if (!function_exists('aksrt_capture_user_center_view')) {
|
||||
'orders' => 'orders',
|
||||
'auth' => 'auth',
|
||||
'revenue' => 'revenue',
|
||||
'msg' => 'msg',
|
||||
'settings' => 'settings',
|
||||
'header' => 'header',
|
||||
'sidebar' => 'sidebar',
|
||||
@@ -201,7 +202,7 @@ if (!function_exists('aksrt_capture_user_center_panel')) {
|
||||
* Capture a built-in or registered user-center panel body.
|
||||
*/
|
||||
function aksrt_capture_user_center_panel(string $tab_key, array $tab, array $context): string {
|
||||
$built_in_tabs = ['profile', 'level', 'creator', 'posts', 'follow', 'comments', 'favorites', 'credits', 'vip', 'orders', 'auth', 'revenue', 'settings'];
|
||||
$built_in_tabs = ['profile', 'level', 'creator', 'posts', 'follow', 'comments', 'favorites', 'credits', 'vip', 'orders', 'auth', 'revenue', 'msg', 'settings'];
|
||||
if (in_array($tab_key, $built_in_tabs, true)) {
|
||||
return aksrt_capture_user_center_view($tab_key, $context);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
/**
|
||||
* User center notification preferences panel.
|
||||
*
|
||||
* @package AKSRT
|
||||
*/
|
||||
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
$context = is_array($args['context'] ?? null) ? $args['context'] : [];
|
||||
$user_id = (int) ($context['user_id'] ?? get_current_user_id());
|
||||
$preferences = class_exists('\AKSRT\User\NotificationPreferences')
|
||||
? \AKSRT\User\NotificationPreferences::get($user_id)
|
||||
: ['posts' => true, 'like' => true, 'system' => true];
|
||||
$items = [
|
||||
'posts' => [
|
||||
'title' => __('文章评论', 'aksrt'),
|
||||
'description' => __('接收文章、评论、收藏等相关消息', 'aksrt'),
|
||||
],
|
||||
'like' => [
|
||||
'title' => __('点赞喜欢', 'aksrt'),
|
||||
'description' => __('接收点赞、关注等相关消息', 'aksrt'),
|
||||
],
|
||||
'system' => [
|
||||
'title' => __('系统消息', 'aksrt'),
|
||||
'description' => __('接收订单、活动、等系统消息', 'aksrt'),
|
||||
],
|
||||
];
|
||||
?>
|
||||
<form class="uc-notification-preferences" data-aksrt-notification-preferences>
|
||||
<div class="uc-notification-preferences__header">
|
||||
<div>
|
||||
<h2><?php esc_html_e('消息通知', 'aksrt'); ?></h2>
|
||||
<p><?php esc_html_e('选择你希望接收的站内消息类型。', 'aksrt'); ?></p>
|
||||
</div>
|
||||
<span class="uc-notification-preferences__header-icon" aria-hidden="true"><i class="fa fas fa-bell"></i></span>
|
||||
</div>
|
||||
|
||||
<div class="uc-notification-preferences__list">
|
||||
<?php foreach ($items as $key => $item) : ?>
|
||||
<label class="uc-notification-preference" for="aksrt-notification-<?php echo esc_attr($key); ?>">
|
||||
<span class="uc-notification-preference__copy">
|
||||
<strong><?php echo esc_html($item['title']); ?></strong>
|
||||
<small><?php echo esc_html($item['description']); ?></small>
|
||||
</span>
|
||||
<span class="uc-notification-switch">
|
||||
<input id="aksrt-notification-<?php echo esc_attr($key); ?>" type="checkbox" name="<?php echo esc_attr($key); ?>" value="1" role="switch" <?php checked(!empty($preferences[$key])); ?>>
|
||||
<span aria-hidden="true"></span>
|
||||
</span>
|
||||
</label>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
|
||||
<div class="uc-notification-preferences__footer">
|
||||
<button type="submit" class="btn-primary"><?php esc_html_e('保存设置', 'aksrt'); ?></button>
|
||||
</div>
|
||||
</form>
|
||||
@@ -43,8 +43,8 @@ $settings = array_values(array_filter([
|
||||
'label' => __('消息通知', 'aksrt'),
|
||||
'icon' => 'bell',
|
||||
'tone' => 'notice',
|
||||
'url' => (string) ($messages_url ?? ''),
|
||||
'count' => (int) ($notification_unread_count ?? 0),
|
||||
'url' => isset($dashboard_tabs['msg']) ? aksrt_get_user_center_tab_url('msg') : '',
|
||||
'tab' => 'msg',
|
||||
],
|
||||
[
|
||||
'label' => __('个人资料', 'aksrt'),
|
||||
|
||||
@@ -32,7 +32,11 @@ function aksrt_get_user_notifications(int $user_id = 0): array {
|
||||
'status' => 'hold',
|
||||
]);
|
||||
|
||||
if ($pending_comments > 0 && (!class_exists('\AKSRT\Settings\Settings') || \AKSRT\Settings\Settings::notification_enabled('pending_comments'))) {
|
||||
if (
|
||||
$pending_comments > 0
|
||||
&& (!class_exists('\AKSRT\Settings\Settings') || \AKSRT\Settings\Settings::notification_enabled('pending_comments'))
|
||||
&& (!class_exists('\AKSRT\User\NotificationPreferences') || \AKSRT\User\NotificationPreferences::allows($user_id, 'pending_comments'))
|
||||
) {
|
||||
$items[] = [
|
||||
'type' => 'pending_comments',
|
||||
'title' => __('评论待审核', 'aksrt'),
|
||||
@@ -249,6 +253,9 @@ if (!function_exists('aksrt_add_user_notification')) :
|
||||
function aksrt_add_user_notification(int $user_id, array $payload): void {
|
||||
if ($user_id <= 0) return;
|
||||
$type = sanitize_key((string) ($payload['type'] ?? 'notice'));
|
||||
if (class_exists('\AKSRT\User\NotificationPreferences') && !\AKSRT\User\NotificationPreferences::allows($user_id, $type)) {
|
||||
return;
|
||||
}
|
||||
if (class_exists('\AKSRT\Settings\Settings') && !\AKSRT\Settings\Settings::notification_enabled($type)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ add_action('template_redirect', function () {
|
||||
$tab = $tab === 'balance' ? 'credits' : sanitize_key($tab);
|
||||
$allowed = class_exists('\\AKSRT\\User\\Center')
|
||||
? array_keys(\AKSRT\User\Center::get_instance()->get_dashboard_tabs())
|
||||
: ['profile', 'level', 'creator', 'posts', 'follow', 'comments', 'favorites', 'credits', 'vip', 'orders', 'auth', 'revenue', 'settings'];
|
||||
: ['profile', 'level', 'creator', 'posts', 'follow', 'comments', 'favorites', 'credits', 'vip', 'orders', 'auth', 'revenue', 'msg', 'settings'];
|
||||
if (!in_array($tab, $allowed, true)) {
|
||||
global $wp_query;
|
||||
if ($wp_query instanceof WP_Query) { $wp_query->set_404(); }
|
||||
|
||||
Reference in new issue
Block a user