| @@ -57,9 +57,8 @@ | ||
| 57 | 57 | } |
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | if (empty($config)) { |
| 61 | - error_log('MetaSync Google Index: Service account configuration not found in options table. Option key: ' . self::SERVICE_ACCOUNT_OPTION_KEY); | |
| 62 | 61 | return false; |
| 63 | 62 | } |
| 64 | 63 | |
| 65 | 64 | // Decode JSON if stored as string |
| @@ -73,9 +72,9 @@ | ||
| 73 | 72 | // Validate required fields |
| 74 | 73 | $required_fields = ['client_email', 'private_key', 'project_id']; |
| 75 | 74 | foreach ($required_fields as $field) { |
| 76 | 75 | if (empty($config[$field])) { |
| 77 | - error_log("MetaSync Google Index: Missing required field '{$field}' in service account configuration"); | |
| 76 | + error_log("MetaSync Google Index: Missing required field '{$field}' in service account configuration"); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log -- genuine failure path, bounded, no secrets | |
| 78 | 77 | return false; |
| 79 | 78 | } |
| 80 | 79 | } |
| 81 | 80 | |
| @@ -117,9 +116,9 @@ | ||
| 117 | 116 | // Validate required fields |
| 118 | 117 | $required_fields = ['client_email', 'private_key', 'project_id']; |
| 119 | 118 | foreach ($required_fields as $field) { |
| 120 | 119 | if (empty($config[$field])) { |
| 121 | - error_log("MetaSync Google Index: Cannot save - missing required field '{$field}' in service account configuration"); | |
| 120 | + error_log("MetaSync Google Index: Cannot save - missing required field '{$field}' in service account configuration"); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log -- genuine failure path, bounded, no secrets | |
| 122 | 121 | return false; |
| 123 | 122 | } |
| 124 | 123 | } |
| 125 | 124 | |
| @@ -158,9 +157,9 @@ | ||
| 158 | 157 | ] |
| 159 | 158 | ); |
| 160 | 159 | } |
| 161 | 160 | |
| 162 | - error_log('MetaSync Google Index: Failed to save service account configuration - database error or data too large'); | |
| 161 | + error_log('MetaSync Google Index: Failed to save service account configuration - database error or data too large'); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log -- genuine failure path, bounded, no secrets | |
| 163 | 162 | return false; |
| 164 | 163 | } |
| 165 | 164 | } |
| 166 | 165 | |
| @@ -198,18 +197,8 @@ | ||
| 198 | 197 | if ($action !== 'delete' && $post->post_status !== 'publish') { |
| 199 | 198 | return $this->error_response('Only published posts can be indexed'); |
| 200 | 199 | } |
| 201 | 200 | |
| 202 | - // Log the action | |
| 203 | - error_log(sprintf( | |
| 204 | - 'Google Index Direct: %s action for %s (ID: %d, Type: %s, URL: %s)', | |
| 205 | - strtoupper($action), | |
| 206 | - $post->post_title, | |
| 207 | - $post_id, | |
| 208 | - $post_type, | |
| 209 | - $post_url | |
| 210 | - )); | |
| 211 | - | |
| 212 | 201 | // Perform the API call |
| 213 | 202 | return $this->call_indexing_api($post_url, $action); |
| 214 | 203 | } |
| 215 | 204 | |
| @@ -381,15 +370,21 @@ | ||
| 381 | 370 | |
| 382 | 371 | $status_code = wp_remote_retrieve_response_code($response); |
| 383 | 372 | $body = wp_remote_retrieve_body($response); |
| 384 | 373 | |
| 385 | - // Log the response for debugging | |
| 386 | - error_log(sprintf( | |
| 387 | - 'Google Index API Response - Action: %s, Status: %d, Body: %s', | |
| 388 | - $action, | |
| 389 | - $status_code, | |
| 390 | - $body | |
| 391 | - )); | |
| 374 | + // Log failures only — never log the full API response body | |
| 375 | + if ($status_code < 200 || $status_code >= 300) { | |
| 376 | + $error_data = json_decode($body, true); | |
| 377 | + $error_message = is_array($error_data) && !empty($error_data['error']['message']) | |
| 378 | + ? $error_data['error']['message'] | |
| 379 | + : 'Unknown Google API error'; | |
| 380 | + error_log(sprintf( // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log -- genuine failure path, bounded, no secrets | |
| 381 | + 'Google Index API Error - Action: %s, Status: %d, Error: %s', | |
| 382 | + $action, | |
| 383 | + $status_code, | |
| 384 | + $error_message | |
| 385 | + )); | |
| 386 | + } | |
| 392 | 387 | |
| 393 | 388 | // Parse response body |
| 394 | 389 | $data = json_decode($body, true); |
| 395 | 390 | if (json_last_error() !== JSON_ERROR_NONE) { |
| @@ -465,15 +460,15 @@ | ||
| 465 | 460 | ] |
| 466 | 461 | ); |
| 467 | 462 | } |
| 468 | 463 | |
| 469 | - error_log('MetaSync Google Index: Failed to get access token - ' . $response->get_error_message()); | |
| 464 | + error_log('MetaSync Google Index: Failed to get access token - ' . $response->get_error_message()); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log -- genuine failure path, bounded, no secrets | |
| 470 | 465 | return false; |
| 471 | 466 | } |
| 472 | 467 | |
| 473 | 468 | $body = json_decode(wp_remote_retrieve_body($response), true); |
| 474 | 469 | if (!isset($body['access_token'])) { |
| 475 | - error_log('MetaSync Google Index: No access token in response - ' . print_r($body, true)); | |
| 470 | + error_log('MetaSync Google Index: No access token in response'); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log -- genuine failure path, bounded, no secrets | |
| 476 | 471 | return false; |
| 477 | 472 | } |
| 478 | 473 | |
| 479 | 474 | $access_token = $body['access_token']; |
| @@ -526,9 +521,9 @@ | ||
| 526 | 521 | 'SHA256' |
| 527 | 522 | ); |
| 528 | 523 | |
| 529 | 524 | if (!$success) { |
| 530 | - error_log('MetaSync Google Index: Failed to sign JWT token'); | |
| 525 | + error_log('MetaSync Google Index: Failed to sign JWT token'); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log -- genuine failure path, bounded, no secrets | |
| 531 | 526 | return false; |
| 532 | 527 | } |
| 533 | 528 | |
| 534 | 529 | $base64_signature = $this->base64url_encode($signature); |
| @@ -573,9 +568,9 @@ | ||
| 573 | 568 | * @return array Error response |
| 574 | 569 | */ |
| 575 | 570 | private function error_response($message, $code = 'UNKNOWN_ERROR', $details = []) |
| 576 | 571 | { |
| 577 | - error_log('MetaSync Google Index Error: ' . $message . ' (Code: ' . $code . ')'); | |
| 572 | + error_log('MetaSync Google Index Error: ' . $message . ' (Code: ' . $code . ')'); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log -- genuine failure path, bounded, no secrets | |
| 578 | 573 | |
| 579 | 574 | return [ |
| 580 | 575 | 'success' => false, |
| 581 | 576 | 'error' => [ |