| @@ -30,9 +30,9 @@ | ||
| 30 | 30 | // Load the main class |
| 31 | 31 | if (file_exists(GOOGLE_INDEX_DIRECT_PATH . '/class-google-index-direct.php')) { |
| 32 | 32 | require_once GOOGLE_INDEX_DIRECT_PATH . '/class-google-index-direct.php'; |
| 33 | 33 | } else { |
| 34 | - error_log('MetaSync Google Index: class-google-index-direct.php not found at ' . GOOGLE_INDEX_DIRECT_PATH . '/class-google-index-direct.php'); | |
| 34 | + error_log('MetaSync Google Index: class-google-index-direct.php not found at ' . GOOGLE_INDEX_DIRECT_PATH . '/class-google-index-direct.php'); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log -- genuine failure path, bounded, no secrets | |
| 35 | 35 | return; |
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | // Load admin interface if in admin area |
| @@ -39,9 +39,9 @@ | ||
| 39 | 39 | if (is_admin()) { |
| 40 | 40 | if (file_exists(GOOGLE_INDEX_DIRECT_PATH . '/class-google-index-admin.php')) { |
| 41 | 41 | require_once GOOGLE_INDEX_DIRECT_PATH . '/class-google-index-admin.php'; |
| 42 | 42 | } else { |
| 43 | - error_log('MetaSync Google Index: class-google-index-admin.php not found at ' . GOOGLE_INDEX_DIRECT_PATH . '/class-google-index-admin.php'); | |
| 43 | + error_log('MetaSync Google Index: class-google-index-admin.php not found at ' . GOOGLE_INDEX_DIRECT_PATH . '/class-google-index-admin.php'); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log -- genuine failure path, bounded, no secrets | |
| 44 | 44 | } |
| 45 | 45 | } |
| 46 | 46 | } |
| 47 | 47 | |
| @@ -46,10 +46,14 @@ | ||
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | /** |
| 49 | 49 | * Get Google Index Direct instance |
| 50 | - * | |
| 51 | - * @return Google_Index_Direct | |
| 50 | + * | |
| 51 | + * Returns null when the class could not be loaded — callers that reached this | |
| 52 | + * before google_index_direct_init() ran, or on an install where the class file | |
| 53 | + * is missing, get null rather than a fatal. | |
| 54 | + * | |
| 55 | + * @return Google_Index_Direct|null | |
| 52 | 56 | */ |
| 53 | 57 | function google_index_direct() |
| 54 | 58 | { |
| 55 | 59 | static $instance = null; |
| @@ -55,9 +59,9 @@ | ||
| 55 | 59 | static $instance = null; |
| 56 | 60 | |
| 57 | 61 | if ($instance === null) { |
| 58 | 62 | if (!class_exists('Google_Index_Direct')) { |
| 59 | - error_log('MetaSync Google Index: Google_Index_Direct class not available.'); | |
| 63 | + error_log('MetaSync Google Index: Google_Index_Direct class not available.'); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log -- genuine failure path, bounded, no secrets | |
| 60 | 64 | return null; |
| 61 | 65 | } |
| 62 | 66 | $instance = new Google_Index_Direct(); |
| 63 | 67 | } |
| @@ -95,11 +99,16 @@ | ||
| 95 | 99 | * |
| 96 | 100 | * @param array $service_account_json Service account JSON configuration |
| 97 | 101 | * @return bool True on success, false on failure |
| 98 | 102 | */ |
| 99 | -function google_index_save_service_account($service_account_json) | |
| 103 | +function google_index_save_service_account($service_account_json) | |
| 100 | 104 | { |
| 101 | - return google_index_direct()->save_service_account_config($service_account_json); | |
| 105 | + $instance = google_index_direct(); | |
| 106 | + if (!$instance) { | |
| 107 | + return false; | |
| 108 | + } | |
| 109 | + | |
| 110 | + return $instance->save_service_account_config($service_account_json); | |
| 102 | 111 | } |
| 103 | 112 | |
| 104 | 113 | |
| 105 | 114 | // Initialize on WordPress init |