fix(user): show IP city on home/center and force /user + profile templates
This commit is contained in:
1 parent
ac7ff8d4f2
commit
820fafd8a7
6 files changed
+163
-49
No files matched your search
@@ -46,13 +46,35 @@ if (!function_exists('aksrt_ip_geo_display_enabled')) :
|
||||
if (!aksrt_ip_geo_master_enabled()) {
|
||||
return false;
|
||||
}
|
||||
$location = sanitize_key($location);
|
||||
$c = aksrt_get_ip_geo_config();
|
||||
$display = $c['ip_geo_display'] ?? [];
|
||||
if (!is_array($display)) {
|
||||
$display = [$display];
|
||||
}
|
||||
$display = array_map('sanitize_key', $display);
|
||||
return in_array(sanitize_key($location), $display, true);
|
||||
$display = array_values(array_unique(array_filter(array_map('sanitize_key', $display))));
|
||||
|
||||
// Legacy saves only had "comment". When master is on, expand so user/post
|
||||
// surfaces work without forcing a re-save of the checkbox group.
|
||||
if ($display === [] || $display === ['comment']) {
|
||||
$display = ['comment', 'user_home', 'user_center', 'post'];
|
||||
}
|
||||
|
||||
// Zibll: user home/center are gated by user_city_s, not a separate surface list.
|
||||
// Still honour an explicit opt-out if the admin removed them from the list after upgrade.
|
||||
if (in_array($location, ['user_home', 'user_center'], true)) {
|
||||
if (!aksrt_user_city_enabled()) {
|
||||
return false;
|
||||
}
|
||||
// If list explicitly includes any user surface, require membership; else allow.
|
||||
$has_user_keys = (bool) array_intersect($display, ['user_home', 'user_center']);
|
||||
if ($has_user_keys) {
|
||||
return in_array($location, $display, true);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return in_array($location, $display, true);
|
||||
}
|
||||
endif;
|
||||
|
||||
@@ -72,9 +94,13 @@ if (!function_exists('aksrt_user_city_enabled')) :
|
||||
*/
|
||||
function aksrt_user_city_enabled(): bool {
|
||||
if (!class_exists('\AKSRT\Settings\Settings')) {
|
||||
return false;
|
||||
return true; // zibll default on
|
||||
}
|
||||
$all = \AKSRT\Settings\Settings::get_all();
|
||||
// Unset → on (zibll _pz default true). Explicit false turns off.
|
||||
if (!array_key_exists('user_city_s', $all)) {
|
||||
return true;
|
||||
}
|
||||
return !empty($all['user_city_s']);
|
||||
}
|
||||
endif;
|
||||
@@ -238,7 +264,36 @@ if (!function_exists('aksrt_get_user_addr')) :
|
||||
if ((!is_array($raw) || empty($raw)) && metadata_exists('user', $user_id, 'user_addr')) {
|
||||
$raw = get_user_meta($user_id, 'user_addr', true);
|
||||
}
|
||||
return aksrt_normalize_geo_addr($raw);
|
||||
$addr = aksrt_normalize_geo_addr($raw);
|
||||
if ($addr['country'] !== '' || $addr['province'] !== '' || $addr['city'] !== '') {
|
||||
return $addr;
|
||||
}
|
||||
|
||||
// Lazy backfill from stored IPs so pages work before next login.
|
||||
$ips = [];
|
||||
foreach (['aksrt_register_ip', 'register_ip'] as $k) {
|
||||
$v = trim((string) get_user_meta($user_id, $k, true));
|
||||
if ($v !== '') {
|
||||
$ips[] = $v;
|
||||
}
|
||||
}
|
||||
// Own profile: refresh from current client IP (zibll updates on login; this covers open sessions).
|
||||
if ((int) get_current_user_id() === $user_id) {
|
||||
$cur = function_exists('aksrt_get_client_ip') ? (string) aksrt_get_client_ip() : (string) ($_SERVER['REMOTE_ADDR'] ?? '');
|
||||
$cur = trim($cur);
|
||||
if ($cur !== '') {
|
||||
array_unshift($ips, $cur);
|
||||
}
|
||||
}
|
||||
$ips = array_values(array_unique(array_filter($ips)));
|
||||
foreach ($ips as $ip) {
|
||||
$looked = aksrt_lookup_geo_for_ip($ip);
|
||||
if ($looked['country'] !== '' || $looked['province'] !== '' || $looked['city'] !== '') {
|
||||
update_user_meta($user_id, 'aksrt_user_addr', $looked);
|
||||
return $looked;
|
||||
}
|
||||
}
|
||||
return $addr;
|
||||
}
|
||||
endif;
|
||||
|
||||
@@ -251,9 +306,10 @@ if (!function_exists('aksrt_get_user_city_badge_html')) :
|
||||
* @param string $class CSS.
|
||||
*/
|
||||
function aksrt_get_user_city_badge_html(int $user_id, string $location = 'user_home', string $class = 'badg'): string {
|
||||
if ($user_id <= 0 || !aksrt_user_city_enabled()) {
|
||||
if ($user_id <= 0) {
|
||||
return '';
|
||||
}
|
||||
// aksrt_ip_geo_display_enabled already enforces master + user_city for user surfaces.
|
||||
if (!aksrt_ip_geo_display_enabled($location)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
@@ -348,7 +348,7 @@ if (!function_exists('aksrt_single_render_author_card')) :
|
||||
if ($author_id <= 0) {
|
||||
return;
|
||||
}
|
||||
$author_url = get_author_posts_url($author_id);
|
||||
$author_url = function_exists('aksrt_get_user_home_url') ? aksrt_get_user_home_url($author_id) : get_author_posts_url($author_id);
|
||||
$author_name = get_the_author();
|
||||
$bio = trim((string) get_the_author_meta('description'));
|
||||
$name_html = function_exists('aksrt_get_user_name')
|
||||
|
||||
@@ -57,7 +57,7 @@ if (!function_exists('aksrt_get_comments_user_name_html')) :
|
||||
if ($user_id > 0) {
|
||||
$user = get_userdata($user_id);
|
||||
$display = $user instanceof WP_User ? $user->display_name : get_comment_author($comment);
|
||||
$url = get_author_posts_url($user_id);
|
||||
$url = function_exists('aksrt_get_user_home_url') ? aksrt_get_user_home_url($user_id) : get_author_posts_url($user_id);
|
||||
$name = '<a class="text-ellipsis font-bold aksrt-comment__author" href="' . esc_url($url) . '">' . esc_html($display) . '</a>';
|
||||
if (function_exists('aksrt_render_user_identity_chips')) {
|
||||
$name .= aksrt_render_user_identity_chips($user_id, 'comment');
|
||||
|
||||
Reference in new issue
Block a user