← All changes
|
_inc/lib/admin-pages/class-jetpack-redux-state-helper.php
+125
-205
13.3.3
→
16.3-beta
View file →
| @@ -6,9 +6,10 @@ | ||
| 6 | 6 | * @package automattic/jetpack |
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | 9 | use Automattic\Jetpack\Blaze; |
| 10 | -use Automattic\Jetpack\Boost_Speed_Score\Speed_Score_History; | |
| 10 | +use Automattic\Jetpack\Comments\Block_Editor; | |
| 11 | +use Automattic\Jetpack\Comments\Comments; | |
| 11 | 12 | use Automattic\Jetpack\Connection\Manager as Connection_Manager; |
| 12 | 13 | use Automattic\Jetpack\Connection\Plugin_Storage as Connection_Plugin_Storage; |
| 13 | 14 | use Automattic\Jetpack\Connection\REST_Connector; |
| 14 | 15 | use Automattic\Jetpack\Constants; |
| @@ -14,17 +15,14 @@ | ||
| 14 | 15 | use Automattic\Jetpack\Constants; |
| 15 | 16 | use Automattic\Jetpack\Current_Plan as Jetpack_Plan; |
| 16 | 17 | use Automattic\Jetpack\Device_Detection\User_Agent_Info; |
| 17 | 18 | use Automattic\Jetpack\Identity_Crisis; |
| 18 | -use Automattic\Jetpack\Image_CDN\Image_CDN_Core; | |
| 19 | -use Automattic\Jetpack\Image_CDN\Image_CDN_Image; | |
| 20 | 19 | use Automattic\Jetpack\IP\Utils as IP_Utils; |
| 21 | 20 | use Automattic\Jetpack\Licensing; |
| 22 | 21 | use Automattic\Jetpack\Licensing\Endpoints as Licensing_Endpoints; |
| 23 | 22 | use Automattic\Jetpack\My_Jetpack\Initializer as My_Jetpack_Initializer; |
| 24 | -use Automattic\Jetpack\My_Jetpack\Jetpack_Manage; | |
| 25 | 23 | use Automattic\Jetpack\Partner; |
| 26 | -use Automattic\Jetpack\Partner_Coupon as Jetpack_Partner_Coupon; | |
| 24 | +use Automattic\Jetpack\Publicize\Keyring_Helper; | |
| 27 | 25 | use Automattic\Jetpack\Stats\Options as Stats_Options; |
| 28 | 26 | use Automattic\Jetpack\Status; |
| 29 | 27 | use Automattic\Jetpack\Status\Host; |
| 30 | 28 | |
| @@ -44,13 +42,33 @@ | ||
| 44 | 42 | ); |
| 45 | 43 | } |
| 46 | 44 | |
| 47 | 45 | /** |
| 46 | + * Generate the state for the plugins page: the minimal state plus what the deactivation survey needs. | |
| 47 | + * | |
| 48 | + * @since 16.3 | |
| 49 | + * | |
| 50 | + * @return array | |
| 51 | + */ | |
| 52 | + public static function get_plugins_page_state() { | |
| 53 | + $state = self::get_minimal_state(); | |
| 54 | + | |
| 55 | + $connection = new Connection_Manager(); | |
| 56 | + | |
| 57 | + $state['pluginDeactivation'] = array( | |
| 58 | + 'siteId' => (int) Jetpack_Options::get_option( 'id' ), | |
| 59 | + 'hasConnectedUser' => $connection->has_connected_user(), | |
| 60 | + 'isCurrentUserConnected' => $connection->is_user_connected(), | |
| 61 | + ); | |
| 62 | + | |
| 63 | + return $state; | |
| 64 | + } | |
| 65 | + | |
| 66 | + /** | |
| 48 | 67 | * Generate the initial state array to be used by the Redux store. |
| 49 | 68 | */ |
| 50 | 69 | public static function get_initial_state() { |
| 51 | 70 | global $is_safari; |
| 52 | - global $wp_version; | |
| 53 | 71 | |
| 54 | 72 | // Load API endpoint base classes and endpoints for getting the module list fed into the JS Admin Page. |
| 55 | 73 | require_once JETPACK__PLUGIN_DIR . '_inc/lib/core-api/class.jetpack-core-api-xmlrpc-consumer-endpoint.php'; |
| 56 | 74 | require_once JETPACK__PLUGIN_DIR . '_inc/lib/core-api/class.jetpack-core-api-module-endpoints.php'; |
| @@ -128,35 +146,30 @@ | ||
| 128 | 146 | ); |
| 129 | 147 | |
| 130 | 148 | $connection_status = array_merge( REST_Connector::connection_status( false ), $connection_status ); |
| 131 | 149 | |
| 132 | - $host = new Host(); | |
| 133 | - | |
| 134 | - $speed_score_history = new Speed_Score_History( wp_parse_url( get_site_url(), PHP_URL_HOST ) ); | |
| 135 | - | |
| 136 | 150 | $block_availability = Jetpack_Gutenberg::get_cached_availability(); |
| 137 | 151 | |
| 138 | 152 | return array( |
| 139 | - 'WP_API_root' => esc_url_raw( rest_url() ), | |
| 140 | - 'WP_API_nonce' => wp_create_nonce( 'wp_rest' ), | |
| 141 | - 'registrationNonce' => wp_create_nonce( 'jetpack-registration-nonce' ), | |
| 142 | - 'purchaseToken' => self::get_purchase_token(), | |
| 143 | - 'partnerCoupon' => Jetpack_Partner_Coupon::get_coupon(), | |
| 144 | - 'pluginBaseUrl' => plugins_url( '', JETPACK__PLUGIN_FILE ), | |
| 145 | - 'connectionStatus' => $connection_status, | |
| 146 | - 'connectedPlugins' => Connection_Plugin_Storage::get_all(), | |
| 147 | - 'connectUrl' => false == $current_user_data['isConnected'] // phpcs:ignore Universal.Operators.StrictComparisons.LooseEqual | |
| 153 | + 'WP_API_root' => esc_url_raw( rest_url() ), | |
| 154 | + 'WP_API_nonce' => wp_create_nonce( 'wp_rest' ), | |
| 155 | + 'registrationNonce' => '', // Not used, keeping it for compatibility reasons, see https://github.com/Automattic/jetpack/pull/42076 | |
| 156 | + 'purchaseToken' => self::get_purchase_token(), | |
| 157 | + 'pluginBaseUrl' => plugins_url( '', JETPACK__PLUGIN_FILE ), | |
| 158 | + 'connectionStatus' => $connection_status, | |
| 159 | + 'connectedPlugins' => Connection_Plugin_Storage::get_all(), | |
| 160 | + 'connectUrl' => false == $current_user_data['isConnected'] // phpcs:ignore Universal.Operators.StrictComparisons.LooseEqual | |
| 148 | 161 | ? Jetpack::init()->build_connect_url( true, false, false ) |
| 149 | 162 | : '', |
| 150 | - 'dismissedNotices' => self::get_dismissed_jetpack_notices(), | |
| 151 | - 'isDevVersion' => Jetpack::is_development_version(), | |
| 152 | - 'currentVersion' => JETPACK__VERSION, | |
| 153 | - 'is_gutenberg_available' => true, | |
| 154 | - 'getModules' => $modules, | |
| 155 | - 'rawUrl' => ( new Status() )->get_site_suffix(), | |
| 156 | - 'adminUrl' => esc_url( admin_url() ), | |
| 157 | - 'siteTitle' => (string) htmlspecialchars_decode( get_option( 'blogname' ), ENT_QUOTES ), | |
| 158 | - 'stats' => array( | |
| 163 | + 'dismissedNotices' => self::get_dismissed_jetpack_notices(), | |
| 164 | + 'isDevVersion' => Jetpack::is_development_version(), | |
| 165 | + 'currentVersion' => JETPACK__VERSION, | |
| 166 | + 'is_gutenberg_available' => true, | |
| 167 | + 'getModules' => $modules, | |
| 168 | + 'rawUrl' => ( new Status() )->get_site_suffix(), | |
| 169 | + 'adminUrl' => esc_url( admin_url() ), | |
| 170 | + 'siteTitle' => htmlspecialchars_decode( get_option( 'blogname' ), ENT_QUOTES ), | |
| 171 | + 'stats' => array( | |
| 159 | 172 | // data is populated asynchronously on page load. |
| 160 | 173 | 'data' => array( |
| 161 | 174 | 'general' => false, |
| 162 | 175 | 'day' => false, |
| @@ -164,19 +177,20 @@ | ||
| 164 | 177 | 'month' => false, |
| 165 | 178 | ), |
| 166 | 179 | 'roles' => $stats_roles, |
| 167 | 180 | ), |
| 168 | - 'aff' => Partner::init()->get_partner_code( Partner::AFFILIATE_CODE ), | |
| 169 | - 'partnerSubsidiaryId' => Partner::init()->get_partner_code( Partner::SUBSIDIARY_CODE ), | |
| 170 | - 'settings' => self::get_flattened_settings(), | |
| 171 | - 'userData' => array( | |
| 181 | + 'aff' => Partner::init()->get_partner_code( Partner::AFFILIATE_CODE ), | |
| 182 | + 'partnerSubsidiaryId' => Partner::init()->get_partner_code( Partner::SUBSIDIARY_CODE ), | |
| 183 | + 'settings' => self::get_flattened_settings(), | |
| 184 | + 'userData' => array( | |
| 172 | 185 | 'currentUser' => $current_user_data, |
| 173 | 186 | ), |
| 174 | - 'siteData' => array( | |
| 187 | + 'siteData' => array( | |
| 175 | 188 | 'blog_id' => Jetpack_Options::get_option( 'id', 0 ), |
| 176 | 189 | 'icon' => has_site_icon() |
| 177 | 190 | ? apply_filters( 'jetpack_photon_url', get_site_icon_url(), array( 'w' => 64 ) ) |
| 178 | 191 | : '', |
| 192 | + 'representativeImage' => self::get_site_image(), | |
| 179 | 193 | 'siteVisibleToSearchEngines' => '1' == get_option( 'blog_public' ), // phpcs:ignore Universal.Operators.StrictComparisons.LooseEqual |
| 180 | 194 | /** |
| 181 | 195 | * Whether promotions are visible or not. |
| 182 | 196 | * |
| @@ -184,23 +198,23 @@ | ||
| 184 | 198 | * |
| 185 | 199 | * @param bool $are_promotions_active Status of promotions visibility. True by default. |
| 186 | 200 | */ |
| 187 | 201 | 'showPromotions' => apply_filters( 'jetpack_show_promotions', true ), |
| 188 | - 'isAtomicSite' => $host->is_woa_site(), | |
| 189 | - 'isWoASite' => $host->is_woa_site(), | |
| 190 | - 'isAtomicPlatform' => $host->is_atomic_platform(), | |
| 191 | 202 | 'plan' => Jetpack_Plan::get(), |
| 192 | 203 | 'showBackups' => Jetpack::show_backups_ui(), |
| 193 | - 'showRecommendations' => Jetpack_Recommendations::is_enabled(), | |
| 204 | + 'showScan' => Jetpack::show_scan_ui(), | |
| 194 | 205 | /** This filter is documented in my-jetpack/src/class-initializer.php */ |
| 195 | 206 | 'showMyJetpack' => My_Jetpack_Initializer::should_initialize(), |
| 196 | 207 | 'isMultisite' => is_multisite(), |
| 197 | 208 | 'dateFormat' => get_option( 'date_format' ), |
| 198 | - 'latestBoostSpeedScores' => $speed_score_history->latest(), | |
| 199 | - 'isSharingBlockAvailable' => (bool) isset( $block_availability['sharing-buttons'] ) | |
| 209 | + 'isSharingBlockAvailable' => isset( $block_availability['sharing-buttons'] ) | |
| 200 | 210 | && $block_availability['sharing-buttons']['available'], |
| 211 | + 'isLikeBlockAvailable' => isset( $block_availability['like'] ) | |
| 212 | + && $block_availability['like']['available'], | |
| 213 | + // The rebuilt comment form is what offers blocks; the package may lag this file on a staged deploy. | |
| 214 | + 'isCommentBlocksAvailable' => class_exists( Block_Editor::class ) && Comments::is_enabled(), | |
| 201 | 215 | ), |
| 202 | - 'themeData' => array( | |
| 216 | + 'themeData' => array( | |
| 203 | 217 | 'name' => $current_theme->get( 'Name' ), |
| 204 | 218 | 'stylesheet' => $current_theme->get_stylesheet(), |
| 205 | 219 | 'hasUpdate' => (bool) get_theme_update_available( $current_theme ), |
| 206 | 220 | 'isBlockTheme' => (bool) $current_theme->is_block_theme(), |
| @@ -210,105 +224,53 @@ | ||
| 210 | 224 | 'webfonts' => wp_theme_has_theme_json() |
| 211 | 225 | && ( function_exists( 'wp_register_webfont_provider' ) || function_exists( 'wp_register_webfonts' ) ), |
| 212 | 226 | ), |
| 213 | 227 | ), |
| 214 | - 'jetpackStateNotices' => array( | |
| 228 | + 'jetpackStateNotices' => array( | |
| 215 | 229 | 'messageCode' => Jetpack::state( 'message' ), |
| 216 | 230 | 'errorCode' => Jetpack::state( 'error' ), |
| 217 | 231 | 'errorDescription' => Jetpack::state( 'error_description' ), |
| 218 | - 'messageContent' => Jetpack::state( 'display_update_modal' ) ? self::get_update_modal_data() : null, | |
| 219 | 232 | ), |
| 220 | - 'tracksUserData' => Jetpack_Tracks_Client::get_connected_user_tracks_identity(), | |
| 221 | - 'currentIp' => IP_Utils::get_ip(), | |
| 222 | - 'lastPostUrl' => esc_url( $last_post ), | |
| 223 | - 'externalServicesConnectUrls' => self::get_external_services_connect_urls(), | |
| 224 | - 'calypsoEnv' => ( new Host() )->get_calypso_env(), | |
| 225 | - 'products' => Jetpack::get_products_for_purchase(), | |
| 226 | - 'recommendationsStep' => Jetpack_Core_Json_Api_Endpoints::get_recommendations_step()['step'], | |
| 227 | - 'isSafari' => $is_safari || User_Agent_Info::is_opera_desktop(), // @todo Rename isSafari everywhere. | |
| 228 | - 'doNotUseConnectionIframe' => Constants::is_true( 'JETPACK_SHOULD_NOT_USE_CONNECTION_IFRAME' ), | |
| 229 | - 'licensing' => array( | |
| 233 | + 'tracksUserData' => Jetpack_Tracks_Client::get_connected_user_tracks_identity(), | |
| 234 | + 'currentIp' => IP_Utils::get_ip(), | |
| 235 | + 'lastPostUrl' => esc_url( $last_post ), | |
| 236 | + 'externalServicesConnectUrls' => self::get_external_services_connect_urls(), | |
| 237 | + 'calypsoEnv' => ( new Host() )->get_calypso_env(), | |
| 238 | + 'isSafari' => $is_safari || User_Agent_Info::is_opera_desktop(), // @todo Rename isSafari everywhere. | |
| 239 | + 'doNotUseConnectionIframe' => Constants::is_true( 'JETPACK_SHOULD_NOT_USE_CONNECTION_IFRAME' ), | |
| 240 | + 'licensing' => array( | |
| 230 | 241 | 'error' => Licensing::instance()->last_error(), |
| 231 | 242 | 'showLicensingUi' => Licensing::instance()->is_licensing_input_enabled(), |
| 232 | 243 | 'userCounts' => Licensing_Endpoints::get_user_license_counts(), |
| 233 | 244 | 'activationNoticeDismiss' => Licensing::instance()->get_license_activation_notice_dismiss(), |
| 234 | 245 | ), |
| 235 | - 'jetpackManage' => array( | |
| 236 | - 'isEnabled' => Jetpack_Manage::could_use_jp_manage(), | |
| 237 | - 'isAgencyAccount' => Jetpack_Manage::is_agency_account(), | |
| 246 | + 'useMyJetpackLicensingUI' => My_Jetpack_Initializer::is_licensing_ui_enabled(), | |
| 247 | + 'isOdysseyStatsEnabled' => Stats_Options::get_option( 'enable_odyssey_stats' ), | |
| 248 | + 'shouldInitializeBlaze' => Blaze::should_initialize(), | |
| 249 | + 'isBlazeDashboardEnabled' => Blaze::is_dashboard_enabled(), | |
| 250 | + // The composed AI gate chain (host, and the master where its rollout | |
| 251 | + // is active) — what the editor enforces, for settings UI that must | |
| 252 | + // not contradict it. | |
| 253 | + 'isAiEnabled' => Jetpack_AI_Settings::is_ai_enabled(), | |
| 254 | + // The AI SEO feature, gates folded in: controls that drive only its | |
| 255 | + // automatic half must follow it too. | |
| 256 | + 'isAiSeoEnabled' => Jetpack_AI_Settings::is_ai_seo_enabled(), | |
| 257 | + 'isSubscriptionSiteEnabled' => apply_filters( 'jetpack_subscription_site_enabled', false ), | |
| 258 | + 'newsletterDateExample' => gmdate( get_option( 'date_format' ), time() ), | |
| 259 | + 'subscriptionSiteEditSupported' => $current_theme->is_block_theme(), | |
| 260 | + | |
| 261 | + /* | |
| 262 | + * This filter is already documented in jetpack/modules/subscriptions.php. | |
| 263 | + * Defaults on for every site; hosts can opt out with the filter. | |
| 264 | + */ | |
| 265 | + 'isWpAdminSubscriberManagementEnabled' => apply_filters( | |
| 266 | + 'jetpack_wp_admin_subscriber_management_enabled', | |
| 267 | + true | |
| 238 | 268 | ), |
| 239 | - 'hasSeenWCConnectionModal' => Jetpack_Options::get_option( 'has_seen_wc_connection_modal', false ), | |
| 240 | - 'newRecommendations' => Jetpack_Recommendations::get_new_conditional_recommendations(), | |
| 241 | - // Check if WooCommerce plugin is active (based on https://docs.woocommerce.com/document/create-a-plugin/). | |
| 242 | - 'isWooCommerceActive' => in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', Jetpack::get_active_plugins() ), true ), | |
| 243 | - 'useMyJetpackLicensingUI' => My_Jetpack_Initializer::is_licensing_ui_enabled(), | |
| 244 | - 'isOdysseyStatsEnabled' => Stats_Options::get_option( 'enable_odyssey_stats' ), | |
| 245 | - 'shouldInitializeBlaze' => Blaze::should_initialize(), | |
| 246 | - 'isBlazeDashboardEnabled' => Blaze::is_dashboard_enabled(), | |
| 247 | - 'socialInitialState' => self::get_publicize_initial_state(), | |
| 248 | - 'gutenbergInitialState' => self::get_gutenberg_initial_state(), | |
| 249 | - 'isSubscriptionSiteEnabled' => apply_filters( 'jetpack_subscription_site_enabled', false ), | |
| 250 | - 'subscriptionSiteEditSupported' => $current_theme->is_block_theme() && version_compare( $wp_version, '6.5-beta2', '>=' ), | |
| 251 | 269 | ); |
| 252 | 270 | } |
| 253 | 271 | |
| 254 | 272 | /** |
| 255 | - * Get information about the Gutenberg plugin and its Interactivity API support. | |
| 256 | - * | |
| 257 | - * @see https://make.wordpress.org/core/tag/interactivity-api/ | |
| 258 | - * | |
| 259 | - * @return array | |
| 260 | - */ | |
| 261 | - private static function get_gutenberg_initial_state() { | |
| 262 | - // If Gutenberg is not installed, | |
| 263 | - // check if we run a version of WP that would include support. | |
| 264 | - if ( ! Constants::is_true( 'IS_GUTENBERG_PLUGIN' ) ) { | |
| 265 | - global $wp_version; | |
| 266 | - return array( | |
| 267 | - 'isAvailable' => false, | |
| 268 | - 'hasInteractivityApi' => version_compare( $wp_version, '6.4', '>=' ), | |
| 269 | - ); | |
| 270 | - } | |
| 271 | - | |
| 272 | - // If we're running a dev version, assume it's the latest. | |
| 273 | - if ( Constants::is_true( 'GUTENBERG_DEVELOPMENT_MODE' ) ) { | |
| 274 | - return array( | |
| 275 | - 'isAvailable' => true, | |
| 276 | - 'hasInteractivityApi' => true, | |
| 277 | - ); | |
| 278 | - } | |
| 279 | - | |
| 280 | - $gutenberg_version = Constants::get_constant( 'GUTENBERG_VERSION' ); | |
| 281 | - if ( ! $gutenberg_version ) { | |
| 282 | - return array( | |
| 283 | - 'isAvailable' => false, | |
| 284 | - 'hasInteractivityApi' => false, | |
| 285 | - ); | |
| 286 | - } | |
| 287 | - | |
| 288 | - return array( | |
| 289 | - 'isAvailable' => true, | |
| 290 | - 'hasInteractivityApi' => version_compare( $gutenberg_version, '16.6.0', '>=' ), | |
| 291 | - ); | |
| 292 | - } | |
| 293 | - | |
| 294 | - /** | |
| 295 | - * Gets the initial state for the Publicize module. | |
| 296 | - * | |
| 297 | - * @return array|null | |
| 298 | - */ | |
| 299 | - public static function get_publicize_initial_state() { | |
| 300 | - $jetpack_social_settings = new Automattic\Jetpack\Publicize\Jetpack_Social_Settings\Settings(); | |
| 301 | - $settings = $jetpack_social_settings->get_settings( true ); | |
| 302 | - | |
| 303 | - if ( empty( $settings ) ) { | |
| 304 | - return null; | |
| 305 | - } | |
| 306 | - | |
| 307 | - return $settings; | |
| 308 | - } | |
| 309 | - | |
| 310 | - /** | |
| 311 | 273 | * Gets array of any Jetpack notices that have been dismissed. |
| 312 | 274 | * |
| 313 | 275 | * @return mixed|void |
| 314 | 276 | */ |
| @@ -335,69 +297,33 @@ | ||
| 335 | 297 | } |
| 336 | 298 | |
| 337 | 299 | /** |
| 338 | 300 | * Returns the release post content and image data as an associative array. |
| 339 | - * This data is used to create the update modal. | |
| 301 | + * | |
| 302 | + * The update modal that consumed this data has been removed, so there is nothing to return. | |
| 303 | + * | |
| 304 | + * @deprecated 16.2 | |
| 305 | + * | |
| 306 | + * @return null | |
| 340 | 307 | */ |
| 341 | 308 | public static function get_update_modal_data() { |
| 342 | - $post_data = self::get_release_post_data(); | |
| 343 | - | |
| 344 | - if ( ! isset( $post_data['posts'][0] ) ) { | |
| 345 | - return; | |
| 346 | - } | |
| 347 | - | |
| 348 | - $post = $post_data['posts'][0]; | |
| 349 | - | |
| 350 | - if ( empty( $post['content'] ) ) { | |
| 351 | - return; | |
| 352 | - } | |
| 353 | - | |
| 354 | - // This allows us to embed videopress videos into the release post. | |
| 355 | - add_filter( 'wp_kses_allowed_html', array( __CLASS__, 'allow_post_embed_iframe' ), 10, 2 ); | |
| 356 | - $content = wp_kses_post( $post['content'] ); | |
| 357 | - remove_filter( 'wp_kses_allowed_html', array( __CLASS__, 'allow_post_embed_iframe' ), 10, 2 ); | |
| 358 | - | |
| 359 | - $post_title = isset( $post['title'] ) ? $post['title'] : null; | |
| 360 | - $title = wp_kses( $post_title, array() ); | |
| 361 | - | |
| 362 | - $post_thumbnail = isset( $post['post_thumbnail'] ) ? $post['post_thumbnail'] : null; | |
| 363 | - if ( ! empty( $post_thumbnail ) ) { | |
| 364 | - $photon_image = new Image_CDN_Image( | |
| 365 | - array( | |
| 366 | - 'file' => Image_CDN_Core::cdn_url( $post_thumbnail['URL'] ), | |
| 367 | - 'width' => $post_thumbnail['width'], | |
| 368 | - 'height' => $post_thumbnail['height'], | |
| 369 | - ), | |
| 370 | - $post_thumbnail['mime_type'] | |
| 371 | - ); | |
| 372 | - $photon_image->resize( | |
| 373 | - array( | |
| 374 | - 'width' => 600, | |
| 375 | - 'height' => null, | |
| 376 | - 'crop' => false, | |
| 377 | - ) | |
| 378 | - ); | |
| 379 | - $post_thumbnail_url = $photon_image->get_raw_filename(); | |
| 380 | - } else { | |
| 381 | - $post_thumbnail_url = null; | |
| 382 | - } | |
| 383 | - | |
| 384 | - $post_array = array( | |
| 385 | - 'release_post_content' => $content, | |
| 386 | - 'release_post_featured_image' => $post_thumbnail_url, | |
| 387 | - 'release_post_title' => $title, | |
| 388 | - ); | |
| 389 | - | |
| 390 | - return $post_array; | |
| 309 | + _deprecated_function( __METHOD__, 'jetpack-16.2' ); | |
| 310 | + return null; | |
| 391 | 311 | } |
| 392 | 312 | |
| 393 | 313 | /** |
| 394 | 314 | * Temporarily allow post content to contain iframes, e.g. for videopress. |
| 395 | 315 | * |
| 316 | + * Only ever used while sanitizing the release post for the removed update modal. | |
| 317 | + * | |
| 318 | + * @deprecated 16.2 | |
| 319 | + * | |
| 396 | 320 | * @param string $tags The tags. |
| 397 | 321 | * @param string $context The context. |
| 398 | 322 | */ |
| 399 | 323 | public static function allow_post_embed_iframe( $tags, $context ) { |
| 324 | + _deprecated_function( __METHOD__, 'jetpack-16.2' ); | |
| 325 | + | |
| 400 | 326 | if ( 'post' === $context ) { |
| 401 | 327 | $tags['iframe'] = array( |
| 402 | 328 | 'src' => true, |
| 403 | 329 | 'height' => true, |
| @@ -410,38 +336,20 @@ | ||
| 410 | 336 | return $tags; |
| 411 | 337 | } |
| 412 | 338 | |
| 413 | 339 | /** |
| 414 | - * Obtains the release post from the Jetpack release post blog. A release post will be displayed in the | |
| 415 | - * update modal when a post has a tag equal to the Jetpack version number. | |
| 340 | + * Obtains the release post from the Jetpack release post blog. | |
| 416 | 341 | * |
| 417 | - * The response parameters for the post array can be found here: | |
| 418 | - * https://developer.wordpress.com/docs/api/1.1/get/sites/%24site/posts/%24post_ID/#apidoc-response | |
| 342 | + * The release post blog has had no post tagged for a current Jetpack version since 2023, and the | |
| 343 | + * update modal that consumed this has been removed, so this no longer makes a remote request. | |
| 419 | 344 | * |
| 420 | - * @return array|null Returns an associative array containing the release post data at index ['posts'][0]. | |
| 421 | - * Returns null if the release post data is not available. | |
| 345 | + * @deprecated 16.2 | |
| 346 | + * | |
| 347 | + * @return null | |
| 422 | 348 | */ |
| 423 | 349 | public static function get_release_post_data() { |
| 424 | - if ( Constants::is_defined( 'TESTING_IN_JETPACK' ) && Constants::get_constant( 'TESTING_IN_JETPACK' ) ) { | |
| 425 | - return null; | |
| 426 | - } | |
| 427 | - | |
| 428 | - $release_post_src = add_query_arg( | |
| 429 | - array( | |
| 430 | - 'order_by' => 'date', | |
| 431 | - 'tag' => JETPACK__VERSION, | |
| 432 | - 'number' => '1', | |
| 433 | - ), | |
| 434 | - 'https://public-api.wordpress.com/rest/v1/sites/' . JETPACK__RELEASE_POST_BLOG_SLUG . '/posts' | |
| 435 | - ); | |
| 436 | - | |
| 437 | - $response = wp_remote_get( $release_post_src ); | |
| 438 | - | |
| 439 | - if ( ! is_array( $response ) ) { | |
| 440 | - return null; | |
| 441 | - } | |
| 442 | - | |
| 443 | - return json_decode( wp_remote_retrieve_body( $response ), true ); | |
| 350 | + _deprecated_function( __METHOD__, 'jetpack-16.2' ); | |
| 351 | + return null; | |
| 444 | 352 | } |
| 445 | 353 | |
| 446 | 354 | /** |
| 447 | 355 | * Get external services connect URLs. |
| @@ -447,13 +355,10 @@ | ||
| 447 | 355 | * Get external services connect URLs. |
| 448 | 356 | */ |
| 449 | 357 | public static function get_external_services_connect_urls() { |
| 450 | 358 | $connect_urls = array(); |
| 451 | - require_once JETPACK__PLUGIN_DIR . '_inc/lib/class.jetpack-keyring-service-helper.php'; | |
| 452 | - // phpcs:disable | |
| 453 | - foreach ( Jetpack_Keyring_Service_Helper::SERVICES as $service_name => $service_info ) { | |
| 454 | - // phpcs:enable | |
| 455 | - $connect_urls[ $service_name ] = Jetpack_Keyring_Service_Helper::connect_url( $service_name, $service_info['for'] ); | |
| 359 | + foreach ( Keyring_Helper::SERVICES as $service_name => $service_info ) { | |
| 360 | + $connect_urls[ $service_name ] = Keyring_Helper::connect_url( $service_name, $service_info['for'] ); | |
| 456 | 361 | } |
| 457 | 362 | return $connect_urls; |
| 458 | 363 | } |
| 459 | 364 | |
| @@ -487,8 +392,21 @@ | ||
| 487 | 392 | */ |
| 488 | 393 | public static function generate_purchase_token() { |
| 489 | 394 | return wp_generate_password( 12, false ); |
| 490 | 395 | } |
| 396 | + | |
| 397 | + /** | |
| 398 | + * Get a representative image for the site. | |
| 399 | + * | |
| 400 | + * @since 15.0 | |
| 401 | + * | |
| 402 | + * @return string | |
| 403 | + */ | |
| 404 | + public static function get_site_image(): string { | |
| 405 | + // Get the dynamic image generated for the Open Graph Meta tags. | |
| 406 | + require_once JETPACK__PLUGIN_DIR . 'functions.opengraph.php'; | |
| 407 | + return jetpack_og_get_fallback_social_image( 200, 200 )['src']; | |
| 408 | + } | |
| 491 | 409 | } |
| 492 | 410 | |
| 493 | 411 | // phpcs:disable Universal.Files.SeparateFunctionsFromOO.Mixed -- TODO: Move these functions to some other file. |
| 494 | 412 | |
| @@ -526,11 +444,13 @@ | ||
| 526 | 444 | $current_user_data = array( |
| 527 | 445 | 'isConnected' => $is_user_connected, |
| 528 | 446 | 'isMaster' => $is_master_user, |
| 529 | 447 | 'username' => $current_user->user_login, |
| 448 | + 'displayName' => $current_user->display_name, | |
| 449 | + 'email' => $current_user->user_email, | |
| 530 | 450 | 'id' => $current_user->ID, |
| 531 | 451 | 'wpcomUser' => $dotcom_data, |
| 532 | - 'gravatar' => get_avatar_url( $current_user->ID, 64, 'mm', '', array( 'force_display' => true ) ), | |
| 452 | + 'gravatar' => get_avatar_url( $current_user->ID ), | |
| 533 | 453 | 'permissions' => array( |
| 534 | 454 | 'admin_page' => current_user_can( 'jetpack_admin_page' ), |
| 535 | 455 | 'connect' => current_user_can( 'jetpack_connect' ), |
| 536 | 456 | 'connect_user' => current_user_can( 'jetpack_connect_user' ), |