fix(homepage): unify runtime rendering contract
This commit is contained in:
1 parent
bd6f55c42e
commit
bcebd37807
13 files changed
+951
-926
No files matched your search
@@ -0,0 +1,184 @@
|
||||
<?php
|
||||
/**
|
||||
* Homepage header component visibility and rendering.
|
||||
*
|
||||
* @package AKSRT
|
||||
*/
|
||||
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
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 {
|
||||
global $wp_query;
|
||||
|
||||
if (is_admin() || !($wp_query instanceof WP_Query)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
$settings = class_exists('\AKSRT\Settings\Settings')
|
||||
? \AKSRT\Settings\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;
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('aksrt_header_slide')) {
|
||||
/**
|
||||
* Render header slider after the site header (outside main).
|
||||
*/
|
||||
function aksrt_header_slide(): void {
|
||||
if (!aksrt_header_slide_is_show()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Reuse existing hero partial as the slider implementation.
|
||||
get_template_part('templates/parts/home-modules/module', 'hero');
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user