$cleanedSiteTitle, 'devbuild' => defined('EXTENDIFY_DEVMODE') ? constant('EXTENDIFY_DEVMODE') : is_readable(EXTENDIFY_PATH . '.devbuild'), 'siteId' => \get_option('extendify_site_id', ''), 'tlds' => ($partnerData['domainTLDs'] ?? []), 'priorityTlds' => ($partnerData['priorityDomainTLDs'] ?? []), 'partnerId' => \esc_attr(constant('EXTENDIFY_PARTNER_ID')), 'wpLanguage' => \get_locale(), 'wpVersion' => \get_bloginfo('version'), 'businessDescription' => \esc_attr($businessDescription), 'siteProfile' => $siteProfile, ]; $response = \wp_remote_post( sprintf('%s/api/domains/suggest', Constants::AI_HOST), [ 'body' => \wp_json_encode($data), 'headers' => ['Content-Type' => 'application/json'], ] ); if (is_wp_error($response)) { return new \WP_REST_Response([]); } $status = \wp_remote_retrieve_response_code($response); if ($status < 200 || $status >= 300) { return new \WP_REST_Response([]); } $body = wp_remote_retrieve_body($response); if (empty($body)) { return new \WP_REST_Response([]); } return new \WP_REST_Response(json_decode($body, true), $status); } /** * Clean site title. * * @param string $siteTitle - The site title to clean. * @return string */ public static function cleanSiteTitle($siteTitle) { return trim(preg_replace('/[^\p{L}\p{N}\s\-]+/u', '', html_entity_decode($siteTitle))); } /** * Check if the site Title is part of the blocked list. * * @param string $siteTitle - The site title to check. * @return bool */ public static function hasValidSiteTitle($siteTitle) { return empty(array_filter(self::$blockList, function ($item) use ($siteTitle) { // in php 8.0 we can use str_contains. return strpos(strtolower($siteTitle), strtolower($item)) !== false; })); } /** * Delete the cache for the domains suggestions. * * @return \WP_REST_Response */ public static function deleteCache() { \delete_transient('extendify_domains'); return new \WP_REST_Response(['success' => true]); } /** * Persist the tracking data * * @param \WP_REST_Request $request - The request. * @return \WP_REST_Response */ public static function tracking($request) { $data = json_decode($request->get_param('state'), true); update_option('extendify_domains_recommendations_activities', Sanitizer::sanitizeArray($data)); return new \WP_REST_Response($data); } }