not empty in URL for testing purpose, or it's active. */ public static function is_new_pricing_202208() { // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.ValidatedSanitizedInput.MissingUnslash if ( isset( $_GET['new_pricing_202208'] ) && $_GET['new_pricing_202208'] ) { return true; } $record_count = intval( Search_Stats::estimate_count() ); $search_pricing = static::get_pricing_from_wpcom( $record_count ); if ( is_wp_error( $search_pricing ) ) { return false; } return '202208' === $search_pricing['pricing_version']; } /** * Override status to `needs_purchase_or_free` when status is `needs_purchase`. */ public static function get_status() { $status = parent::get_status(); return $status; } /** * Use centralized Search pricing API. * * The function is also used by the search package, as a result it could be called before site connection - i.e. blog token might not be available. * * @param int $record_count Record count to estimate pricing. * * @return array|WP_Error */ public static function get_pricing_from_wpcom( $record_count ) { static $pricings = array(); if ( isset( $pricings[ $record_count ] ) ) { return $pricings[ $record_count ]; } if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) { // For simple sites fetch the response directly. $response = Client::wpcom_json_api_request_as_blog( sprintf( '/jetpack-search/pricing?record_count=%1$d&locale=%2$s', $record_count, get_user_locale() ), '2', array( 'timeout' => 5 ), null, 'wpcom' ); } else { // For non-simple sites we have to use the wp_remote_get, as connection might not be available. $response = wp_remote_get( sprintf( Constants::get_constant( 'JETPACK__WPCOM_JSON_API_BASE' ) . '/wpcom/v2/jetpack-search/pricing?record_count=%1$d&locale=%2$s', $record_count, get_user_locale() ), array( 'timeout' => 5 ) ); } if ( is_wp_error( $response ) || 200 !== wp_remote_retrieve_response_code( $response ) ) { return new WP_Error( 'search_pricing_fetch_failed' ); } $body = wp_remote_retrieve_body( $response ); $pricings[ $record_count ] = json_decode( $body, true ); return $pricings[ $record_count ]; } /** * Hits the wpcom api to check Search status. * * @todo Maybe add caching. * * @return Object|WP_Error */ private static function get_state_from_wpcom() { static $status = null; if ( $status !== null ) { return $status; } $blog_id = Jetpack_Options::get_option( 'id' ); $response = Client::wpcom_json_api_request_as_blog( '/sites/' . $blog_id . '/jetpack-search/plan', '2', array( 'timeout' => 5 ), null, 'wpcom' ); if ( is_wp_error( $response ) || 200 !== wp_remote_retrieve_response_code( $response ) ) { return new WP_Error( 'search_state_fetch_failed' ); } $body = wp_remote_retrieve_body( $response ); $status = json_decode( $body ); return $status; } /** * Checks whether the product supports trial or not * * Returns true if it supports. Return false otherwise. * * Free products will always return false. * * @return boolean */ public static function has_trial_support() { return static::is_new_pricing_202208(); } /** * Checks if the site purchases contain a paid search plan * * @return bool */ public static function has_paid_plan_for_product() { $purchases_data = Wpcom_Products::get_site_current_purchases(); if ( is_wp_error( $purchases_data ) ) { return false; } if ( is_array( $purchases_data ) && ! empty( $purchases_data ) ) { foreach ( $purchases_data as $purchase ) { // Search is available as standalone product and as part of the Complete plan. if ( ( str_contains( $purchase->product_slug, 'jetpack_search' ) && ! str_contains( $purchase->product_slug, 'jetpack_search_free' ) ) || str_starts_with( $purchase->product_slug, 'jetpack_complete' ) ) { return true; } } } return false; } /** * Checks if the site purchases contain a free search plan * * @return bool */ public static function has_free_plan_for_product() { $purchases_data = Wpcom_Products::get_site_current_purchases(); if ( is_wp_error( $purchases_data ) ) { return false; } if ( is_array( $purchases_data ) && ! empty( $purchases_data ) ) { foreach ( $purchases_data as $purchase ) { if ( str_contains( $purchase->product_slug, 'jetpack_search_free' ) ) { return true; } } } return false; } /** * Activates the product. Try to enable instant search after the Search module was enabled. * * @param bool|WP_Error $product_activation Is the result of the top level activation actions. You probably won't do anything if it is an WP_Error. * @return bool|WP_Error */ public static function do_product_specific_activation( $product_activation ) { $product_activation = parent::do_product_specific_activation( $product_activation ); if ( is_wp_error( $product_activation ) ) { return $product_activation; } if ( class_exists( 'Automattic\Jetpack\Search\Module_Control' ) ) { ( new Search_Module_Control() )->enable_instant_search(); } // we don't want to change the success of the activation if we fail to activate instant search. That's not mandatory. return $product_activation; } /** * Get the URL the user is taken after activating the product * * @return ?string */ public static function get_post_activation_url() { return ''; // stay in My Jetpack page or continue the purchase flow if needed. } /** * Get the URL where the user manages the product * * @return ?string */ public static function get_manage_url() { return admin_url( 'admin.php?page=jetpack-search' ); } }
Fatal error: Uncaught Error: Class "Automattic\Jetpack\My_Jetpack\Products\Search" not found in /htdocs/wp-content/plugins/jetpack/jetpack_vendor/automattic/jetpack-my-jetpack/src/class-products.php:192 Stack trace: #0 /htdocs/wp-content/plugins/jetpack/jetpack_vendor/automattic/jetpack-my-jetpack/src/class-initializer.php(80): Automattic\Jetpack\My_Jetpack\Products::extend_plugins_action_links() #1 /htdocs/wp-content/plugins/jetpack/class.jetpack.php(976): Automattic\Jetpack\My_Jetpack\Initializer::init() #2 /htdocs/wp-includes/class-wp-hook.php(324): Jetpack->late_initialization('') #3 /htdocs/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters(NULL, Array) #4 /htdocs/wp-includes/plugin.php(517): WP_Hook->do_action(Array) #5 /htdocs/wp-settings.php(559): do_action('plugins_loaded') #6 /htdocs/wp-config.php(85): require_once('/htdocs/wp-sett...') #7 /htdocs/wp-load.php(50): require_once('/htdocs/wp-conf...') #8 /htdocs/wp-blog-header.php(13): require_once('/htdocs/wp-load...') #9 /htdocs/index.php(17): require('/htdocs/wp-blog...') #10 {main} thrown in /htdocs/wp-content/plugins/jetpack/jetpack_vendor/automattic/jetpack-my-jetpack/src/class-products.php on line 192