has_cap('manage_options') || empty($partnerData)) { return $redirectTo; } return \admin_url() . 'admin.php?page=extendify-assist'; }, 10, 3); // Redirect to a safe place if the user doesn't have access. add_action('admin_page_access_denied', function () { // phpcs:ignore WordPress.Security.NonceVerification.Recommended if (isset($_GET['page']) && strpos(sanitize_text_field(wp_unslash($_GET['page'])), 'extendify') !== false) { wp_safe_redirect(admin_url()); exit; } }); // Allow Extendify requests to have a longer timeout. add_filter('http_request_args', function ($args, $url) { if (strpos($url, 'extendify') !== false) { $args['timeout'] = 45; } return $args; }, 100, 2); // Clean up the site profile if being accessed add_filter('option_extendify_site_profile', function ($value) { $profile = is_string($value) ? json_decode($value, true) : $value; $profile = is_array($profile) ? $profile : []; $map = [ 'aiSiteType' => 'type', 'aiTitle' => 'title', 'aiDescription' => 'description', 'aiObjective' => 'objective', 'aiSiteCategory' => 'category', 'aiStructure' => 'structure', 'aiKeywords' => 'imageSearchTerms', 'logoObjectName' => 'logoObjectName', ]; foreach ($map as $old => $new) { if (!array_key_exists($new, $profile)) { $profile[$new] = $profile[$old] ?? null; } } // if tone is set and is not array (and ensure lowercase) if (isset($profile['tone']) && !is_array($profile['tone'])) { $profile['tone'] = array_map(function ($v) { return strtolower((string) $v); }, (array) ($profile['tone'] ?? [])); } return $profile; }); endif;