Skip to content

Commit

Permalink
Remove/connection nudges where not needed (#39533)
Browse files Browse the repository at this point in the history
* 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@3212e56
  • Loading branch information
CodeyGuyDylan authored and matticbot committed Sep 27, 2024
1 parent c7a1e42 commit 88b3524
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
56 changes: 44 additions & 12 deletions src/class-blaze.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -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,
);
}

/**
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit 88b3524

Please sign in to comment.