Skip to content

Commit

Permalink
Masterbar: Remove feature inclusion on Jetpack self-hosted sites (#38804
Browse files Browse the repository at this point in the history
)
  • Loading branch information
coder-karen authored and gogdzl committed Oct 25, 2024
1 parent fb90c0d commit 9cfb5b6
Show file tree
Hide file tree
Showing 8 changed files with 112 additions and 85 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -193,12 +193,19 @@ class JetpackNotices extends React.Component {
'jetpack_deprecate_dismissed[jetpack-ga-admin-removal-notice]'
) &&
'1' === cookieParsed[ 'jetpack_deprecate_dismissed[jetpack-ga-admin-removal-notice]' ],
isMasterbarNoticeDismissed:
cookieParsed &&
cookieParsed.hasOwnProperty(
'jetpack_deprecate_dismissed[jetpack-masterbar-admin-removal-notice]'
) &&
'1' ===
cookieParsed[ 'jetpack_deprecate_dismissed[jetpack-masterbar-admin-removal-notice]' ],
};

this.dismissGoogleAnalyticsNotice = this.dismissGoogleAnalyticsNotice.bind( this );
}

dismissGoogleAnalyticsNotice() {
dismissGoogleAnalyticsNotice = () => {
this.setState( { isGoogleAnalyticsNoticeDismissed: true } );

document.cookie = cookie.serialize(
'jetpack_deprecate_dismissed[jetpack-ga-admin-removal-notice]',
'1',
Expand All @@ -208,8 +215,21 @@ class JetpackNotices extends React.Component {
SameSite: 'None',
}
);
this.setState( { isGoogleAnalyticsNoticeDismissed: true } );
}
};

dismissMasterbarNotice = () => {
this.setState( { isMasterbarNoticeDismissed: true } );

document.cookie = cookie.serialize(
'jetpack_deprecate_dismissed[jetpack-masterbar-admin-removal-notice]',
'1',
{
path: '/',
maxAge: 365 * 24 * 60 * 60,
SameSite: 'None',
}
);
};

render() {
const siteDataErrors = this.props.siteDataErrors.filter( error =>
Expand All @@ -220,6 +240,9 @@ class JetpackNotices extends React.Component {
const showGoogleAnalyticsNotice =
this.props.showGoogleAnalyticsNotice && ! this.state.isGoogleAnalyticsNoticeDismissed;

const showMasterbarNotice =
this.props.showMasterbarNotice && ! this.state.isMasterbarNoticeDismissed;

return (
<div aria-live="polite">
<NoticesList />
Expand Down Expand Up @@ -292,6 +315,23 @@ class JetpackNotices extends React.Component {
</ExternalLink>
</SimpleNotice>
) }
{ showMasterbarNotice && (
<SimpleNotice
status="is-warning"
dismissText={ __( 'Dismiss', 'jetpack' ) }
onDismissClick={ this.dismissMasterbarNotice }
>
<div>
{ __( "Jetpack's WordPress.com Toolbar feature has been removed.", 'jetpack' ) }
</div>
<ExternalLink href={ getRedirectUrl( 'jetpack-support-masterbar' ) }>
{ __(
'To find out more about what this means for you, please refer to this document',
'jetpack'
) }
</ExternalLink>
</SimpleNotice>
) }
</div>
);
}
Expand Down Expand Up @@ -330,6 +370,7 @@ export default connect(
state,
'jetpack-legacy-google-analytics/jetpack-legacy-google-analytics.php'
),
showMasterbarNotice: window.Initial_State?.isMasterbarActive && ! isWoASite( state ),
};
},
dispatch => {
Expand Down
4 changes: 0 additions & 4 deletions projects/plugins/jetpack/_inc/client/writing/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import { isModuleFound } from 'state/search';
import { getSettings } from 'state/settings';
import Composing from './composing';
import CustomContentTypes from './custom-content-types';
import { Masterbar } from './masterbar';
import PostByEmail from './post-by-email';
import ThemeEnhancements from './theme-enhancements';
import Widgets from './widgets';
Expand Down Expand Up @@ -92,9 +91,6 @@ export class Writing extends React.Component {
userCanManageModules={ this.props.userCanManageModules }
/>
) }
{ this.props.isModuleFound( 'masterbar' ) && ! this.props.masterbarIsAlwaysActive && (
<Masterbar connectUrl={ this.props.connectUrl } { ...commonProps } />
) }
{ ! showComposing && ! showPostByEmail && (
<Card>
{ __(
Expand Down
65 changes: 0 additions & 65 deletions projects/plugins/jetpack/_inc/client/writing/masterbar.jsx

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ public static function get_initial_state() {
'newsletterDateExample' => gmdate( get_option( 'date_format' ), time() ),
'subscriptionSiteEditSupported' => $current_theme->is_block_theme(),
'isGoogleAnalyticsActive' => ( new Modules() )->is_active( 'google-analytics', false ),
'isMasterbarActive' => ( new Modules() )->is_active( 'masterbar', false ),
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
* @since 9.1.0
*/

use Automattic\Jetpack\Status\Host;

/**
* Class WPCOM_REST_API_V2_Endpoint_Admin_Menu
*/
Expand Down Expand Up @@ -85,9 +83,6 @@ public function get_item_permissions_check( $request ) { // phpcs:ignore Generic
* @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
*/
public function get_item( $request ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter, VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
if ( ! ( new Host() )->is_wpcom_platform() && get_option( 'wpcom_admin_interface' ) !== 'wp-admin' ) {
require_once JETPACK__PLUGIN_DIR . 'jetpack_vendor/automattic/jetpack-masterbar/src/admin-menu/load.php';
}

// All globals need to be declared for menu items to properly register.
global $admin_page_hooks, $menu, $menu_order, $submenu, $_wp_menu_nopriv, $_wp_submenu_nopriv; // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
Expand Down Expand Up @@ -119,7 +114,9 @@ private function hide_customizer_menu_on_block_theme() {

remove_action( 'customize_register', array( 'Jetpack_Fonts_Typekit', 'maybe_override_for_advanced_mode' ), 20 );

remove_action( 'customize_register', 'Automattic\Jetpack\Masterbar\register_css_nudge_control' );
if ( class_exists( 'Automattic\Jetpack\Masterbar' ) ) {
remove_action( 'customize_register', 'Automattic\Jetpack\Masterbar\register_css_nudge_control' );
}

remove_action( 'customize_register', array( 'Jetpack_Custom_CSS_Enhancements', 'customize_register' ) );
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: compat

WordPress.com Toolbar: Removed feature from Jetpack self-hosted sites.
11 changes: 8 additions & 3 deletions projects/plugins/jetpack/modules/masterbar.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
* @package automattic/jetpack
*/

use Automattic\Jetpack\Masterbar\Main as Jetpack_Masterbar;

Jetpack_Masterbar::init();
/**
* Remove Masterbar from the old Module list.
* Available at wp-admin/admin.php?page=jetpack_modules
* We only need this function and module file until the Masterbar is fully removed from Jetpack including notices).
*
* @param array $items Array of Jetpack modules.
* @return array
*/
52 changes: 50 additions & 2 deletions projects/plugins/jetpack/src/class-deprecate.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ private function __construct() {
add_action( 'admin_notices', array( $this, 'render_admin_notices' ) );
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_scripts' ) );
add_filter( 'my_jetpack_red_bubble_notification_slugs', array( $this, 'add_my_jetpack_red_bubbles' ) );
add_filter( 'jetpack_modules_list_table_items', array( $this, 'remove_masterbar_module_list' ) );
}

/**
Expand Down Expand Up @@ -70,7 +71,7 @@ public function enqueue_admin_scripts() {
}

/**
* Render Google Analytics deprecation notice.
* Render deprecation notices for relevant features.
*
* @return void
*/
Expand All @@ -84,6 +85,15 @@ public function render_admin_notices() {
. ' <a href="' . $support_url . '" target="_blank">' . esc_html__( 'To keep tracking visits and more information on this change, please refer to this document', 'jetpack' ) . '</a>.'
);
}
if ( $this->show_masterbar_notice() ) {
$support_url = Redirect::get_url( 'jetpack-support-masterbar' );

$this->render_notice(
'jetpack-masterbar-admin-removal-notice',
esc_html__( "Jetpack's WordPress.com Toolbar feature has been removed.", 'jetpack' )
. ' <a href="' . $support_url . '" target="_blank">' . esc_html__( 'To find out more about what this means for you, please refer to this document', 'jetpack' ) . '</a>.'
);
}
}

/**
Expand All @@ -106,6 +116,18 @@ public function add_my_jetpack_red_bubbles( $slugs ) {
),
);
}
if ( $this->show_masterbar_notice() ) {
$slugs['jetpack-masterbar-deprecate-feature'] = array(
'data' => array(
'text' => __( "Jetpack's WordPress.com Toolbar feature has been removed.", 'jetpack' ),
'link' => array(
'label' => esc_html__( 'See documentation', 'jetpack' ),
'url' => Redirect::get_url( 'jetpack-support-masterbar' ),
),
'id' => 'jetpack-masterbar-admin-removal-notice',
),
);
}

return $slugs;
}
Expand Down Expand Up @@ -151,7 +173,7 @@ private function render_notice( $id, $text, $params = array() ) {
* @return bool
*/
private function has_notices() {
return $this->show_ga_notice();
return ( $this->show_ga_notice() || $this->show_masterbar_notice() );
}

/**
Expand All @@ -165,4 +187,30 @@ private function show_ga_notice() {
&& ! ( new Host() )->is_woa_site()
&& empty( $_COOKIE['jetpack_deprecate_dismissed']['jetpack-ga-admin-removal-notice'] );
}

/**
* Check if Masterbar notice should show up.
*
* @return bool
*/
private function show_masterbar_notice() {
return ( new Modules() )->is_active( 'masterbar', false )
&& ! ( new Host() )->is_woa_site()
&& empty( $_COOKIE['jetpack_deprecate_dismissed']['jetpack-masterbar-admin-removal-notice'] );
}

/**
* Remove Masterbar from the old Module list.
* Available at wp-admin/admin.php?page=jetpack_modules
* We only need this function until the Masterbar is fully removed from Jetpack (including notices).
*
* @param array $items Array of Jetpack modules.
* @return array
*/
public function remove_masterbar_module_list( $items ) {
if ( isset( $items['masterbar'] ) && get_option( 'wpcom_admin_interface' ) !== 'wp-admin' ) {
unset( $items['masterbar'] );
}
return $items;
}
}

0 comments on commit 9cfb5b6

Please sign in to comment.