← All changes
|
jetpack_vendor/automattic/jetpack-search/src/class-plan.php
+16
-5
12.4.2
→
16.3
View file →
| @@ -11,8 +11,12 @@ | ||
| 11 | 11 | use Automattic\Jetpack\Connection\Client; |
| 12 | 12 | use Jetpack_Options; |
| 13 | 13 | use WP_Error; |
| 14 | 14 | |
| 15 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 16 | + exit( 0 ); | |
| 17 | +} | |
| 18 | + | |
| 15 | 19 | /** |
| 16 | 20 | * Registers the REST routes for Search. |
| 17 | 21 | */ |
| 18 | 22 | class Plan { |
| @@ -45,9 +49,14 @@ | ||
| 45 | 49 | /** |
| 46 | 50 | * Refresh plan info stored in options |
| 47 | 51 | */ |
| 48 | 52 | public function get_plan_info_from_wpcom() { |
| 49 | - $blog_id = Jetpack_Options::get_option( 'id' ); | |
| 53 | + $blog_id = Jetpack_Options::get_option( 'id' ); | |
| 54 | + // An unregistered site (or a stale cache view hiding the registration) has no | |
| 55 | + // blog ID: bail rather than requesting the malformed `/sites//…` path. | |
| 56 | + if ( ! $blog_id ) { | |
| 57 | + return new WP_Error( 'site_not_registered', 'Site not registered.' ); | |
| 58 | + } | |
| 50 | 59 | $response = Client::wpcom_json_api_request_as_blog( |
| 51 | 60 | '/sites/' . $blog_id . '/jetpack-search/plan', |
| 52 | 61 | '2', |
| 53 | 62 | array(), |
| @@ -63,9 +72,9 @@ | ||
| 63 | 72 | |
| 64 | 73 | /** |
| 65 | 74 | * Get plan info. |
| 66 | 75 | * |
| 67 | - * @param {bool} $force_refresh - Default to false. Set true to load from WPCOM. | |
| 76 | + * @param bool $force_refresh - Default to false. Set true to load from WPCOM. | |
| 68 | 77 | */ |
| 69 | 78 | public function get_plan_info( $force_refresh = false ) { |
| 70 | 79 | if ( $force_refresh ) { |
| 71 | 80 | $this->get_plan_info_from_wpcom(); |
| @@ -90,9 +99,9 @@ | ||
| 90 | 99 | * Returns true if plan supports Instant Search. |
| 91 | 100 | */ |
| 92 | 101 | public function supports_instant_search() { |
| 93 | 102 | $plan_info = $this->get_plan_info(); |
| 94 | - return ( isset( $plan_info['supports_instant_search'] ) && $plan_info['supports_instant_search'] ) || $this->has_jetpack_search_product(); | |
| 103 | + return ( isset( $plan_info['supports_instant_search'] ) && $plan_info['supports_instant_search'] ); | |
| 95 | 104 | } |
| 96 | 105 | |
| 97 | 106 | /** |
| 98 | 107 | * Returns true if the plan support either Instant Search or Classic Search. |
| @@ -98,9 +107,9 @@ | ||
| 98 | 107 | * Returns true if the plan support either Instant Search or Classic Search. |
| 99 | 108 | */ |
| 100 | 109 | public function supports_search() { |
| 101 | 110 | $plan_info = $this->get_plan_info(); |
| 102 | - return ( isset( $plan_info['supports_search'] ) && $plan_info['supports_search'] ) || $this->has_jetpack_search_product(); | |
| 111 | + return ( isset( $plan_info['supports_search'] ) && $plan_info['supports_search'] ); | |
| 103 | 112 | } |
| 104 | 113 | |
| 105 | 114 | /** |
| 106 | 115 | * Returns true if the plan usage is exceeded and search should no longer work. |
| @@ -158,8 +167,11 @@ | ||
| 158 | 167 | * |
| 159 | 168 | * @param array $plan_info - the decoded plan info array. |
| 160 | 169 | */ |
| 161 | 170 | public function set_plan_options( $plan_info ) { |
| 171 | + if ( isset( $plan_info['swap_classic_to_inline_search'] ) && is_bool( $plan_info['swap_classic_to_inline_search'] ) ) { | |
| 172 | + update_option( Module_Control::SEARCH_MODULE_SWAP_CLASSIC_TO_INLINE_OPTION_KEY, (bool) $plan_info['swap_classic_to_inline_search'] ); | |
| 173 | + } | |
| 162 | 174 | if ( ! isset( $plan_info['supports_instant_search'] ) ) { |
| 163 | 175 | return false; |
| 164 | 176 | } |
| 165 | 177 | // set option whether has Jetpack Search plan for capability reason. |
| @@ -173,6 +185,5 @@ | ||
| 173 | 185 | } |
| 174 | 186 | update_option( self::JETPACK_SEARCH_PLAN_INFO_OPTION_KEY, $plan_info ); |
| 175 | 187 | return true; |
| 176 | 188 | } |
| 177 | - | |
| 178 | 189 | } |