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
@@ -310,9 +310,9 @@ class GlobalController extends ControllerBase {
|
||||
'overrides' => $overrides,
|
||||
])
|
||||
: array_merge(['mode' => ($mode !== '' ? $mode : 'list'), 'context' => 'home'], $overrides);
|
||||
$render_config['skip_wrapper'] = true;
|
||||
$html = aksrt_render_post_list($query, $render_config, false);
|
||||
} elseif ($query->have_posts()) {
|
||||
$html = '<div class="posts-row aksrt-homepage__posts" data-view="' . esc_attr($mode) . '">';
|
||||
while ($query->have_posts()) {
|
||||
$query->the_post();
|
||||
if (function_exists('aksrt_homepage_render_post_card')) {
|
||||
@@ -321,7 +321,6 @@ class GlobalController extends ControllerBase {
|
||||
$html .= ob_get_clean();
|
||||
}
|
||||
}
|
||||
$html .= '</div>';
|
||||
wp_reset_postdata();
|
||||
}
|
||||
|
||||
|
||||
@@ -30,17 +30,13 @@ trait HomepageSettingsRest {
|
||||
$allowed_sorts = \AKSRT\Settings\HomeCms::homepage_allowed_sorts();
|
||||
$settings = [];
|
||||
|
||||
// --- Zibll main list contract ---
|
||||
if (array_key_exists('home_posts_list_s', $params) || array_key_exists('home_posts_list_enabled', $params)) {
|
||||
$settings['home_posts_list_s'] = array_key_exists('home_posts_list_s', $params)
|
||||
? !empty($params['home_posts_list_s'])
|
||||
: !empty($params['home_posts_list_enabled']);
|
||||
// --- Canonical Zibll main list contract ---
|
||||
if (array_key_exists('home_posts_list_s', $params)) {
|
||||
$settings['home_posts_list_s'] = !empty($params['home_posts_list_s']);
|
||||
}
|
||||
|
||||
if (array_key_exists('home_list1_orderby_s', $params) || array_key_exists('home_list_sort_enabled', $params)) {
|
||||
$settings['home_list1_orderby_s'] = array_key_exists('home_list1_orderby_s', $params)
|
||||
? !empty($params['home_list1_orderby_s'])
|
||||
: !empty($params['home_list_sort_enabled']);
|
||||
if (array_key_exists('home_list1_orderby_s', $params)) {
|
||||
$settings['home_list1_orderby_s'] = !empty($params['home_list1_orderby_s']);
|
||||
}
|
||||
|
||||
if (isset($params['home_list1_orderby_option']) && is_array($params['home_list1_orderby_option'])) {
|
||||
@@ -48,45 +44,22 @@ trait HomepageSettingsRest {
|
||||
$params['home_list1_orderby_option'],
|
||||
$allowed_sorts
|
||||
);
|
||||
} elseif (isset($params['home_list_sort_options']) && is_array($params['home_list_sort_options'])) {
|
||||
$settings['home_list1_orderby_option'] = $this->sanitize_home_list1_orderby_option(
|
||||
[
|
||||
'orderby' => $params['homepage_default_sort'] ?? 'modified',
|
||||
'options' => $params['home_list_sort_options'],
|
||||
],
|
||||
$allowed_sorts
|
||||
);
|
||||
} elseif (isset($params['homepage_default_sort'])) {
|
||||
$default = sanitize_key((string) $params['homepage_default_sort']);
|
||||
if (!in_array($default, $allowed_sorts, true)) {
|
||||
$default = 'modified';
|
||||
}
|
||||
$settings['home_list1_orderby_option'] = [
|
||||
'orderby' => $default,
|
||||
'options' => array_values(array_unique(array_merge([$default], ['date', 'views', 'likes', 'comments']))),
|
||||
];
|
||||
}
|
||||
|
||||
if (array_key_exists('index_list_title', $params) || array_key_exists('home_list_title', $params)) {
|
||||
$title = array_key_exists('index_list_title', $params)
|
||||
? (string) $params['index_list_title']
|
||||
: (string) $params['home_list_title'];
|
||||
$settings['index_list_title'] = sanitize_text_field($title);
|
||||
if (array_key_exists('index_list_title', $params)) {
|
||||
$settings['index_list_title'] = sanitize_text_field((string) $params['index_list_title']);
|
||||
}
|
||||
|
||||
if (isset($params['home_exclude_posts']) || isset($params['home_exclude_post_ids'])) {
|
||||
$raw = $params['home_exclude_posts'] ?? $params['home_exclude_post_ids'];
|
||||
$settings['home_exclude_posts'] = $this->sanitize_id_list($raw);
|
||||
if (array_key_exists('home_exclude_posts', $params)) {
|
||||
$settings['home_exclude_posts'] = $this->sanitize_id_list($params['home_exclude_posts']);
|
||||
}
|
||||
|
||||
if (isset($params['home_exclude_cats']) || isset($params['home_exclude_category_ids'])) {
|
||||
$raw = $params['home_exclude_cats'] ?? $params['home_exclude_category_ids'];
|
||||
$settings['home_exclude_cats'] = $this->sanitize_id_list($raw);
|
||||
if (array_key_exists('home_exclude_cats', $params)) {
|
||||
$settings['home_exclude_cats'] = $this->sanitize_id_list($params['home_exclude_cats']);
|
||||
}
|
||||
|
||||
if (isset($params['home_lists']) || isset($params['homepage_tabs'])) {
|
||||
$raw_tabs = $params['home_lists'] ?? $params['homepage_tabs'];
|
||||
$settings['home_lists'] = $this->sanitize_home_lists($raw_tabs, $allowed_sorts);
|
||||
if (array_key_exists('home_lists', $params)) {
|
||||
$settings['home_lists'] = $this->sanitize_home_lists($params['home_lists'], $allowed_sorts);
|
||||
}
|
||||
|
||||
// --- AKSRT presentation extras (optional, not Zibll dual-write) ---
|
||||
@@ -140,7 +113,7 @@ trait HomepageSettingsRest {
|
||||
$current[$key] = $value;
|
||||
}
|
||||
|
||||
// Drop superseded AKSRT-only keys when canonical Zibll keys are written.
|
||||
// Canonical writes also remove superseded aliases from persisted settings.
|
||||
$superseded = [
|
||||
'home_posts_list_enabled',
|
||||
'home_list_sort_enabled',
|
||||
@@ -152,38 +125,7 @@ trait HomepageSettingsRest {
|
||||
'homepage_default_sort',
|
||||
];
|
||||
foreach ($superseded as $dead_key) {
|
||||
if (array_key_exists($dead_key, $current) && (
|
||||
array_key_exists('home_posts_list_s', $settings)
|
||||
|| array_key_exists('home_list1_orderby_s', $settings)
|
||||
|| array_key_exists('home_list1_orderby_option', $settings)
|
||||
|| array_key_exists('index_list_title', $settings)
|
||||
|| array_key_exists('home_exclude_posts', $settings)
|
||||
|| array_key_exists('home_exclude_cats', $settings)
|
||||
|| array_key_exists('home_lists', $settings)
|
||||
)) {
|
||||
// Only strip keys we actually replaced in this request.
|
||||
}
|
||||
}
|
||||
if (array_key_exists('home_posts_list_s', $settings)) {
|
||||
unset($current['home_posts_list_enabled']);
|
||||
}
|
||||
if (array_key_exists('home_list1_orderby_s', $settings)) {
|
||||
unset($current['home_list_sort_enabled']);
|
||||
}
|
||||
if (array_key_exists('home_list1_orderby_option', $settings)) {
|
||||
unset($current['home_list_sort_options'], $current['homepage_default_sort']);
|
||||
}
|
||||
if (array_key_exists('index_list_title', $settings)) {
|
||||
unset($current['home_list_title']);
|
||||
}
|
||||
if (array_key_exists('home_exclude_posts', $settings)) {
|
||||
unset($current['home_exclude_post_ids']);
|
||||
}
|
||||
if (array_key_exists('home_exclude_cats', $settings)) {
|
||||
unset($current['home_exclude_category_ids']);
|
||||
}
|
||||
if (array_key_exists('home_lists', $settings)) {
|
||||
unset($current['homepage_tabs']);
|
||||
unset($current[$dead_key]);
|
||||
}
|
||||
|
||||
update_option($option_key, $current);
|
||||
|
||||
Reference in new issue
Block a user