PluginProbe
xSpeed Cache: AI-Powered Performance Hub with MCP, Caching & CDN / 1.4.1
xSpeed Cache: AI-Powered Performance Hub with MCP, Caching & CDN v1.4.1
1.4.1 1.4.0 1.3.7 1.3.6 1.3.5 1.3.4 1.3.3 1.3.2 1.3.1 1.3.0 1.2.4 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 1.1.2 All 35 releases
← All changes | includes/modules/Cloudflare/CloudflareModule.php +399 -16 1.3.2 → 1.4.1 View file →
@@ -34,14 +34,52 @@
34 34 * warning when Cloudflare is silently failing. (#119)
35 35 */
36 36 private const HEALTH_OPTION = 'xspeed_cloudflare_health';
37 37
38 + /** Cron event that does the edge call for a batch of purged URLs. */
39 + private const PURGE_URLS_EVENT = 'xspeed_cloudflare_purge_urls';
40 +
41 + /** Cron event for the zone-wide fallback when a batch is too large. */
42 + private const PURGE_ALL_EVENT = 'xspeed_cloudflare_purge_edge_all';
43 +
44 + /**
45 + * Above this many URLs, purge the zone instead of naming every page.
46 + *
47 + * The batch travels as the cron event's ARGUMENT, and the cron table is
48 + * an autoloaded option, so an unbounded batch is an unbounded payload in
49 + * `alloptions` for as long as the event is pending. A bulk product
50 + * import, or an `xspeed_purge_product_urls` filter that expands to a few
51 + * hundred URLs, is enough. Past the threshold the zone purge is one call
52 + * with no payload, and it is what the site would have got from
53 + * `purge_all()` anyway.
54 + */
55 + private const MAX_DEFERRED_URLS = 100;
56 +
57 + /**
58 + * URLs purged this request, awaiting a batched call at shutdown.
59 + *
60 + * Keyed blog id => URL => true. By URL so the same page arriving twice —
61 + * a post and the archive that lists it can resolve to the same address —
62 + * is sent once. By BLOG because one module instance serves the whole
63 + * process: a `Cache::purge_url()` raised inside `switch_to_blog()` would
64 + * otherwise land in a batch sent against whatever blog happened to be
65 + * current at shutdown, merging several sites' URLs into one zone with one
66 + * site's token, and writing the health record and activity log to the
67 + * wrong site too. Nothing does that today — Pro's network purge goes
68 + * through `purge_all()` — but the re-entry guard in Cache anticipates a
69 + * network purge that loops blogs in one request.
70 + *
71 + * @var array<int,array<string,true>>
72 + */
73 + private array $pending_edge_urls = array();
74 +
38 75 public function ui_metadata(): array {
39 76 return array(
40 77 'label' => __( 'Cloudflare', 'xspeed' ),
41 78 'icon' => 'Cloud',
42 - 'description' => __( 'Connect a Cloudflare zone for automatic edge purging when xSpeed clears its cache, plus a dev-mode toggle.', 'xspeed' ),
79 + 'description' => __( 'Clear the Cloudflare cache whenever xSpeed clears its own cache.', 'xspeed' ),
43 80 'custom_panel' => 'CloudflarePanel',
81 + 'group' => 'network',
44 82 );
45 83 }
46 84
47 85 /**
@@ -61,10 +99,10 @@
61 99 return array(
62 100 'enabled' => array(
63 101 'type' => 'bool',
64 102 'default' => false,
65 - 'label' => __( 'Enable Cloudflare integration', 'xspeed' ),
66 - 'description' => __( 'Use the credentials below to verify your zone and run purges.', 'xspeed' ),
103 + 'label' => __( 'Connect Cloudflare', 'xspeed' ),
104 + 'description' => __( 'Lets xSpeed clear the Cloudflare cache for your domain, using the details below.', 'xspeed' ),
67 105 ),
68 106 'auth_method' => array(
69 107 'type' => 'enum',
70 108 'default' => 'token',
@@ -73,9 +111,9 @@
73 111 'token' => 'API Token',
74 112 'key' => 'Global API Key',
75 113 ),
76 114 'label' => __( 'Authentication', 'xspeed' ),
77 - 'description' => __( 'API Tokens (scoped, recommended) or the legacy Global API Key with your account email.', 'xspeed' ),
115 + 'description' => __( 'An API token is safer and recommended. The older Global API Key also needs your account email.', 'xspeed' ),
78 116 'dependsOn' => array( 'field' => 'enabled' ),
79 117 ),
80 118 'api_token' => array(
81 119 'type' => 'secret',
@@ -80,9 +118,9 @@
80 118 'api_token' => array(
81 119 'type' => 'secret',
82 120 'default' => '',
83 121 'label' => __( 'API Token', 'xspeed' ),
84 - 'description' => __( 'Create a token at dash.cloudflare.com → My Profile → API Tokens. Needs "Zone → Cache Purge" + "Zone Settings" permissions.', 'xspeed' ),
122 + 'description' => __( 'Create one at dash.cloudflare.com → My Profile → API Tokens. Give it the "Zone → Cache Purge" and "Zone Settings" permissions.', 'xspeed' ),
85 123 // Only the token auth branch (and only while CF is enabled, via
86 124 // the transitive gate on auth_method → enabled).
87 125 'dependsOn' => array( 'field' => 'auth_method', 'value' => 'token' ),
88 126 ),
@@ -88,10 +126,10 @@
88 126 ),
89 127 'email' => array(
90 128 'type' => 'string',
91 129 'default' => '',
92 - 'label' => __( 'Account Email', 'xspeed' ),
93 - 'description' => __( 'Only used when Authentication is set to Global API Key.', 'xspeed' ),
130 + 'label' => __( 'Account email', 'xspeed' ),
131 + 'description' => __( 'The email address of your Cloudflare account.', 'xspeed' ),
94 132 'dependsOn' => array( 'field' => 'auth_method', 'value' => 'key' ),
95 133 ),
96 134 'api_key' => array(
97 135 'type' => 'secret',
@@ -96,9 +134,9 @@
96 134 'api_key' => array(
97 135 'type' => 'secret',
98 136 'default' => '',
99 137 'label' => __( 'Global API Key', 'xspeed' ),
100 - 'description' => __( 'Found at dash.cloudflare.com → My Profile → API Tokens → Global API Key.', 'xspeed' ),
138 + 'description' => __( 'Find it at dash.cloudflare.com → My Profile → API Tokens → Global API Key.', 'xspeed' ),
101 139 'dependsOn' => array( 'field' => 'auth_method', 'value' => 'key' ),
102 140 ),
103 141 'zone_id' => array(
104 142 'type' => 'string',
@@ -103,16 +141,16 @@
103 141 'zone_id' => array(
104 142 'type' => 'string',
105 143 'default' => '',
106 144 'label' => __( 'Zone ID', 'xspeed' ),
107 - 'description' => __( 'The 32-character hex Zone ID from your domain overview page.', 'xspeed' ),
145 + 'description' => __( 'The 32-character Zone ID shown on your domain overview page in Cloudflare.', 'xspeed' ),
108 146 'dependsOn' => array( 'field' => 'enabled' ),
109 147 ),
110 148 'auto_purge_on_update' => array(
111 149 'type' => 'bool',
112 150 'default' => true,
113 - 'label' => __( 'Auto-purge Cloudflare on xSpeed purge', 'xspeed' ),
114 - 'description' => __( 'When xSpeed clears its own cache (post save, settings change, manual purge), trigger a Cloudflare purge too.', 'xspeed' ),
151 + 'label' => __( 'Clear Cloudflare with xSpeed', 'xspeed' ),
152 + 'description' => __( 'Clear the Cloudflare cache each time xSpeed clears its own, for example after you save a post.', 'xspeed' ),
115 153 'dependsOn' => array( 'field' => 'enabled' ),
116 154 ),
117 155 );
118 156 }
@@ -187,8 +225,25 @@
187 225 add_action( 'init', array( $this, 'boot_on_init' ) );
188 226 }
189 227
190 228 /**
229 + * Leave no queued edge calls behind.
230 + *
231 + * A batch scheduled seconds before the module was switched off would
232 + * otherwise fire against a zone the site no longer manages, and the
233 + * event would sit in the cron table with no listener after that.
234 + */
235 + public function deactivate(): void {
236 + // `wp_unschedule_hook()`, not `wp_clear_scheduled_hook()`. The latter
237 + // keys on `md5( serialize( $args ) )` and defaults `$args` to an
238 + // empty array, so it only ever clears the no-arguments key. Every
239 + // event this module schedules carries the URL batch as its argument,
240 + // so clear_scheduled_hook cleared nothing at all here.
241 + wp_unschedule_hook( self::PURGE_URLS_EVENT );
242 + wp_unschedule_hook( self::PURGE_ALL_EVENT );
243 + }
244 +
245 + /**
191 246 * The real boot body — see boot() for why it runs on `init`.
192 247 */
193 248 public function boot_on_init(): void {
194 249 $opts = $this->get_settings();
@@ -194,13 +249,22 @@
194 249 $opts = $this->get_settings();
195 250 if ( empty( $opts['enabled'] ) ) {
196 251 return;
197 252 }
253 + // Something else on the site is already the Cloudflare layer in front
254 + // of it. The switch stays as the owner left it, and this zone is not
255 + // purged while the block lasts. See Module::blocked_by().
256 + if ( null !== $this->blocked_by() ) {
257 + return;
258 + }
198 259 if ( ! empty( $opts['auto_purge_on_update'] ) ) {
199 260 // xSpeed fires this action whenever it purges its own
200 261 // cache (see Cache::purge_all). Listening here keeps
201 262 // CF in sync without any new wiring elsewhere.
202 263 add_action( 'xspeed_after_purge_all', array( $this, 'on_xspeed_purge' ), 10, 0 );
264 + add_action( 'xspeed_after_purge_url', array( $this, 'on_xspeed_purge_url' ), 10, 1 );
265 + add_action( self::PURGE_URLS_EVENT, array( $this, 'purge_edge_urls' ), 10, 1 );
266 + add_action( self::PURGE_ALL_EVENT, array( $this, 'purge_edge_all' ), 10, 0 );
203 267 }
204 268 }
205 269
206 270 public function on_xspeed_purge(): void {
@@ -225,8 +289,321 @@
225 289 $this->purge_edge( 'auto-purge' );
226 290 }
227 291
228 292 /**
293 + * Mirror a single-URL purge at the edge.
294 + *
295 + * Post edits arrive here too when they clear only their affected pages
296 + * (`Cache::purge_urls()` publishes one event with every URL); an edit
297 + * that clears the whole site comes through the full-purge listener
298 + * above. What else reaches `purge_url()` is the narrower set: the two admin purge
299 + * buttons, an approved comment, a user change, a WooCommerce product or
300 + * stock change, `--url` on the CLI and REST, and MCP. Every one of those
301 + * cleared xSpeed's copy and left Cloudflare's, so the page stayed stale
302 + * at the edge until its lifetime ran out or somebody pressed Purge All —
303 + * which is a whole-zone purge to fix one page.
304 + *
305 + * Single-file purge is also the cheap call, which is the opposite of how
306 + * it looks. Cloudflare's tightest documented purge limit is the one on
307 + * purge-everything, hostname, tag and prefix; file purges are metered
308 + * separately and far more generously. The `purge_all` listener above is
309 + * the one near a limit, not this.
310 + *
311 + * @param array<string,mixed> $context The event payload. See the
312 + * `xspeed_after_purge_url` docblock.
313 + */
314 + public function on_xspeed_purge_url( $context ): void {
315 + if ( ! is_array( $context ) || 'urls' !== ( $context['scope'] ?? '' ) ) {
316 + return;
317 + }
318 + $urls = array_filter( array_map( 'strval', (array) ( $context['urls'] ?? array() ) ) );
319 + if ( array() === $urls ) {
320 + return;
321 + }
322 + // Same guard as the full-purge listener: `wp xspeed purge` reports
323 + // the edge as its own line item, and purging here as well would make
324 + // the outcome nobody reported the one that lands in the health record.
325 + if ( class_exists( '\\XSpeed\\Purge_Runner' ) && \XSpeed\Purge_Runner::covers( 'cloudflare' ) ) {
326 + return;
327 + }
328 + if ( true !== $this->can_purge_edge() ) {
329 + return;
330 + }
331 +
332 + // Collected and sent once, not one API call per URL. A request can
333 + // raise several of these (a bulk edit, a stock change on each item
334 + // of an order), and a round trip each would be a wait each.
335 + if ( array() === $this->pending_edge_urls ) {
336 + add_action( 'shutdown', array( $this, 'flush_edge_url_purges' ), 20 );
337 + }
338 + $blog = function_exists( 'get_current_blog_id' ) ? (int) get_current_blog_id() : 0;
339 + foreach ( $urls as $url ) {
340 + $this->pending_edge_urls[ $blog ][ $url ] = true;
341 + }
342 + \XSpeed\Cache::note_purge_forwarded( 'Cloudflare' );
343 + }
344 +
345 + /**
346 + * Hand whatever `on_xspeed_purge_url()` collected to cron.
347 + *
348 + * Three of the callers are ordinary visitor traffic — an approved
349 + * comment, a user registration, a WooCommerce stock change during
350 + * checkout — and none of them made an outbound request before this
351 + * listener existed. Doing the HTTPS inline would put a blocking round
352 + * trip to Cloudflare on the end of a shopper's checkout, once per
353 + * request, with the timeout as the worst case. So the batch is scheduled
354 + * and the request ends.
355 + *
356 + * Inline when there is nothing to defer to: cron cannot defer to itself,
357 + * and a CLI run exits before a spawned cron request would be served.
358 + * Both are contexts where a blocking call is the right answer anyway.
359 + *
360 + * Deliberately not what WP Rocket does — its Cloudflare add-on calls
361 + * `purge_files()` straight from `after_rocket_clean_post`, so a visitor
362 + * leaving a comment waits on Cloudflare. LiteSpeed sidesteps it by never
363 + * purging Cloudflare per URL at all. Deferring is the same thing
364 + * `Preloader` and `Cookie_Inspector` already do here for the same
365 + * reason: outbound HTTP belongs in a later request, not on the one that
366 + * happened to trigger it.
367 + *
368 + * Three ways a batch can still be lost, all silent because the health
369 + * record is only written inside the flush: a PHP fatal (WordPress's own
370 + * fatal handler is registered before `shutdown_action_hook` and ends the
371 + * process first), another plugin calling `exit` from a `shutdown`
372 + * callback at a priority below 20, and a `purge_url()` raised during
373 + * `shutdown` ABOVE priority 20, which re-arms a hook that has already
374 + * dispatched. Rare, but this is the note that saves the next person
375 + * debugging "the edge kept a stale page" from rediscovering them.
376 + *
377 + * Public because it is a `shutdown` callback; not part of the module's
378 + * contract.
379 + */
380 + public function flush_edge_url_purges(): void {
381 + $batches = $this->pending_edge_urls;
382 + $this->pending_edge_urls = array();
383 + $current = function_exists( 'get_current_blog_id' ) ? (int) get_current_blog_id() : 0;
384 +
385 + foreach ( $batches as $blog => $keyed ) {
386 + $urls = array_keys( $keyed );
387 + if ( array() === $urls ) {
388 + continue;
389 + }
390 + // Each batch is scheduled and sent as the site that raised it,
391 + // because the cron table, the settings, the health record and the
392 + // activity log are all per-site.
393 + $switched = (int) $blog !== $current && function_exists( 'switch_to_blog' );
394 + if ( $switched ) {
395 + switch_to_blog( (int) $blog );
396 + }
397 + try {
398 + $this->dispatch_edge_url_batch( $urls );
399 + } finally {
400 + // A throwing adapter must not leave the rest of shutdown
401 + // running as the wrong site.
402 + if ( $switched ) {
403 + restore_current_blog();
404 + }
405 + }
406 + }
407 + }
408 +
409 + /** Schedule one site's batch, or send it now where there is nothing to defer to. */
410 + private function dispatch_edge_url_batch( array $urls ): void {
411 + // Too many to name. Purge the zone instead of carrying every URL in
412 + // an autoloaded option, and say so, because a zone purge costs more
413 + // origin traffic than the page purges it replaces and nobody should
414 + // have to infer that it happened.
415 + if ( count( $urls ) > self::max_deferred_urls() ) {
416 + $this->dispatch_edge_purge_all( count( $urls ) );
417 + return;
418 + }
419 +
420 + if ( ! self::must_purge_inline() && function_exists( 'wp_schedule_single_event' ) ) {
421 + // `$wp_error = true`, because the bare form returns false for two
422 + // opposite situations and only one of them is a failure.
423 + //
424 + // Scheduling at `time()` puts the timestamp in the past by the
425 + // time core compares it, which sets core's `$min_timestamp` to 0
426 + // (wp-includes/cron.php) — so ANY identical event anywhere in the
427 + // cron table, however old, counts as a duplicate and the call
428 + // returns false. Two comments on the same post produce
429 + // byte-identical args, so the second one would have taken the
430 + // inline fallback: a blocking call to Cloudflare on a visitor's
431 + // request, which is the exact thing this deferral exists to
432 + // avoid, while the already-queued event fired anyway and sent
433 + // the batch twice.
434 + //
435 + // A duplicate means the work is already queued. That is success.
436 + $scheduled = wp_schedule_single_event( time(), self::PURGE_URLS_EVENT, array( $urls ), true );
437 + if ( true === $scheduled ) {
438 + return;
439 + }
440 + if ( is_wp_error( $scheduled ) && 'duplicate_event' === $scheduled->get_error_code() ) {
441 + return;
442 + }
443 + // Anything else — a filter vetoing the event, a broken cron
444 + // table — is a real refusal, and dropping the purge silently
445 + // would leave the edge stale with nothing to say so.
446 + }
447 +
448 + $this->purge_edge_urls( $urls );
449 + }
450 +
451 + /** Is this a context with no later request to defer the edge call to? */
452 + private static function must_purge_inline(): bool {
453 + if ( defined( 'WP_CLI' ) && WP_CLI ) {
454 + return true;
455 + }
456 + return function_exists( 'wp_doing_cron' ) && wp_doing_cron();
457 + }
458 +
459 + /**
460 + * How many URLs may ride along in a deferred batch.
461 + *
462 + * Filterable because the right answer depends on how long a site's cron
463 + * backlog sits: the cost is the payload's time in `alloptions`, not the
464 + * URL count itself.
465 + */
466 + private static function max_deferred_urls(): int {
467 + if ( ! function_exists( 'apply_filters' ) ) {
468 + return self::MAX_DEFERRED_URLS;
469 + }
470 +
471 + /**
472 + * Filter the batch size above which a zone purge replaces named URLs.
473 + *
474 + * @param int $max URLs per deferred batch.
475 + */
476 + $max = (int) apply_filters( 'xspeed_cloudflare_max_deferred_purge_urls', self::MAX_DEFERRED_URLS );
477 +
478 + // A filter of zero would send every single-page purge to the zone.
479 + return $max > 0 ? $max : self::MAX_DEFERRED_URLS;
480 + }
481 +
482 + /** Queue the zone-wide fallback, or run it now where cron cannot. */
483 + private function dispatch_edge_purge_all( int $url_count ): void {
484 + if ( class_exists( '\\XSpeed\\Activity_Log' ) ) {
485 + \XSpeed\Activity_Log::record(
486 + 'cache_purged',
487 + sprintf(
488 + /* translators: %d: number of URLs that changed at once. */
489 + __( 'Purging the whole Cloudflare zone: %d URLs changed at once, too many to purge individually', 'xspeed' ),
490 + $url_count
491 + )
492 + );
493 + }
494 +
495 + if ( ! self::must_purge_inline() && function_exists( 'wp_schedule_single_event' ) ) {
496 + // No arguments, so every oversized batch in a request collapses
497 + // onto one event. `duplicate_event` is the wanted outcome here,
498 + // not a failure.
499 + $scheduled = wp_schedule_single_event( time(), self::PURGE_ALL_EVENT, array(), true );
500 + if ( true === $scheduled ) {
501 + return;
502 + }
503 + if ( is_wp_error( $scheduled ) && 'duplicate_event' === $scheduled->get_error_code() ) {
504 + return;
505 + }
506 + }
507 +
508 + $this->purge_edge_all();
509 + }
510 +
511 + /**
512 + * Purge the whole zone, as the fallback for an oversized batch.
513 + *
514 + * Public because it is the `PURGE_ALL_EVENT` cron callback. Re-checks the
515 + * connection for the same reason the URL batch does: this runs in a later
516 + * request than the one that queued it.
517 + */
518 + public function purge_edge_all(): void {
519 + if ( true !== $this->can_purge_edge() ) {
520 + return;
521 + }
522 + $this->purge_edge( 'auto-purge' );
523 + }
524 +
525 + /**
526 + * Purge a batch of URLs at the edge and record the outcome.
527 + *
528 + * Public because it is the `PURGE_URLS_EVENT` cron callback.
529 + *
530 + * @param string[] $urls
531 + */
532 + public function purge_edge_urls( $urls ): void {
533 + $urls = array_values( array_filter( array_map( 'strval', (array) $urls ) ) );
534 + if ( array() === $urls ) {
535 + return;
536 + }
537 + // Re-checked here rather than trusted from collect time: a scheduled
538 + // batch runs in a later request, and the credentials or the switch
539 + // may have changed between the two.
540 + if ( true !== $this->can_purge_edge() ) {
541 + // Said out loud, because otherwise "the credentials were removed
542 + // between queueing and running" and "the purge succeeded" look
543 + // identical from the panel, and the pages stay stale at the edge
544 + // either way.
545 + if ( class_exists( '\\XSpeed\\Activity_Log' ) ) {
546 + \XSpeed\Activity_Log::record(
547 + 'cache_purge_skipped',
548 + sprintf(
549 + /* translators: %d: number of URLs. */
550 + _n(
551 + 'Skipped a queued Cloudflare purge of %d URL: the connection is no longer available',
552 + 'Skipped a queued Cloudflare purge of %d URLs: the connection is no longer available',
553 + count( $urls ),
554 + 'xspeed'
555 + ),
556 + count( $urls )
557 + ),
558 + \XSpeed\Activity_Log::WARN
559 + );
560 + }
561 + return;
562 + }
563 +
564 + $result = Cloudflare::purge_urls( $this->get_settings(), $urls );
565 + $ok = ! empty( $result['ok'] );
566 + $reason = $ok ? '' : $this->message_of( $result );
567 +
568 + // Recorded for the same reason the full purge is: a token that passes
569 + // verify can still lack "Zone → Cache Purge", and a silent auth
570 + // failure here means stale pages at the edge with nothing to say so.
571 + $this->record_health( $ok, 'purge', $reason );
572 +
573 + if ( ! class_exists( '\\XSpeed\\Activity_Log' ) ) {
574 + return;
575 + }
576 + if ( $ok ) {
577 + \XSpeed\Activity_Log::record(
578 + 'cache_purged',
579 + sprintf(
580 + /* translators: %d: number of URLs purged. */
581 + _n(
582 + 'Purged %d URL from the Cloudflare edge cache',
583 + 'Purged %d URLs from the Cloudflare edge cache',
584 + count( $urls ),
585 + 'xspeed'
586 + ),
587 + count( $urls )
588 + ),
589 + \XSpeed\Activity_Log::INFO
590 + );
591 + return;
592 + }
593 + \XSpeed\Activity_Log::record(
594 + 'cloudflare_purge_failed',
595 + sprintf(
596 + /* translators: 1: number of URLs, 2: failure reason. */
597 + __( 'Cloudflare URL purge failed (%1$d URL(s)): %2$s', 'xspeed' ),
598 + count( $urls ),
599 + $reason ? $reason : __( 'unknown error', 'xspeed' )
600 + ),
601 + \XSpeed\Activity_Log::WARN
602 + );
603 + }
604 +
605 + /**
229 606 * Whether this site can purge its Cloudflare zone right now.
230 607 *
231 608 * @return true|string True, or the reason it cannot — for the skip line
232 609 * in `wp xspeed purge`, which has to explain itself
@@ -236,8 +613,12 @@
236 613 $opts = $this->get_settings();
237 614 if ( empty( $opts['enabled'] ) ) {
238 615 return __( 'the Cloudflare integration is switched off', 'xspeed' );
239 616 }
617 + $blocked = $this->blocked_by();
618 + if ( null !== $blocked ) {
619 + return $blocked;
620 + }
240 621 if ( ! $this->has_credentials( $opts ) ) {
241 622 return __( 'no zone ID or API credentials are configured', 'xspeed' );
242 623 }
243 624
@@ -305,17 +686,19 @@
305 686 * Persist any settings sent with the save, then verify the credentials
306 687 * immediately so an invalid or newly-changed token surfaces on the panel
307 688 * instead of failing silently the next time xSpeed purges. Response shape
308 689 * is unchanged (flat settings) so the autosave client is unaffected. (#119)
690 + *
691 + * The parent writes the settings, so its licence, blocked-by and
692 + * wp-config refusals apply here too; a refused write is not verified.
309 693 */
310 694 public function rest_update_settings( \WP_REST_Request $request ) {
311 - $params = $request->get_json_params();
312 - if ( ! is_array( $params ) ) {
313 - $params = $request->get_params();
695 + $response = parent::rest_update_settings( $request );
696 + if ( is_wp_error( $response ) ) {
697 + return $response;
314 698 }
315 - $settings = $this->update_settings( is_array( $params ) ? $params : array() );
316 699 $this->verify_and_record();
317 - return rest_ensure_response( $settings );
700 + return $response;
318 701 }
319 702
320 703 public function rest_verify( \WP_REST_Request $request ) {
321 704 $res = Cloudflare::verify( $this->get_settings() );