| @@ -17,9 +17,8 @@ | ||
| 17 | 17 | if ( ! defined( 'ABSPATH' ) ) { |
| 18 | 18 | exit; |
| 19 | 19 | } |
| 20 | 20 | |
| 21 | -use ThinkRank\Core\Settings; | |
| 22 | 21 | use ThinkRank\Integrations\Google_PageSpeed_Client; |
| 23 | 22 | |
| 24 | 23 | /** |
| 25 | 24 | * Performance Data Collector Class |
| @@ -131,38 +130,15 @@ | ||
| 131 | 130 | * |
| 132 | 131 | * @return bool |
| 133 | 132 | */ |
| 134 | 133 | private function has_pagespeed_credentials(): bool { |
| 135 | - if ($this->get_google_pagespeed_api_key() !== '') { | |
| 136 | - return true; | |
| 137 | - } | |
| 138 | - | |
| 139 | - return $this->get_google_access_token() !== ''; | |
| 134 | + // One predicate, next to the for_site() auth order it mirrors: keeping a | |
| 135 | + // second copy here is how the Performance tab drifted into demanding | |
| 136 | + // OAuth specifically (#519). | |
| 137 | + return Google_PageSpeed_Client::site_has_credentials(); | |
| 140 | 138 | } |
| 141 | 139 | |
| 142 | 140 | /** |
| 143 | - * Get the site-owned PageSpeed API key from settings. | |
| 144 | - * | |
| 145 | - * @return string API key, or an empty string when not configured. | |
| 146 | - */ | |
| 147 | - private function get_google_pagespeed_api_key(): string { | |
| 148 | - $api_key = (new Settings())->get('google_pagespeed_api_key', ''); | |
| 149 | - return is_string($api_key) ? trim($api_key) : ''; | |
| 150 | - } | |
| 151 | - | |
| 152 | - /** | |
| 153 | - * Get Google OAuth access token from settings | |
| 154 | - * | |
| 155 | - * @return string Access token or empty string if not configured | |
| 156 | - */ | |
| 157 | - private function get_google_access_token(): string { | |
| 158 | - // OAuth tokens are encrypted at rest; Settings::get() decrypts them. | |
| 159 | - // Reading the raw option yields ciphertext that PageSpeed rejects with a 401. | |
| 160 | - $access_token = (new Settings())->get('google_access_token', ''); | |
| 161 | - return is_string($access_token) ? $access_token : ''; | |
| 162 | - } | |
| 163 | - | |
| 164 | - /** | |
| 165 | 141 | * Option storing the timestamp of the last successful collection, |
| 166 | 142 | * used by the 7-day auto-refresh gate. |
| 167 | 143 | */ |
| 168 | 144 | private const LAST_COLLECTED_OPTION = 'thinkrank_cwv_last_collected'; |
| @@ -267,8 +243,16 @@ | ||
| 267 | 243 | * @return void |
| 268 | 244 | */ |
| 269 | 245 | public function collect_performance_data_via_cron(): void { |
| 270 | 246 | if ($this->collect_performance_data()) { |
| 247 | + return; | |
| 248 | + } | |
| 249 | + | |
| 250 | + // Not-configured is a configuration state, not a failure: it is the | |
| 251 | + // default for a fresh install, it never resolves on its own, and the | |
| 252 | + // REST layer already reports it to the UI. Logging it wrote a line to | |
| 253 | + // every unconfigured site's error log on every scheduled run (#585). | |
| 254 | + if ($this->last_error_code === self::ERROR_NOT_CONFIGURED) { | |
| 271 | 255 | return; |
| 272 | 256 | } |
| 273 | 257 | |
| 274 | 258 | error_log( // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log -- the only record that a silent cron failure happened. |