diff options
Diffstat (limited to 'plugins/jetpack/jetpack_vendor/automattic/jetpack-sync/src/class-rest-endpoints.php')
-rw-r--r-- | plugins/jetpack/jetpack_vendor/automattic/jetpack-sync/src/class-rest-endpoints.php | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/plugins/jetpack/jetpack_vendor/automattic/jetpack-sync/src/class-rest-endpoints.php b/plugins/jetpack/jetpack_vendor/automattic/jetpack-sync/src/class-rest-endpoints.php index ae12ff32..6e4cb8c9 100644 --- a/plugins/jetpack/jetpack_vendor/automattic/jetpack-sync/src/class-rest-endpoints.php +++ b/plugins/jetpack/jetpack_vendor/automattic/jetpack-sync/src/class-rest-endpoints.php @@ -306,6 +306,17 @@ class REST_Endpoints { ) ); + // Trigger Dedicated Sync request. + register_rest_route( + 'jetpack/v4', + '/sync/spawn-sync', + array( + 'methods' => WP_REST_Server::READABLE, + 'callback' => __CLASS__ . '::spawn_sync', + 'permission_callback' => '__return_true', + ) + ); + } /** @@ -726,6 +737,38 @@ class REST_Endpoints { } /** + * This endpoint is used by Sync to spawn a + * dedicated Sync request which will trigger Sync to run. + * + * If Dedicated Sync is enabled, this callback should never run as + * processing of Sync actions will occur earlier and exit. + * + * @see Actions::init + * @see Sender::do_dedicated_sync_and_exit + * + * @since $$next_version$$ + * + * @return \WP_REST_Response + */ + public static function spawn_sync() { + nocache_headers(); + + if ( ! Settings::is_dedicated_sync_enabled() ) { + return new WP_Error( + 'dedicated_sync_disabled', + 'Dedicated Sync flow is disabled.', + array( 'status' => 422 ) + ); + } + + return new WP_Error( + 'dedicated_sync_failed', + 'Failed to process Dedicated Sync request', + array( 'status' => 500 ) + ); + } + + /** * Verify that request has default permissions to perform sync actions. * * @since 1.23.1 |