| @@ -108,24 +108,38 @@ | ||
| 108 | 108 | ['status' => 400] |
| 109 | 109 | ); |
| 110 | 110 | } |
| 111 | 111 | |
| 112 | - // Merge the 6 robots booleans into the existing option rather than | |
| 113 | - // replacing it, so sibling keys written by other paths (e.g. the SEO | |
| 114 | - // importer's noindex_date_archives / noindex_author_archives, consumed | |
| 115 | - // by the frontend) survive a save. Mirrors the MCP ability's merge. | |
| 112 | + // Merge into the existing option rather than replacing it, so sibling | |
| 113 | + // keys written by other paths (e.g. the SEO importer's | |
| 114 | + // noindex_date_archives / noindex_author_archives, consumed by the | |
| 115 | + // frontend) survive a save (#134). | |
| 116 | 116 | $existing = get_option(self::OPTION_NAME, []); |
| 117 | 117 | if (!is_array($existing)) { |
| 118 | 118 | $existing = []; |
| 119 | 119 | } |
| 120 | - $sanitized_settings = array_merge($existing, [ | |
| 121 | - 'index' => isset($settings['index']) ? (bool) $settings['index'] : true, | |
| 122 | - 'noindex' => isset($settings['noindex']) ? (bool) $settings['noindex'] : false, | |
| 123 | - 'nofollow' => isset($settings['nofollow']) ? (bool) $settings['nofollow'] : false, | |
| 124 | - 'noarchive' => isset($settings['noarchive']) ? (bool) $settings['noarchive'] : false, | |
| 125 | - 'noimageindex' => isset($settings['noimageindex']) ? (bool) $settings['noimageindex'] : false, | |
| 126 | - 'nosnippet' => isset($settings['nosnippet']) ? (bool) $settings['nosnippet'] : false, | |
| 127 | - ]); | |
| 120 | + | |
| 121 | + $sanitized_settings = wp_parse_args($existing, $this->get_default_settings()); | |
| 122 | + | |
| 123 | + // Only write the keys the caller actually sent. Writing all six on every | |
| 124 | + // request meant a payload of {"noarchive": true} silently reset the | |
| 125 | + // other five — and diverged from the MCP ability, which writes the same | |
| 126 | + // option with an array_key_exists() merge (#560). | |
| 127 | + $found = false; | |
| 128 | + foreach (array_keys($this->get_default_settings()) as $key) { | |
| 129 | + if (array_key_exists($key, $settings)) { | |
| 130 | + $sanitized_settings[$key] = (bool) $settings[$key]; | |
| 131 | + $found = true; | |
| 132 | + } | |
| 133 | + } | |
| 134 | + | |
| 135 | + if (!$found) { | |
| 136 | + return new WP_Error( | |
| 137 | + 'no_valid_settings', | |
| 138 | + 'No valid robots meta setting keys were provided.', | |
| 139 | + ['status' => 400] | |
| 140 | + ); | |
| 141 | + } | |
| 128 | 142 | |
| 129 | 143 | update_option(self::OPTION_NAME, $sanitized_settings); |
| 130 | 144 | |
| 131 | 145 | return new WP_REST_Response([ |