$options The plugin options. * @return string */ public static function urlForAdvancedSetting(string $anchorId, array $options): string { $args = array(self::QUERY_ARG => '1'); if (function_exists('wp_create_nonce')) { $args['_wpnonce'] = (string)wp_create_nonce(self::NONCE_ACTION); } $url = ABJ_404_Solution_AdminPageUrlBuilder::subpageUrl('abj404_options', $args, $options); if ($anchorId !== '') { $url .= '#' . rawurlencode($anchorId); } return $url; } /** * Honour an inbound advanced-setting link: switch the current user to * Advanced Mode so the field the link points at is actually rendered. * * No-op unless the request carries the query arg, a valid nonce for this * user's session, and the caller is a plugin admin. Never switches a user * back to Simple Mode; that stays a deliberate act on the mode toggle. * * @return bool True when the preference was switched. */ public static function applyIfRequested(): bool { if (!isset($_GET[self::QUERY_ARG])) { return false; } if (!function_exists('wp_verify_nonce')) { return false; } $policy = abj_service('admin_access_policy'); if (!is_object($policy) || !method_exists($policy, 'isPluginAdmin') || !$policy->isPluginAdmin()) { return false; } $nonce = ABJ_404_Solution_RequestInputNormalizer::readText( $_GET, array('name' => '_wpnonce')); if ($nonce === '' || !wp_verify_nonce($nonce, self::NONCE_ACTION)) { return false; } $preference = abj_service('settings_mode_preference'); if (!is_object($preference) || !method_exists($preference, 'setMode')) { return false; } $writeResult = $preference->setMode( ABJ_404_Solution_SettingsModePreference::MODE_ADVANCED ); if ($writeResult === false) { self::reportModeWriteFailure(); return false; } return true; } private static function reportModeWriteFailure(): void { $message = 'Advanced-settings deep link could not persist the current user mode.'; $logger = function_exists('abj_service_optional') ? abj_service_optional('logging') : null; if (is_object($logger) && method_exists($logger, 'warn')) { $logger->warn($message); return; } abj404_logPhpFallback('settings-mode-deep-link', $message); } }