| @@ -349,18 +349,26 @@ | ||
| 349 | 349 | if (empty($params)) { |
| 350 | 350 | $params = $request->get_params(); // Fallback if content-type is not JSON |
| 351 | 351 | } |
| 352 | 352 | |
| 353 | - // Sanitize Post Types | |
| 354 | - $post_types = isset($params['auto_submit_post_types']) ? (array) $params['auto_submit_post_types'] : []; | |
| 355 | - $sanitized_post_types = array_map('sanitize_text_field', $post_types); | |
| 353 | + $current_settings = get_option($this->option_name, []); | |
| 354 | + if (!is_array($current_settings)) { | |
| 355 | + $current_settings = []; | |
| 356 | + } | |
| 357 | + $new_settings = $current_settings; | |
| 356 | 358 | |
| 357 | - // We generally don't let user update API Key directly via update_settings, | |
| 358 | - // they should use regenerate, but if we need to support manual entry: | |
| 359 | - $current_settings = get_option($this->option_name, []); | |
| 360 | - $new_settings = array_merge($current_settings, [ | |
| 361 | - 'auto_submit_post_types' => $sanitized_post_types | |
| 362 | - ]); | |
| 359 | + // Only write the post types when the caller actually sent them. Writing | |
| 360 | + // unconditionally meant a payload of {"enabled": true} cleared the list, | |
| 361 | + // so the feature came on with nothing to submit — and diverged from the | |
| 362 | + // MCP ability, which writes this same option with an array_key_exists() | |
| 363 | + // merge. An explicit empty array still clears, since isset() is true | |
| 364 | + // for one (#562). | |
| 365 | + if (isset($params['auto_submit_post_types'])) { | |
| 366 | + $new_settings['auto_submit_post_types'] = array_values(array_map( | |
| 367 | + 'sanitize_key', | |
| 368 | + (array) $params['auto_submit_post_types'] | |
| 369 | + )); | |
| 370 | + } | |
| 363 | 371 | |
| 364 | 372 | // Save enabled state |
| 365 | 373 | if (isset($params['enabled'])) { |
| 366 | 374 | $new_settings['enabled'] = rest_sanitize_boolean($params['enabled']); |