diff options
Diffstat (limited to 'plugins/jetpack/_inc/lib/admin-pages/class-jetpack-redux-state-helper.php')
-rw-r--r-- | plugins/jetpack/_inc/lib/admin-pages/class-jetpack-redux-state-helper.php | 38 |
1 files changed, 28 insertions, 10 deletions
diff --git a/plugins/jetpack/_inc/lib/admin-pages/class-jetpack-redux-state-helper.php b/plugins/jetpack/_inc/lib/admin-pages/class-jetpack-redux-state-helper.php index ebad61af..dff497ea 100644 --- a/plugins/jetpack/_inc/lib/admin-pages/class-jetpack-redux-state-helper.php +++ b/plugins/jetpack/_inc/lib/admin-pages/class-jetpack-redux-state-helper.php @@ -13,6 +13,8 @@ use Automattic\Jetpack\Constants; use Automattic\Jetpack\Device_Detection\User_Agent_Info; use Automattic\Jetpack\Identity_Crisis; use Automattic\Jetpack\Licensing; +use Automattic\Jetpack\Licensing\Endpoints as Licensing_Endpoints; +use Automattic\Jetpack\My_Jetpack\Initializer as My_Jetpack_Initializer; use Automattic\Jetpack\Partner; use Automattic\Jetpack\Partner_Coupon as Jetpack_Partner_Coupon; use Automattic\Jetpack\Status; @@ -23,6 +25,18 @@ use Automattic\Jetpack\Status\Host; */ class Jetpack_Redux_State_Helper { /** + * Generate minimal state for React to fetch its own data asynchronously after load + * This can improve user experience, reducing time spent on server requests before serving the page + * e.g. used by React Disconnect Dialog on plugins page where the full initial state is not needed + */ + public static function get_minimal_state() { + return array( + 'WP_API_root' => esc_url_raw( rest_url() ), + 'WP_API_nonce' => wp_create_nonce( 'wp_rest' ), + ); + } + + /** * Generate the initial state array to be used by the Redux store. */ public static function get_initial_state() { @@ -45,6 +59,10 @@ class Jetpack_Redux_State_Helper { $modules[ $slug ]['long_description'] = html_entity_decode( $data['long_description'] ); } + // "mock" a block module in order to get it searchable in the settings. + $modules['blocks']['module'] = 'blocks'; + $modules['blocks']['additional_search_queries'] = esc_html_x( 'blocks, block, gutenberg', 'Search terms', 'jetpack' ); + // Collecting roles that can view site stats. $stats_roles = array(); $enabled_roles = function_exists( 'stats_get_option' ) ? stats_get_option( 'roles' ) : array( 'administrator' ); @@ -100,10 +118,6 @@ class Jetpack_Redux_State_Helper { $host = new Host(); - // Get Jetpack benefits for this site. - $jetpack_benefits_response = Jetpack_Core_API_Site_Endpoint::get_benefits(); - $jetpack_benefits = 200 === $jetpack_benefits_response->status ? json_decode( $jetpack_benefits_response->data['data'] ) : array(); - return array( 'WP_API_root' => esc_url_raw( rest_url() ), 'WP_API_nonce' => wp_create_nonce( 'wp_rest' ), @@ -113,7 +127,7 @@ class Jetpack_Redux_State_Helper { 'pluginBaseUrl' => plugins_url( '', JETPACK__PLUGIN_FILE ), 'connectionStatus' => $connection_status, 'connectedPlugins' => Connection_Plugin_Storage::get_all(), - 'connectUrl' => false == $current_user_data['isConnected'] // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison + 'connectUrl' => false == $current_user_data['isConnected'] // phpcs:ignore Universal.Operators.StrictComparisons.LooseEqual ? Jetpack::init()->build_connect_url( true, false, false ) : '', 'dismissedNotices' => self::get_dismissed_jetpack_notices(), @@ -145,7 +159,7 @@ class Jetpack_Redux_State_Helper { 'icon' => has_site_icon() ? apply_filters( 'jetpack_photon_url', get_site_icon_url(), array( 'w' => 64 ) ) : '', - 'siteVisibleToSearchEngines' => '1' == get_option( 'blog_public' ), // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison + 'siteVisibleToSearchEngines' => '1' == get_option( 'blog_public' ), // phpcs:ignore Universal.Operators.StrictComparisons.LooseEqual /** * Whether promotions are visible or not. * @@ -160,6 +174,8 @@ class Jetpack_Redux_State_Helper { 'plan' => Jetpack_Plan::get(), 'showBackups' => Jetpack::show_backups_ui(), 'showRecommendations' => Jetpack_Recommendations::is_enabled(), + /** This filter is documented in my-jetpack/src/class-initializer.php */ + 'showMyJetpack' => My_Jetpack_Initializer::should_initialize(), 'isMultisite' => is_multisite(), 'dateFormat' => get_option( 'date_format' ), ), @@ -168,9 +184,10 @@ class Jetpack_Redux_State_Helper { 'hasUpdate' => (bool) get_theme_update_available( $current_theme ), 'support' => array( 'infinite-scroll' => current_theme_supports( 'infinite-scroll' ) || in_array( $current_theme->get_stylesheet(), $inf_scr_support_themes, true ), + 'widgets' => current_theme_supports( 'widgets' ), + 'webfonts' => WP_Theme_JSON_Resolver::theme_has_support() && function_exists( 'wp_register_webfont_provider' ) && function_exists( 'wp_register_webfonts' ), ), ), - 'jetpackBenefits' => $jetpack_benefits, 'jetpackStateNotices' => array( 'messageCode' => Jetpack::state( 'message' ), 'errorCode' => Jetpack::state( 'error' ), @@ -189,12 +206,14 @@ class Jetpack_Redux_State_Helper { 'licensing' => array( 'error' => Licensing::instance()->last_error(), 'showLicensingUi' => Licensing::instance()->is_licensing_input_enabled(), - 'userCounts' => Jetpack_Core_Json_Api_Endpoints::get_user_license_counts(), + 'userCounts' => Licensing_Endpoints::get_user_license_counts(), 'activationNoticeDismiss' => Licensing::instance()->get_license_activation_notice_dismiss(), ), 'hasSeenWCConnectionModal' => Jetpack_Options::get_option( 'has_seen_wc_connection_modal', false ), + 'newRecommendations' => Jetpack_Recommendations::get_new_conditional_recommendations(), // Check if WooCommerce plugin is active (based on https://docs.woocommerce.com/document/create-a-plugin/). 'isWooCommerceActive' => in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', Jetpack::get_active_plugins() ), true ), + 'useMyJetpackLicensingUI' => My_Jetpack_Initializer::is_licensing_ui_enabled(), ); } @@ -342,7 +361,7 @@ class Jetpack_Redux_State_Helper { $connect_urls = array(); jetpack_require_lib( 'class.jetpack-keyring-service-helper' ); // phpcs:disable - foreach ( Jetpack_Keyring_Service_Helper::$SERVICES as $service_name => $service_info ) { + foreach ( Jetpack_Keyring_Service_Helper::SERVICES as $service_name => $service_info ) { // phpcs:enable $connect_urls[ $service_name ] = Jetpack_Keyring_Service_Helper::connect_url( $service_name, $service_info['for'] ); } @@ -380,7 +399,6 @@ class Jetpack_Redux_State_Helper { public static function generate_purchase_token() { return wp_generate_password( 12, false ); } - } /** |