client = $client; $this->licenseManager = $licenseManager; } /** * @param array $postIds * @return array|WP_Error */ public function scan(array $postIds = []): array|WP_Error { if (!$this->licenseManager->isValid()) { return new WP_Error('license_invalid', __('Your license is invalid or has expired.', 'geolens')); } $environment = (new EnvironmentCollector())->collect(); $schemas = (new SchemaCollector())->collect($postIds); $robots = (new RobotsCollector())->collect(); $dataBag = (new DataBag(site_url())) ->setEnvironment($environment) ->setSchemas($schemas) ->setRobotsTxt($robots['robots_txt']) ->setLlmsTxt($robots['llms_txt']) ->setSiteInfo($this->collectSiteInfo()); if (!$dataBag->validate()) { return new WP_Error('validation_failed', __('Scan request data failed validation.', 'geolens')); } $result = $this->client->post('/scan', $dataBag->toArray()); if (is_wp_error($result)) { return $result; } set_transient(self::TRANSIENT_KEY, $result, self::CACHE_TTL_HOURS * HOUR_IN_SECONDS); if (function_exists('do_action')) { do_action('geolens_scan_completed', $result); } return $result; } /** * @return array|null */ public function getLastResult(): ?array { $cached = get_transient(self::TRANSIENT_KEY); return $cached !== false ? $cached : null; } public function clearCache(): void { delete_transient(self::TRANSIENT_KEY); } /** * Collect site-level info for Schema generation. * * @return array{name: string, description: string, url: string, logo_url: ?string, language: string} */ private function collectSiteInfo(): array { $logoUrl = null; $customLogoId = get_theme_mod('custom_logo'); if ($customLogoId) { $logoUrl = wp_get_attachment_image_url((int) $customLogoId, 'full') ?: null; } if (!$logoUrl) { $siteIconUrl = get_site_icon_url(); $logoUrl = $siteIconUrl ?: null; } return [ 'name' => get_bloginfo('name'), 'description' => get_bloginfo('description'), 'url' => site_url(), 'logo_url' => $logoUrl, 'language' => get_bloginfo('language'), ]; } }