feat(admin): rebuild page display settings

This commit is contained in:
kate522 committed 2026-08-19 00:07:13 +08:00
1 parent 09b1e8fd35
commit 480e2bf07e
117 files changed
+1815 -9081

No files matched your search

+21 -14
View File
@@ -90,28 +90,35 @@ endif;
if (!function_exists('aksrt_archive_get_sort_state')) :
/**
* Shared latest/oldest/popular sort state for term archives.
* Build the canonical Zibll orderby state for term archives.
*
* @param array<string,mixed> $option Page-display orderby fieldset.
* @return array{current:string,links:array<string,string>}
*/
function aksrt_archive_get_sort_state(): array {
$current_orderby = sanitize_key((string) get_query_var('orderby'));
$current_order = strtoupper(sanitize_key((string) get_query_var('order')));
$current = 'latest';
function aksrt_archive_get_sort_state(array $option = []): array {
$all = class_exists('\AKSRT\Settings\Settings')
? \AKSRT\Settings\Settings::homepage_allowed_sorts()
: ['modified', 'date', 'views', 'like', 'comment_count', 'favorite', 'rand'];
$lists = is_array($option['lists'] ?? null) ? $option['lists'] : [];
$lists = array_values(array_intersect(array_map('sanitize_key', $lists), $all));
if (!empty($option['dropdown'])) {
$lists = array_values(array_unique(array_merge($lists, $all)));
}
if ($current_orderby === 'date' && $current_order === 'ASC') {
$current = 'oldest';
} elseif ($current_orderby === 'comment_count') {
$current = 'popular';
$current = isset($_GET['orderby']) ? sanitize_key(wp_unslash((string) $_GET['orderby'])) : 'date';
if (!in_array($current, $all, true)) {
$current = 'date';
}
$base_url = remove_query_arg(['orderby', 'order', 'paged']);
$links = [];
foreach ($lists as $orderby) {
$links[$orderby] = add_query_arg('orderby', $orderby, $base_url);
}
return [
'current' => $current,
'links' => [
'latest' => remove_query_arg(['orderby', 'order', 'paged']),
'oldest' => add_query_arg(['orderby' => 'date', 'order' => 'asc', 'paged' => false]),
'popular' => add_query_arg(['orderby' => 'comment_count', 'order' => 'desc', 'paged' => false]),
],
'links' => $links,
];
}
endif;