feat(categories): align archive and directory pages
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
7faa2d53d8
commit
fbb53c6890
7 files changed
+443
-315
No files matched your search
@@ -31,7 +31,15 @@ if (!function_exists('jio_archive_render_term_header')) :
|
||||
$description = esc_html(trim(wp_strip_all_tags((string) $args['description'])));
|
||||
$more = '';
|
||||
if ($term instanceof WP_Term) {
|
||||
$more = '<div class="page-cover-more-btns flex ac"><a href="javascript:;" class="main-search-btn" search-type="post" search-trem="' . (int) $term->term_id . '" trem-name="' . esc_attr($term->name) . '" search-placeholder="' . esc_attr(sprintf(__('在%s中搜索', 'jio'), $term->name)) . '" title="' . esc_attr(sprintf(__('在%s中搜索', 'jio'), $term->name)) . '"><i class="fa fas fa-search" aria-hidden="true"></i></a></div>';
|
||||
$edit_url = !$is_tag && current_user_can('edit_term', (int) $term->term_id)
|
||||
? get_edit_term_link((int) $term->term_id, $term->taxonomy)
|
||||
: false;
|
||||
$edit_label = __('编辑此分类', 'jio');
|
||||
$edit_button = $edit_url
|
||||
? '<a class="admin-edit" href="' . esc_url($edit_url) . '" title="' . esc_attr($edit_label) . '"><i class="fa fas fa-edit" aria-hidden="true"></i><span class="screen-reader-text">' . esc_html($edit_label) . '</span></a>'
|
||||
: '';
|
||||
$more = '<div class="page-cover-more-btns flex ac">' . $edit_button
|
||||
. '<a href="javascript:;" class="main-search-btn" search-type="post" search-trem="' . (int) $term->term_id . '" trem-name="' . esc_attr($term->name) . '" search-placeholder="' . esc_attr(sprintf(__('在%s中搜索', 'jio'), $term->name)) . '" title="' . esc_attr(sprintf(__('在%s中搜索', 'jio'), $term->name)) . '"><i class="fa fas fa-search" aria-hidden="true"></i></a></div>';
|
||||
}
|
||||
if (empty($args['show_cover'])) {
|
||||
echo '<div class="jio-panel relative"><h4 class="title-h-left">' . $title . '</h4><div class="muted-2-color">' . $description . '</div>' . $more . '</div>';
|
||||
|
||||
@@ -363,12 +363,41 @@ if (!function_exists('jio_get_term_allow_view_rule')) :
|
||||
}
|
||||
endif;
|
||||
|
||||
if (!function_exists('jio_get_term_allow_view_data')) :
|
||||
/** Resolve reading permission for a category archive. */
|
||||
function jio_get_term_allow_view_data(int $term_id): array {
|
||||
$data = [
|
||||
'allow' => true,
|
||||
'type' => '',
|
||||
'not_html' => '',
|
||||
'allow_reason' => '',
|
||||
'html' => '',
|
||||
];
|
||||
if ($term_id <= 0 || current_user_can('manage_options')) {
|
||||
return $data;
|
||||
}
|
||||
|
||||
$rule = jio_get_term_allow_view_rule($term_id);
|
||||
if (empty($rule['type']) || $rule['type'] === 'public') {
|
||||
return $data;
|
||||
}
|
||||
$link = get_term_link($term_id, 'category');
|
||||
$redirect_url = is_wp_error($link) ? home_url('/') : (string) $link;
|
||||
return jio_resolve_allow_view_rule(
|
||||
(string) $rule['type'],
|
||||
(array) ($rule['roles'] ?? []),
|
||||
null,
|
||||
$redirect_url
|
||||
);
|
||||
}
|
||||
endif;
|
||||
|
||||
if (!function_exists('jio_resolve_allow_view_rule')) :
|
||||
/**
|
||||
* @param array<string,mixed> $roles Role constraints for type=roles.
|
||||
* @return array{allow:bool,type:string,not_html:string,allow_reason:string,html:string}
|
||||
*/
|
||||
function jio_resolve_allow_view_rule(string $type, array $roles, WP_Post $post): array {
|
||||
function jio_resolve_allow_view_rule(string $type, array $roles, ?WP_Post $post = null, string $redirect_url = ''): array {
|
||||
$type = sanitize_key($type);
|
||||
if (in_array($type, ['login', 'signin'], true)) {
|
||||
$type = 'signin';
|
||||
@@ -383,7 +412,11 @@ if (!function_exists('jio_resolve_allow_view_rule')) :
|
||||
];
|
||||
|
||||
$user_id = get_current_user_id();
|
||||
$login_url = function_exists('jio_get_login_url') ? jio_get_login_url() : wp_login_url(get_permalink($post));
|
||||
if ($redirect_url !== '') {
|
||||
$login_url = function_exists('jio_get_login_url') ? jio_get_login_url($redirect_url) : wp_login_url($redirect_url);
|
||||
} else {
|
||||
$login_url = function_exists('jio_get_login_url') ? jio_get_login_url() : wp_login_url($post instanceof WP_Post ? get_permalink($post) : '');
|
||||
}
|
||||
|
||||
if ($type === 'signin') {
|
||||
$data['html'] = '<p class="separator muted-3-color em09">' . esc_html__('登录后可查看', 'jio') . '</p>';
|
||||
|
||||
Reference in new issue
Block a user