Skip to content

Commit

Permalink
WPCOM MU: Add admin notice to know about hosting menu (#35930)
Browse files Browse the repository at this point in the history
* WPCOM MU: Add dismissible admin banner for site menu

* changelog

* WPCOM MU: Add helper function for displaying the notice and only show on dashboard

* Hide while loading

* Check for flag enabled & typo fix

---------

Co-authored-by: Gabriel Demichelis <gabrieldemichelis@gmail.com>

Committed via a GitHub action: https://github.com/Automattic/jetpack/actions/runs/8042932843
  • Loading branch information
okmttdhr authored and matticbot committed Feb 26, 2024
1 parent d7841fa commit 9ece40b
Show file tree
Hide file tree
Showing 5 changed files with 135 additions and 19 deletions.
14 changes: 7 additions & 7 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions vendor/automattic/jetpack-mu-wpcom/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.

### Added
- Adds a dismissible admin notice to inform users of the hosting menu
- Add Scheduled Updates package

### Changed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,3 +175,118 @@ function wpcom_add_wpcom_menu_item() {
);
}
add_action( 'admin_menu', 'wpcom_add_wpcom_menu_item' );

/**
* Helper function to determine if the admin notice should be shown.
*
* @return bool
*/
function wpcom_site_menu_should_show_notice() {
if ( ! function_exists( 'wpcom_is_nav_redesign_enabled' ) || ! wpcom_is_nav_redesign_enabled() ) {
return false;
}
if ( get_option( 'wpcom_site_menu_notice_dismissed' ) ) {
return false;
}

$screen = get_current_screen();
return 'dashboard' === $screen->id;
}

/**
* Add a notice to the admin menu to inform users about the new WordPress.com menu item.
*/
function wpcom_add_hosting_menu_intro_notice() {
if ( ! wpcom_site_menu_should_show_notice() || ! function_exists( 'wpcom_is_nav_redesign_enabled' ) || ! wpcom_is_nav_redesign_enabled() ) {
return;
}
?>
<style>

body.no-js .wpcom-site-menu-intro-notice {
display: none !important;
}
.wpcom-site-menu-intro-notice {
display: none !important;
padding: 8px 12px;
}

.wrap > .wpcom-site-menu-intro-notice {
display: flex !important;
}
.wpcom-site-menu-intro-notice.notice.notice-info {
border-left-color: #3858e9;
display: flex;
align-items: center;
gap: 12px;
}

.wpcom-site-menu-intro-notice .dashicons-wordpress-alt {
color: #3858e9;
font-size: 32px;
width: 32px;
height: 32px;
}

.wpcom-site-menu-intro-notice span.title {
font-size: 14px;
font-weight: 600;
}

.wpcom-site-menu-intro-notice span {
color: rgb(29, 35, 39);
font-size: 14px;
}

.wpcom-site-menu-intro-notice a.close-button {
height: 16px;
margin-left: auto;
}
</style>
<div class="wpcom-site-menu-intro-notice notice notice-info" role="alert">
<div class="banner-icon">
<span class="dashicons dashicons-wordpress-alt"></span>
</div>
<div>
<span class="title"><?php esc_html_e( 'WordPress.com', 'jetpack-mu-wpcom' ); ?></span><br />
<span>
<?php esc_html_e( 'To access settings for plans, domains, subscribers, etc., click "Hosting" in the sidebar.', 'jetpack-mu-wpcom' ); ?>
</span>
</div>
<a href="#" class="close-button" aria-label=<?php echo esc_attr__( 'Dismiss', 'jetpack-mu-wpcom' ); ?>>
<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg"><rect x="12.7019" y="2.35547" width="1.53333" height="15.287" rx="0.766667" transform="rotate(45 12.7019 2.35547)" fill="#646970"></rect><rect x="13.6445" y="13.165" width="1.53333" height="15.287" rx="0.766667" transform="rotate(135 13.6445 13.165)" fill="#646970"></rect></svg>
</a>
</div>
<?php
}
add_action( 'admin_notices', 'wpcom_add_hosting_menu_intro_notice' );

/**
* Handles the AJAX request to dismiss the admin notice.
*/
function wpcom_add_hosting_menu_intro_notice_dismiss() {
if ( ! wpcom_site_menu_should_show_notice() ) {
return;
}
?>
<script>
document.addEventListener( 'DOMContentLoaded', function() {
document.querySelector( '.wpcom-site-menu-intro-notice a.close-button' ).addEventListener( 'click', function( event ) {
event.preventDefault();
this.closest( '.wpcom-site-menu-intro-notice' ).remove();
wp.ajax.post( 'dismiss_wpcom_site_menu_intro_notice' );
} );
} );
</script>
<?php
}
add_action( 'admin_footer', 'wpcom_add_hosting_menu_intro_notice_dismiss' );

/**
* Acts as the AJAX callback to set an option for dismissing the admin notice.
*/
function wpcom_site_menu_handle_dismiss_notice() {
update_option( 'wpcom_site_menu_notice_dismissed', 1 );
wp_die();
}
add_action( 'wp_ajax_dismiss_wpcom_site_menu_intro_notice', 'wpcom_site_menu_handle_dismiss_notice' );
12 changes: 6 additions & 6 deletions vendor/composer/installed.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"dist": {
"type": "path",
"url": "/tmp/jetpack-build/Automattic/jetpack-assets",
"reference": "f78a02a2318ff7317994bae0c9ebd0f9c6f89982"
"reference": "6834c4d8a96e2d07ada249406c0f0e8bbbe8bc56"
},
"require": {
"automattic/jetpack-constants": "^2.0.0",
Expand Down Expand Up @@ -76,7 +76,7 @@
"dist": {
"type": "path",
"url": "/tmp/jetpack-build/Automattic/jetpack-constants",
"reference": "eff83abc28e4d98231a9b203c0528de3ba621e4d"
"reference": "692498b92769a4f508261940abd841f08a3ded75"
},
"require": {
"php": ">=7.0"
Expand Down Expand Up @@ -125,12 +125,12 @@
},
{
"name": "automattic/jetpack-mu-wpcom",
"version": "5.14.0-alpha.1708907363",
"version_normalized": "5.14.0.0-alpha1708907363",
"version": "5.14.0-alpha.1708915220",
"version_normalized": "5.14.0.0-alpha1708915220",
"dist": {
"type": "path",
"url": "/tmp/jetpack-build/Automattic/jetpack-mu-wpcom",
"reference": "e0160ce50df7c48cc5e6b3a0e11a8d588ce74db4"
"reference": "ae870b8756d8adbc95a5fc6420d1163925afa616"
},
"require": {
"automattic/jetpack-assets": "^2.1.1",
Expand Down Expand Up @@ -202,7 +202,7 @@
"dist": {
"type": "path",
"url": "/tmp/jetpack-build/Automattic/scheduled-updates",
"reference": "68736def2418570c612c209dfc617e173ec9be59"
"reference": "a2d9e2e32315a5961d4c477e78762fa1591bb788"
},
"require": {
"php": ">=7.0"
Expand Down
12 changes: 6 additions & 6 deletions vendor/composer/installed.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
'automattic/jetpack-assets' => array(
'pretty_version' => '2.1.1',
'version' => '2.1.1.0',
'reference' => 'f78a02a2318ff7317994bae0c9ebd0f9c6f89982',
'reference' => '6834c4d8a96e2d07ada249406c0f0e8bbbe8bc56',
'type' => 'jetpack-library',
'install_path' => __DIR__ . '/../automattic/jetpack-assets',
'aliases' => array(),
Expand All @@ -22,16 +22,16 @@
'automattic/jetpack-constants' => array(
'pretty_version' => '2.0.0',
'version' => '2.0.0.0',
'reference' => 'eff83abc28e4d98231a9b203c0528de3ba621e4d',
'reference' => '692498b92769a4f508261940abd841f08a3ded75',
'type' => 'jetpack-library',
'install_path' => __DIR__ . '/../automattic/jetpack-constants',
'aliases' => array(),
'dev_requirement' => false,
),
'automattic/jetpack-mu-wpcom' => array(
'pretty_version' => '5.14.0-alpha.1708907363',
'version' => '5.14.0.0-alpha1708907363',
'reference' => 'e0160ce50df7c48cc5e6b3a0e11a8d588ce74db4',
'pretty_version' => '5.14.0-alpha.1708915220',
'version' => '5.14.0.0-alpha1708915220',
'reference' => 'ae870b8756d8adbc95a5fc6420d1163925afa616',
'type' => 'jetpack-library',
'install_path' => __DIR__ . '/../automattic/jetpack-mu-wpcom',
'aliases' => array(),
Expand All @@ -49,7 +49,7 @@
'automattic/scheduled-updates' => array(
'pretty_version' => '0.1.0-alpha.1708634064',
'version' => '0.1.0.0-alpha1708634064',
'reference' => '68736def2418570c612c209dfc617e173ec9be59',
'reference' => 'a2d9e2e32315a5961d4c477e78762fa1591bb788',
'type' => 'jetpack-library',
'install_path' => __DIR__ . '/../automattic/scheduled-updates',
'aliases' => array(),
Expand Down

0 comments on commit 9ece40b

Please sign in to comment.