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
@@ -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