163 lines
4.0 KiB
PHP
163 lines
4.0 KiB
PHP
<?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',
|
|
'category',
|
|
'tag',
|
|
'author',
|
|
'single',
|
|
'search',
|
|
'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',
|
|
];
|
|
}
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
// 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');
|
|
}
|
|
}
|