| @@ -80,19 +80,18 @@ | ||
| 80 | 80 | */ |
| 81 | 81 | public static function set_mode( $mode ) { |
| 82 | 82 | // Validate mode |
| 83 | 83 | if ( ! in_array( $mode, array( self::MODE_PRODUCTION, self::MODE_STAGING ), true ) ) { |
| 84 | - error_log( "MetaSync Endpoint Manager: Invalid mode '{$mode}' provided" ); | |
| 84 | + error_log( "MetaSync Endpoint Manager: Invalid mode '{$mode}' provided" ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log -- genuine failure path, bounded, no secrets | |
| 85 | 85 | return false; |
| 86 | 86 | } |
| 87 | 87 | |
| 88 | 88 | $result = update_option( self::MODE_OPTION, $mode ); |
| 89 | 89 | |
| 90 | - if ( $result ) { | |
| 91 | - error_log( "MetaSync Endpoint Manager: Endpoints switched to {$mode} mode by user " . get_current_user_id() ); | |
| 92 | - } | |
| 93 | - | |
| 94 | - return $result; | |
| 90 | + // WordPress returns false when the requested value is already stored. | |
| 91 | + // Read it back so selecting the current mode remains an idempotent success, | |
| 92 | + // while a failed write that leaves another value still reports failure. | |
| 93 | + return $result || self::get_mode() === $mode; | |
| 95 | 94 | } |
| 96 | 95 | |
| 97 | 96 | /** |
| 98 | 97 | * Get a specific endpoint URL by key. |
| @@ -103,9 +102,9 @@ | ||
| 103 | 102 | public static function get_endpoint( $endpoint_key ) { |
| 104 | 103 | $mode = self::get_mode(); |
| 105 | 104 | |
| 106 | 105 | if ( ! isset( self::$endpoints[ $mode ][ $endpoint_key ] ) ) { |
| 107 | - error_log( "MetaSync Endpoint Manager: Unknown endpoint key '{$endpoint_key}'" ); | |
| 106 | + error_log( "MetaSync Endpoint Manager: Unknown endpoint key '{$endpoint_key}'" ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log -- genuine failure path, bounded, no secrets | |
| 108 | 107 | |
| 109 | 108 | // Fallback to production if key exists there |
| 110 | 109 | if ( isset( self::$endpoints[ self::MODE_PRODUCTION ][ $endpoint_key ] ) ) { |
| 111 | 110 | return self::$endpoints[ self::MODE_PRODUCTION ][ $endpoint_key ]; |