From 88b3524294ed47c9184cfbf2a85cf68bc72aba72 Mon Sep 17 00:00:00 2001 From: CodeyGuyDylan Date: Fri, 27 Sep 2024 15:29:17 +0000 Subject: [PATCH] Remove/connection nudges where not needed (#39533) * Remove connection nudges for cards that don't need it on dashboard * Ask for user connection on Blaze when not present and remove nudge on Akismet * changelog * Get rid of connection nudge for Search modules * Fix blaze tests Committed via a GitHub action: https://github.com/Automattic/jetpack/actions/runs/11073180334 Upstream-Ref: Automattic/jetpack@3212e569b8f53de5461ca7464f229c00367c1116 --- CHANGELOG.md | 1 + src/class-blaze.php | 56 +++++++++++++++++++++++++++++++++++---------- 2 files changed, 45 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7a27f7b..73ea24b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 This is an alpha version! The changes listed here are not final. ### Changed +- Remove user connection nudges where they aren't needed. Add user connection nudges where needed - Update dependencies. ## [0.22.11] - 2024-09-23 diff --git a/src/class-blaze.php b/src/class-blaze.php index c81836f..d282140 100644 --- a/src/class-blaze.php +++ b/src/class-blaze.php @@ -61,7 +61,7 @@ public static function init() { * @return void */ public static function add_post_links_actions() { - if ( self::should_initialize() ) { + if ( self::should_initialize()['can_init'] ) { add_filter( 'post_row_actions', array( __CLASS__, 'jetpack_blaze_row_action' ), 10, 2 ); add_filter( 'page_row_actions', array( __CLASS__, 'jetpack_blaze_row_action' ), 10, 2 ); } @@ -97,7 +97,7 @@ public static function is_dashboard_enabled() { * @return void */ public static function enable_blaze_menu() { - if ( ! self::should_initialize() ) { + if ( ! self::should_initialize()['can_init'] ) { return; } @@ -195,7 +195,7 @@ public static function site_supports_blaze( $blog_id ) { * Determines if criteria is met to enable Blaze features. * Keep in mind that this makes remote requests, so we want to avoid calling it when unnecessary, like in the frontend. * - * @return bool + * @return array */ public static function should_initialize() { $is_wpcom = defined( 'IS_WPCOM' ) && IS_WPCOM; @@ -204,7 +204,10 @@ public static function should_initialize() { // Only admins should be able to Blaze posts on a site. if ( ! current_user_can( 'manage_options' ) ) { - return false; + return array( + 'can_init' => false, + 'reason' => 'user_not_admin', + ); } // Allow short-circuiting the Blaze initialization via a filter. @@ -216,7 +219,12 @@ public static function should_initialize() { * * @param bool $should_initialize Whether Blaze should be enabled. Default to true. */ - return apply_filters( 'jetpack_blaze_enabled', true ); + $should_init = apply_filters( 'jetpack_blaze_enabled', true ); + + return array( + 'can_init' => $should_init, + 'reason' => $should_init ? null : 'initialization_disabled', + ); } // On self-hosted sites, we must do some additional checks. @@ -227,25 +235,49 @@ public static function should_initialize() { */ if ( is_wp_error( $site_id ) - || ! $connection->is_connected() - || ! $connection->is_user_connected() ) { - return false; + return array( + 'can_init' => false, + 'reason' => 'wp_error', + ); + } + + if ( ! $connection->is_connected() ) { + return array( + 'can_init' => false, + 'reason' => 'site_not_connected', + ); + } + + if ( ! $connection->is_user_connected() ) { + return array( + 'can_init' => false, + 'reason' => 'user_not_connected', + ); } // The whole thing is powered by Sync! if ( ! Sync_Settings::is_sync_enabled() ) { - return false; + return array( + 'can_init' => false, + 'reason' => 'sync_disabled', + ); } } // Check if the site supports Blaze. if ( is_numeric( $site_id ) && ! self::site_supports_blaze( $site_id ) ) { - return false; + return array( + 'can_init' => false, + 'reason' => 'site_not_eligible', + ); } // Final fallback. - return true; + return array( + 'can_init' => true, + 'reason' => null, + ); } /** @@ -368,7 +400,7 @@ public static function enqueue_block_editor_assets() { return; } // Bail if criteria is not met to enable Blaze features. - if ( ! self::should_initialize() ) { + if ( ! self::should_initialize()['can_init'] ) { return; }