PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.3-beta
Jetpack – WP Security, Backup, Speed, & Growth v16.3-beta
16.3 16.3-beta 16.3-a.5 16.3-a.7 16.3-a.3 16.3-a.1 16.2 16.2-beta 12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 All 508 releases
← All changes | jetpack_vendor/automattic/jetpack-search/src/class-rest-controller.php +52 -0 16.3-a.5 → 16.3-beta View file →
@@ -182,8 +182,24 @@
182 182 )
183 183 );
184 184 register_rest_route(
185 185 static::$namespace,
186 + '/search/plan/activate-free',
187 + array(
188 + 'methods' => WP_REST_Server::EDITABLE,
189 + 'callback' => array( $this, 'activate_free_plan' ),
190 + 'permission_callback' => array( $this, 'require_admin_privilege_callback' ),
191 + 'args' => array(
192 + 'source' => array(
193 + 'type' => 'string',
194 + 'required' => false,
195 + 'sanitize_callback' => 'sanitize_key',
196 + ),
197 + ),
198 + )
199 + );
200 + register_rest_route(
201 + static::$namespace,
186 202 '/search/plan/deactivate',
187 203 array(
188 204 'methods' => WP_REST_Server::EDITABLE,
189 205 'callback' => array( $this, 'deactivate_plan' ),
@@ -612,8 +628,44 @@
612 628 array(
613 629 'code' => 'success',
614 630 )
615 631 );
632 + }
633 +
634 + /**
635 + * Grant the free Search product to this site instead of sending the user to a $0 checkout.
636 + *
637 + * POST `jetpack/v4/search/plan/activate-free`
638 + *
639 + * @since 8.3.0
640 + *
641 + * @param WP_REST_Request $request - REST request.
642 + * @return WP_REST_Response|WP_Error Errors carry `checkout_fallback`, which the dashboard
643 + * branches on to decide whether to fall back to checkout.
644 + */
645 + public function activate_free_plan( $request ) {
646 + /*
647 + * Another plugin can load an older My Jetpack before this package's copy registers, and
648 + * that copy has no such method. Degrade to the checkout the dashboard still has.
649 + */
650 + if ( ! method_exists( Search_Product::class, 'activate_free_product' ) ) {
651 + return new WP_Error(
652 + 'jetpack_search_free_activation_unavailable',
653 + __( 'Jetpack Search Free could not be activated for this site.', 'jetpack-search-pkg' ),
654 + array(
655 + 'status' => 501,
656 + 'checkout_fallback' => true,
657 + )
658 + );
659 + }
660 +
661 + $source = $request->get_param( 'source' );
662 + $result = Search_Product::activate_free_product( $source ? $source : 'search-dashboard' );
663 + if ( is_wp_error( $result ) ) {
664 + return $result;
665 + }
666 +
667 + return rest_ensure_response( $result );
616 668 }
617 669
618 670 /**
619 671 * Deactivate plan: turn off search module and instant search.