Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove/connection nudges where not needed #39533

Merged
merged 5 commits into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: changed

Remove user connection nudges where they aren't needed. Add user connection nudges where needed
56 changes: 44 additions & 12 deletions projects/packages/blaze/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
6 changes: 3 additions & 3 deletions projects/packages/blaze/tests/php/test-blaze.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,10 @@ public function test_dashboard_filter_enable() {
* @covers Automattic\Jetpack\Blaze::should_initialize
*/
public function test_filter_overwrites_eligibility() {
$this->assertFalse( Blaze::should_initialize() );
$this->assertFalse( Blaze::should_initialize()['can_init'] );
wp_set_current_user( $this->admin_id );
add_filter( 'jetpack_blaze_enabled', '__return_true' );
$this->assertTrue( Blaze::should_initialize() );
$this->assertTrue( Blaze::should_initialize()['can_init'] );
add_filter( 'jetpack_blaze_enabled', '__return_false' );
}

Expand All @@ -111,7 +111,7 @@ public function test_filter_overwrites_eligibility() {
*/
public function test_editor_not_eligible() {
wp_set_current_user( $this->editor_id );
$this->assertFalse( Blaze::should_initialize() );
$this->assertFalse( Blaze::should_initialize()['can_init'] );
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: changed

Remove user connection nudges where they aren't needed. Add user connection nudges where needed
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ public function add_tools_menu() {
add_menu_page( esc_attr__( 'Tools', 'jetpack-masterbar' ), __( 'Tools', 'jetpack-masterbar' ), 'publish_posts', 'tools.php', null, 'dashicons-admin-tools', 75 );
add_submenu_page( 'tools.php', esc_attr__( 'Marketing', 'jetpack-masterbar' ), __( 'Marketing', 'jetpack-masterbar' ), 'publish_posts', 'https://wordpress.com/marketing/tools/' . $this->domain );

if ( Blaze::should_initialize() ) {
if ( Blaze::should_initialize()['can_init'] ) {
// @phan-suppress-next-line PhanTypeMismatchArgumentProbablyReal -- Core should ideally document null for no-callback arg. https://core.trac.wordpress.org/ticket/52539.
add_submenu_page( 'tools.php', esc_attr__( 'Advertising', 'jetpack-masterbar' ), __( 'Advertising', 'jetpack-masterbar' ), 'manage_options', 'https://wordpress.com/advertising/' . $this->domain, null, 1 );
}
Expand Down
25 changes: 3 additions & 22 deletions projects/plugins/jetpack/_inc/client/at-a-glance/akismet.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ import { getJetpackProductUpsellByFeature, FEATURE_SPAM_AKISMET_PLUS } from 'lib
import { noop } from 'lodash';
import { getProductDescriptionUrl } from 'product-descriptions/utils';
import PropTypes from 'prop-types';
import React, { Component } from 'react';
import { Component } from 'react';
import { connect } from 'react-redux';
import { getAkismetData } from 'state/at-a-glance';
import { hasConnectedOwner, isOfflineMode, connectUser } from 'state/connection';
import { isOfflineMode, connectUser } from 'state/connection';
import { getApiNonce, isAtomicSite } from 'state/initial-state';
import { siteHasFeature } from 'state/site';

Expand All @@ -31,7 +31,6 @@ class DashAkismet extends Component {
.isRequired,
isOfflineMode: PropTypes.bool.isRequired,
upgradeUrl: PropTypes.string.isRequired,
hasConnectedOwner: PropTypes.bool.isRequired,
};

static defaultProps = {
Expand Down Expand Up @@ -133,25 +132,8 @@ class DashAkismet extends Component {
);
};

const getConnectBanner = () => {
return (
<JetpackBanner
callToAction={ __( 'Connect', 'jetpack' ) }
title={ __(
'Connect your WordPress.com account to upgrade and automatically clear spam from comments and forms',
'jetpack'
) }
disableHref="false"
onClick={ this.props.connectUser }
eventFeature="akismet"
path="dashboard"
plan={ getJetpackProductUpsellByFeature( FEATURE_SPAM_AKISMET_PLUS ) }
/>
);
};

const getBanner = () => {
return this.props.hasConnectedOwner ? getAkismetUpgradeBanner() : getConnectBanner();
return getAkismetUpgradeBanner();
};

const getAkismetCounter = () => {
Expand Down Expand Up @@ -270,7 +252,6 @@ export default connect(
isOfflineMode: isOfflineMode( state ),
upgradeUrl: getProductDescriptionUrl( state, 'akismet' ),
nonce: getApiNonce( state ),
hasConnectedOwner: hasConnectedOwner( state ),
hasAntiSpam: siteHasFeature( state, 'antispam' ),
hasAkismet: siteHasFeature( state, 'akismet' ),
};
Expand Down
2 changes: 1 addition & 1 deletion projects/plugins/jetpack/_inc/client/at-a-glance/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import QuerySitePlugins from 'components/data/query-site-plugins';
import { withModuleSettingsFormHelpers } from 'components/module-settings/with-module-settings-form-helpers';
import analytics from 'lib/analytics';
import { chunk, get } from 'lodash';
import React, { Component } from 'react';
import { Component } from 'react';
import { connect } from 'react-redux';
import { isOfflineMode, hasConnectedOwner, getConnectionStatus } from 'state/connection';
import {
Expand Down
26 changes: 3 additions & 23 deletions projects/plugins/jetpack/_inc/client/at-a-glance/protect.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,17 @@ import Button from 'components/button';
import DashItem from 'components/dash-item';
import QueryProtectCount from 'components/data/query-dash-protect';
import PropTypes from 'prop-types';
import React, { Component } from 'react';
import { Component } from 'react';
import { connect } from 'react-redux';
import { getProtectCount } from 'state/at-a-glance';
import { isOfflineMode, hasConnectedOwner, connectUser } from 'state/connection';
import { isOfflineMode, connectUser } from 'state/connection';
import { isModuleAvailable } from 'state/modules';

class DashProtect extends Component {
static propTypes = {
isOfflineMode: PropTypes.bool.isRequired,
protectCount: PropTypes.any.isRequired,
isModuleAvailable: PropTypes.bool.isRequired,
hasConnectedOwner: PropTypes.bool.isRequired,
connectUser: PropTypes.func.isRequired,
};

Expand All @@ -34,11 +33,7 @@ class DashProtect extends Component {
link: getRedirectUrl( 'jetpack-support-protect' ),
};

if (
this.props.getOptionValue( 'protect' ) &&
! this.props.isOfflineMode &&
this.props.hasConnectedOwner
) {
if ( this.props.getOptionValue( 'protect' ) && ! this.props.isOfflineMode ) {
const protectCount = this.props.protectCount;

if ( 'N/A' === protectCount ) {
Expand Down Expand Up @@ -87,25 +82,11 @@ class DashProtect extends Component {
module="protect"
support={ support }
className="jp-dash-item__is-inactive"
noToggle={ ! this.props.hasConnectedOwner }
>
<p className="jp-dash-item__description">
{ this.props.isOfflineMode && __( 'Unavailable in Offline Mode', 'jetpack' ) }

{ ! this.props.isOfflineMode &&
! this.props.hasConnectedOwner &&
createInterpolateElement(
__(
'<Button>Connect your WordPress.com</Button> account to keep your site protected from malicious sign in attempts.',
'jetpack'
),
{
Button: <Button className="jp-link-button" onClick={ this.connect } />,
}
) }

{ ! this.props.isOfflineMode &&
this.props.hasConnectedOwner &&
createInterpolateElement(
__(
'<Button>Activate Protect</Button> to keep your site protected from malicious sign in attempts.',
Expand Down Expand Up @@ -137,7 +118,6 @@ export default connect(
protectCount: getProtectCount( state ),
isOfflineMode: isOfflineMode( state ),
isModuleAvailable: isModuleAvailable( state, 'protect' ),
hasConnectedOwner: hasConnectedOwner( state ),
} ),
dispatch => ( {
connectUser: () => {
Expand Down
4 changes: 1 addition & 3 deletions projects/plugins/jetpack/_inc/client/at-a-glance/scan.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -379,11 +379,9 @@ class DashScan extends Component {
}

getUpgradeContent() {
const { hasConnectedOwner } = this.props;

return renderCard( {
className: 'jp-dash-item__is-inactive',
overrideContent: hasConnectedOwner ? this.getUpgradeBanner() : this.getConnectBanner(),
overrideContent: this.getUpgradeBanner(),
} );
}

Expand Down
15 changes: 1 addition & 14 deletions projects/plugins/jetpack/_inc/client/at-a-glance/search.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ class DashSearch extends Component {
className: 'jp-dash-item__is-inactive',
status: 'no-pro-uninstalled-or-inactive',
pro_inactive: true,
overrideContent: this.props.hasConnectedOwner ? (
overrideContent: (
<JetpackBanner
callToAction={
isSearchNewPricingLaunched202208()
Expand All @@ -135,19 +135,6 @@ class DashSearch extends Component {
icon="search"
trackBannerDisplay={ this.props.trackUpgradeButtonView }
/>
) : (
<JetpackBanner
callToAction={ __( 'Connect', 'jetpack' ) }
title={ __(
'Connect your WordPress.com account to upgrade and get Jetpack Search, which helps your visitors instantly find the right content – right when they need it.',
'jetpack'
) }
disableHref="false"
onClick={ this.props.connectUser }
eventFeature="search"
path="dashboard"
plan={ getJetpackProductUpsellByFeature( FEATURE_SEARCH_JETPACK ) }
/>
),
} );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ export const SettingsCard = inprops => {
return '';
}

return props.hasConnectedOwner ? (
return (
<JetpackBanner
callToAction={
isSearchNewPricingLaunched202208()
Expand All @@ -274,26 +274,14 @@ export const SettingsCard = inprops => {
href={ props.searchUpgradeUrl }
rna
/>
) : (
<JetpackBanner
callToAction={ connectLabel() }
title={ __(
'Connect your WordPress.com account to upgrade and help visitors quickly find answers with highly relevant instant search results and powerful filtering.',
'jetpack'
) }
plan={ getJetpackProductUpsellByFeature( FEATURE_SEARCH_JETPACK ) }
feature={ feature }
onClick={ handleConnectClick( feature ) }
rna
/>
);

case FEATURE_SPAM_AKISMET_PLUS:
if ( props.isCheckingAkismetKey || props.isAkismetKeyValid || props.hasAntispam ) {
return '';
}

return props.hasConnectedOwner ? (
return (
<JetpackBanner
callToAction={ upgradeLabel() }
title={ __( 'Automatically clear spam from comments and forms.', 'jetpack' ) }
Expand All @@ -302,18 +290,6 @@ export const SettingsCard = inprops => {
href={ props.spamUpgradeUrl }
rna
/>
) : (
<JetpackBanner
callToAction={ connectLabel() }
title={ __(
'Connect your WordPress.com account to upgrade and automatically clear spam from comments and forms.',
'jetpack'
) }
plan={ getJetpackProductUpsellByFeature( FEATURE_SPAM_AKISMET_PLUS ) }
feature={ feature }
onclick={ props.doConnectUser }
rna
/>
);

case FEATURE_SIMPLE_PAYMENTS_JETPACK:
Expand Down
2 changes: 1 addition & 1 deletion projects/plugins/jetpack/_inc/client/security/antispam.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import TextInput from 'components/text-input';
import analytics from 'lib/analytics';
import { FEATURE_SPAM_AKISMET_PLUS } from 'lib/plans/constants';
import { assign, debounce, isEmpty, trim } from 'lodash';
import React, { Component } from 'react';
import { Component } from 'react';
import { connect } from 'react-redux';
import { isAkismetKeyValid, checkAkismetKey, isCheckingAkismetKey } from 'state/at-a-glance';

Expand Down
Loading
Loading