fix(header): wire multi-function page-type enable like zibll

Connect header_components_show_on through aksrt_header_slide_is_show with
zibll page-type matching, drop the homepage-only gate, align admin options,
apply nav color, enqueue by is_show, remove dead float-btn schema, and
consume footer_tabbar_single extend mode on post singles.
This commit is contained in:
kate522 committed 2026-07-15 17:12:51 +08:00
1 parent 3e3a4631f0
commit bfb64211ee
12 files changed
+445 -285

No files matched your search

+145 -7
View File
@@ -822,27 +822,165 @@ if (!function_exists('aksrt_homepage_render_section')) {
}
}
if (!function_exists('aksrt_header_components_page_type_keys')) {
/**
* Allowed page-type keys for header multi-function (zibll CFS_Module::page_type).
*
* @return list<string>
*/
function aksrt_header_components_page_type_keys(): array {
return [
'home',
'topics',
'category',
'tag',
'author',
'single',
'search',
'forum_home',
'forum_plate',
'forum_post',
'page',
];
}
}
if (!function_exists('aksrt_header_slide_excluded_page_templates')) {
/**
* Page templates excluded from the generic "page" type (zibll parity).
*
* @return list<string>
*/
function aksrt_header_slide_excluded_page_templates(): array {
return [
'templates/pages/page-sign.php',
'templates/pages/page-login.php',
'templates/pages/page-register.php',
'templates/pages/page-reset-password.php',
'templates/pages/page-bind-account.php',
'templates/pages/page-verify-email.php',
'templates/pages/page-download.php',
'templates/pages/page-download-file.php',
'templates/pages/page-forums.php',
];
}
}
if (!function_exists('aksrt_header_slide_match_page_type')) {
/**
* Whether the current main query matches a header-slider page-type key.
*
* Mirrors zibll zib_header_slide_is_show() matching rules.
*/
function aksrt_header_slide_match_page_type(string $type): bool {
global $wp_query;
$type = sanitize_key($type);
if ($type === '' || !($wp_query instanceof WP_Query)) {
return false;
}
$raw_post_type = $wp_query->get('post_type');
if (is_array($raw_post_type)) {
$post_type = (string) reset($raw_post_type);
} else {
$post_type = (string) $raw_post_type;
}
// Special keys that are not plain is_{$type} flags.
if ($type === 'topics') {
return is_tax('topics');
}
if ($type === 'forum_home') {
return is_page_template('templates/pages/page-forums.php');
}
if ($type === 'forum_plate') {
return is_singular('aksrt_forum_plate') || $post_type === 'aksrt_forum_plate';
}
if ($type === 'forum_post') {
return is_singular('aksrt_forum_topic') || $post_type === 'aksrt_forum_topic';
}
// Generic WP_Query is_* flags (home/category/tag/author/single/search/page).
$query_flag = 'is_' . $type;
if (empty($wp_query->{$query_flag})) {
return false;
}
if ($type === 'single') {
// Only ordinary posts; CPTs use dedicated keys.
return $post_type === '' || $post_type === 'post';
}
if ($type === 'page') {
foreach (aksrt_header_slide_excluded_page_templates() as $template) {
if (is_page_template($template)) {
return false;
}
}
return true;
}
return true;
}
}
if (!function_exists('aksrt_header_slide_is_show')) {
/**
* Whether the header multi-function slider should render (zibll header-slider contract).
*
* Master switch: non-empty header_components_show_on + current page-type match.
* Device rule: header_components_device_visibility (only_pc / only_sm).
*/
function aksrt_header_slide_is_show(): bool {
if (is_admin()) {
global $wp_query;
if (is_admin() || !($wp_query instanceof WP_Query)) {
return false;
}
// Match zibll: only first page of the posts index / front page.
if (!(is_front_page() || is_home())) {
// Not on paginated views (zibll: query_vars['paged'] non-empty).
$paged = (int) $wp_query->get('paged');
if ($paged > 1) {
return false;
}
if (function_exists('aksrt_homepage_get_current_page') && aksrt_homepage_get_current_page() > 1) {
return false;
}
return function_exists('aksrt_homepage_module_hero_enabled')
? aksrt_homepage_module_hero_enabled()
: true;
$settings = class_exists('AKSRT_Settings')
? AKSRT_Settings::get_header_components_settings()
: [];
$show_on = isset($settings['show_on_pages']) ? (array) $settings['show_on_pages'] : [];
$allowed = array_values(array_intersect(
array_map('sanitize_key', $show_on),
aksrt_header_components_page_type_keys()
));
// Empty selection = feature off (zibll header_slider_show).
if ($allowed === []) {
return false;
}
// Device visibility (zibll header_slider_show_type).
$show_type = (string) ($settings['show_type'] ?? '');
if ($show_type === 'only_pc' && wp_is_mobile()) {
return false;
}
if ($show_type === 'only_sm' && !wp_is_mobile()) {
return false;
}
foreach ($allowed as $type) {
if (aksrt_header_slide_match_page_type($type)) {
return true;
}
}
return false;
}
}
+101
View File
@@ -1283,3 +1283,104 @@ add_action('save_post_aksrt_banner', 'aksrt_flush_banner_cache');
add_action('deleted_post', 'aksrt_flush_banner_cache');
add_action('trashed_post', 'aksrt_flush_banner_cache');
endif;
if (!function_exists('aksrt_should_use_footer_tabbar_single_extend')) :
/**
* Whether single-post extended footer tabbar should replace the default items.
* Zibll: footer_tabbar_single.s === extend && is_single(post).
*/
function aksrt_should_use_footer_tabbar_single_extend(): bool {
if (!is_singular('post')) {
return false;
}
if (!class_exists('AKSRT_Settings') || !method_exists('AKSRT_Settings', 'get_footer_tabbar_single')) {
return false;
}
return AKSRT_Settings::get_footer_tabbar_single() === 'extend';
}
endif;
if (!function_exists('aksrt_render_footer_tabbar_single_extend')) :
/**
* Render single-post extended footer tabbar actions (like / favorite / share / comment).
*
* @param bool $show_text Whether to show text labels under icons.
*/
function aksrt_render_footer_tabbar_single_extend(bool $show_text = true): void {
$post_id = (int) get_the_ID();
if ($post_id <= 0) {
return;
}
$settings = function_exists('aksrt_resolve_single_post_display_settings')
? aksrt_resolve_single_post_display_settings($post_id)
: [];
$like_on = !isset($settings['like_enabled']) || !empty($settings['like_enabled']);
$favorite_on = !isset($settings['favorite_enabled']) || !empty($settings['favorite_enabled']);
$share_on = !isset($settings['share_enabled']) || !empty($settings['share_enabled']);
$comments_open = comments_open($post_id)
&& !(function_exists('aksrt_are_comments_closed') && aksrt_are_comments_closed());
$like_count = function_exists('aksrt_get_post_likes') ? (int) aksrt_get_post_likes($post_id) : 0;
$favorite_count = function_exists('aksrt_get_post_favorites') ? (int) aksrt_get_post_favorites($post_id) : 0;
$is_liked = function_exists('aksrt_is_post_liked') ? aksrt_is_post_liked($post_id) : false;
$is_favorited = function_exists('aksrt_is_post_favorited') ? aksrt_is_post_favorited($post_id) : false;
$comment_count = (int) get_comments_number($post_id);
if ($like_on) :
?>
<button type="button"
class="tabbar-item single-action-tabbar action-like<?php echo $is_liked ? ' is-active' : ''; ?>"
data-type="like"
data-post-id="<?php echo esc_attr((string) $post_id); ?>"
data-initial-active="<?php echo $is_liked ? '1' : '0'; ?>"
aria-label="<?php esc_attr_e('点赞', 'aksrt'); ?>">
<i class="<?php echo $is_liked ? 'fas' : 'far'; ?> fa-heart" aria-hidden="true"></i>
<?php if ($show_text) : ?><span data-stat-count="likes" data-base-count="<?php echo esc_attr((string) $like_count); ?>"><?php echo esc_html((string) $like_count); ?></span><?php endif; ?>
</button>
<?php
endif;
if ($favorite_on) :
?>
<button type="button"
class="tabbar-item single-action-tabbar action-favorite<?php echo $is_favorited ? ' is-active' : ''; ?>"
data-type="favorite"
data-post-id="<?php echo esc_attr((string) $post_id); ?>"
data-initial-active="<?php echo $is_favorited ? '1' : '0'; ?>"
aria-label="<?php esc_attr_e('收藏', 'aksrt'); ?>">
<i class="<?php echo $is_favorited ? 'fas' : 'far'; ?> fa-star" aria-hidden="true"></i>
<?php if ($show_text) : ?><span data-stat-count="favorites" data-base-count="<?php echo esc_attr((string) $favorite_count); ?>"><?php echo esc_html((string) $favorite_count); ?></span><?php endif; ?>
</button>
<?php
endif;
if ($share_on) :
?>
<button type="button"
class="tabbar-item single-action-tabbar action-share"
data-type="share"
aria-haspopup="true"
aria-expanded="false"
aria-label="<?php esc_attr_e('分享', 'aksrt'); ?>">
<i class="fas fa-share-alt" aria-hidden="true"></i>
<?php if ($show_text) : ?><span><?php esc_html_e('分享', 'aksrt'); ?></span><?php endif; ?>
</button>
<?php
endif;
if ($comments_open) :
?>
<a href="#comments"
class="tabbar-item single-action-tabbar"
data-type="comment"
aria-label="<?php esc_attr_e('评论', 'aksrt'); ?>">
<i class="far fa-comment" aria-hidden="true"></i>
<?php if ($show_text) : ?><span><?php echo esc_html((string) $comment_count); ?></span><?php endif; ?>
</a>
<?php
endif;
}
endif;