| @@ -4,10 +4,9 @@ | ||
| 4 | 4 | * |
| 5 | 5 | * @package automattic/jetpack |
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | -use Automattic\Jetpack\Connection\Client; | |
| 9 | -use Automattic\Jetpack\Connection\Manager as Connection_Manager; | |
| 8 | +use Automattic\Jetpack\Current_Plan as Jetpack_Plan; | |
| 10 | 9 | use Automattic\Jetpack\Plugins_Installer; |
| 11 | 10 | use Automattic\Jetpack\Status; |
| 12 | 11 | use Automattic\Jetpack\Status\Host; |
| 13 | 12 | |
| @@ -67,55 +66,15 @@ | ||
| 67 | 66 | * Returns a boolean indicating if the Jetpack Banner is enabled. |
| 68 | 67 | * |
| 69 | 68 | * @since 9.3.0 |
| 70 | 69 | * |
| 70 | + * @deprecated 13.2 | |
| 71 | + * | |
| 71 | 72 | * @return bool |
| 72 | 73 | */ |
| 73 | 74 | public static function is_banner_enabled() { |
| 74 | - // Shortcircuit early if the recommendations are not enabled at all. | |
| 75 | - if ( ! self::is_enabled() ) { | |
| 76 | - return false; | |
| 77 | - } | |
| 78 | - | |
| 79 | - $recommendations_banner_enabled = Jetpack_Options::get_option( 'recommendations_banner_enabled', null ); | |
| 80 | - | |
| 81 | - // If the option is already set, just return the cached value. | |
| 82 | - // Otherwise calculate it and store it before returning it. | |
| 83 | - if ( null !== $recommendations_banner_enabled ) { | |
| 84 | - return $recommendations_banner_enabled; | |
| 85 | - } | |
| 86 | - | |
| 87 | - if ( ! Jetpack::connection()->is_connected() ) { | |
| 88 | - return new WP_Error( 'site_not_connected', esc_html__( 'Site not connected.', 'jetpack' ) ); | |
| 89 | - } | |
| 90 | - | |
| 91 | - $blog_id = Jetpack_Options::get_option( 'id' ); | |
| 92 | - | |
| 93 | - $request_path = sprintf( '/sites/%s/jetpack-recommendations/site-registered-date', $blog_id ); | |
| 94 | - $result = Client::wpcom_json_api_request_as_blog( | |
| 95 | - $request_path, | |
| 96 | - 2, | |
| 97 | - array( | |
| 98 | - 'headers' => array( 'content-type' => 'application/json' ), | |
| 99 | - ), | |
| 100 | - null, | |
| 101 | - 'wpcom' | |
| 102 | - ); | |
| 103 | - | |
| 104 | - $body = json_decode( wp_remote_retrieve_body( $result ) ); | |
| 105 | - if ( 200 === wp_remote_retrieve_response_code( $result ) ) { | |
| 106 | - $site_registered_date = $body->site_registered_date; | |
| 107 | - } else { | |
| 108 | - $connection = new Connection_Manager( 'jetpack' ); | |
| 109 | - $site_registered_date = $connection->get_assumed_site_creation_date(); | |
| 110 | - } | |
| 111 | - | |
| 112 | - $recommendations_start_date = gmdate( 'Y-m-d H:i:s', strtotime( '2020-12-01 00:00:00' ) ); | |
| 113 | - $recommendations_banner_enabled = $site_registered_date > $recommendations_start_date; | |
| 114 | - | |
| 115 | - Jetpack_Options::update_option( 'recommendations_banner_enabled', $recommendations_banner_enabled ); | |
| 116 | - | |
| 117 | - return $recommendations_banner_enabled; | |
| 75 | + _deprecated_function( __METHOD__, 'jetpack-13.2' ); | |
| 76 | + return false; | |
| 118 | 77 | } |
| 119 | 78 | |
| 120 | 79 | /** |
| 121 | 80 | * Set up actions to monitor for things that trigger a recommendation. |
| @@ -128,23 +87,23 @@ | ||
| 128 | 87 | return false; |
| 129 | 88 | } |
| 130 | 89 | |
| 131 | 90 | // Monitor for the publishing of a new post. |
| 132 | - add_action( 'transition_post_status', array( get_called_class(), 'post_transition' ), 10, 3 ); | |
| 133 | - add_action( 'jetpack_activate_module', array( get_called_class(), 'jetpack_module_activated' ), 10, 2 ); | |
| 91 | + add_action( 'transition_post_status', array( static::class, 'post_transition' ), 10, 3 ); | |
| 92 | + add_action( 'jetpack_activate_module', array( static::class, 'jetpack_module_activated' ), 10, 2 ); | |
| 134 | 93 | |
| 135 | 94 | // Monitor for activating a new plugin. |
| 136 | - add_action( 'activated_plugin', array( get_called_class(), 'plugin_activated' ), 10 ); | |
| 95 | + add_action( 'activated_plugin', array( static::class, 'plugin_activated' ), 10 ); | |
| 137 | 96 | |
| 138 | 97 | // Monitor for the addition of a new comment. |
| 139 | - add_action( 'comment_post', array( get_called_class(), 'comment_added' ), 10, 3 ); | |
| 98 | + add_action( 'comment_post', array( static::class, 'comment_added' ), 10, 3 ); | |
| 140 | 99 | |
| 141 | 100 | // Monitor for Jetpack connection success. |
| 142 | - add_action( 'jetpack_authorize_ending_authorized', array( get_called_class(), 'jetpack_connected' ) ); | |
| 143 | - add_action( self::VIDEOPRESS_TIMED_ACTION, array( get_called_class(), 'recommend_videopress' ) ); | |
| 101 | + add_action( 'jetpack_authorize_ending_authorized', array( static::class, 'jetpack_connected' ) ); | |
| 102 | + add_action( self::VIDEOPRESS_TIMED_ACTION, array( static::class, 'recommend_videopress' ) ); | |
| 144 | 103 | |
| 145 | 104 | // Monitor for changes in plugins that have auto-updates enabled |
| 146 | - add_action( 'update_site_option_auto_update_plugins', array( get_called_class(), 'plugin_auto_update_settings_changed' ), 10, 3 ); | |
| 105 | + add_action( 'update_site_option_auto_update_plugins', array( static::class, 'plugin_auto_update_settings_changed' ), 10, 3 ); | |
| 147 | 106 | } |
| 148 | 107 | |
| 149 | 108 | /** |
| 150 | 109 | * Check when Jetpack modules are activated if some recommendations should be skipped. |
| @@ -211,9 +170,9 @@ | ||
| 211 | 170 | 'woocommerce.php', |
| 212 | 171 | ); |
| 213 | 172 | |
| 214 | 173 | $path_parts = explode( '/', $plugin ); |
| 215 | - $plugin_file = $path_parts ? array_pop( $path_parts ) : $plugin; | |
| 174 | + $plugin_file = array_pop( $path_parts ); | |
| 216 | 175 | |
| 217 | 176 | if ( ! in_array( $plugin_file, $plugin_whitelist, true ) ) { |
| 218 | 177 | $products = array_column( Jetpack_Plan::get_products(), 'product_slug' ); |
| 219 | 178 | |
| @@ -279,9 +238,9 @@ | ||
| 279 | 238 | // The site has anti-spam features already. |
| 280 | 239 | $site_products = array_column( Jetpack_Plan::get_products(), 'product_slug' ); |
| 281 | 240 | $has_anti_spam_product = count( array_intersect( array( 'jetpack_anti_spam', 'jetpack_anti_spam_monthly' ), $site_products ) ) > 0; |
| 282 | 241 | |
| 283 | - if ( Jetpack_Plan::supports( 'antispam' ) || $has_anti_spam_product ) { | |
| 242 | + if ( Jetpack_Plan::supports( 'akismet' ) || Jetpack_Plan::supports( 'antispam' ) || $has_anti_spam_product ) { | |
| 284 | 243 | return; |
| 285 | 244 | } |
| 286 | 245 | |
| 287 | 246 | if ( isset( $commentdata['comment_post_ID'] ) ) { |
| @@ -422,9 +381,9 @@ | ||
| 422 | 381 | */ |
| 423 | 382 | public static function get_new_conditional_recommendations() { |
| 424 | 383 | $conditional_recommendations = self::get_conditional_recommendations(); |
| 425 | 384 | $recommendations_data = Jetpack_Options::get_option( 'recommendations_data', array() ); |
| 426 | - $viewed_recommendations = isset( $recommendations_data['viewedRecommendations'] ) ? $recommendations_data['viewedRecommendations'] : array(); | |
| 385 | + $viewed_recommendations = $recommendations_data['viewedRecommendations'] ?? array(); | |
| 427 | 386 | |
| 428 | 387 | // array_diff returns a keyed array - reduce to unique values. |
| 429 | 388 | return array_unique( array_values( array_diff( $conditional_recommendations, $viewed_recommendations ) ) ); |
| 430 | 389 | } |
| @@ -438,9 +397,8 @@ | ||
| 438 | 397 | } |
| 439 | 398 | |
| 440 | 399 | $setup_wizard_status = Jetpack_Options::get_option( 'setup_wizard_status' ); |
| 441 | 400 | if ( 'completed' === $setup_wizard_status ) { |
| 442 | - Jetpack_Options::update_option( 'recommendations_banner_enabled', false ); | |
| 443 | 401 | Jetpack_Options::update_option( 'recommendations_step', 'setup-wizard-completed' ); |
| 444 | 402 | } |
| 445 | 403 | } |
| 446 | 404 | |