| @@ -1,8 +1,8 @@ | ||
| 1 | 1 | <?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName |
| 2 | 2 | /** |
| 3 | 3 | * Module Name: Notifications |
| 4 | - * Module Description: Receive instant notifications of site comments and likes. | |
| 4 | + * Module Description: Receive real‑time notifications about site activity across your devices. | |
| 5 | 5 | * Sort Order: 13 |
| 6 | 6 | * First Introduced: 1.9 |
| 7 | 7 | * Requires Connection: Yes |
| 8 | 8 | * Requires User Connection: Yes |
| @@ -14,9 +14,14 @@ | ||
| 14 | 14 | * @package automattic/jetpack |
| 15 | 15 | */ |
| 16 | 16 | |
| 17 | 17 | use Automattic\Jetpack\Connection\Manager as Connection_Manager; |
| 18 | +use Automattic\Jetpack\Status\Host; | |
| 18 | 19 | |
| 20 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 21 | + exit( 0 ); | |
| 22 | +} | |
| 23 | + | |
| 19 | 24 | if ( ! defined( 'JETPACK_NOTES__CACHE_BUSTER' ) ) { |
| 20 | 25 | define( 'JETPACK_NOTES__CACHE_BUSTER', JETPACK__VERSION . '-' . gmdate( 'oW' ) . '-lite' ); |
| 21 | 26 | } |
| 22 | 27 | |
| @@ -109,9 +114,9 @@ | ||
| 109 | 114 | return; |
| 110 | 115 | } |
| 111 | 116 | $is_rtl = is_rtl(); |
| 112 | 117 | |
| 113 | - if ( Jetpack::is_module_active( 'masterbar' ) ) { | |
| 118 | + if ( ( new Host() )->is_woa_site() ) { | |
| 114 | 119 | /** |
| 115 | 120 | * Can be used to force Notifications to display in RTL style. |
| 116 | 121 | * |
| 117 | 122 | * @module notes |
| @@ -172,9 +177,9 @@ | ||
| 172 | 177 | if ( self::is_block_editor() ) { |
| 173 | 178 | return; |
| 174 | 179 | } |
| 175 | 180 | |
| 176 | - $wpcom_locale = get_locale(); | |
| 181 | + $user_locale = get_user_locale(); | |
| 177 | 182 | |
| 178 | 183 | if ( ! class_exists( 'GP_Locales' ) ) { |
| 179 | 184 | if ( defined( 'JETPACK__GLOTPRESS_LOCALES_PATH' ) && file_exists( JETPACK__GLOTPRESS_LOCALES_PATH ) ) { |
| 180 | 185 | require JETPACK__GLOTPRESS_LOCALES_PATH; |
| @@ -181,11 +186,11 @@ | ||
| 181 | 186 | } |
| 182 | 187 | } |
| 183 | 188 | |
| 184 | 189 | if ( class_exists( 'GP_Locales' ) ) { |
| 185 | - $wpcom_locale_object = GP_Locales::by_field( 'wp_locale', $wpcom_locale ); | |
| 186 | - if ( $wpcom_locale_object instanceof GP_Locale ) { | |
| 187 | - $wpcom_locale = $wpcom_locale_object->slug; | |
| 190 | + $jetpack_locale_object = GP_Locales::by_field( 'slug', $user_locale ); | |
| 191 | + if ( $jetpack_locale_object instanceof GP_Locale ) { | |
| 192 | + $user_locale = $jetpack_locale_object->slug; | |
| 188 | 193 | } |
| 189 | 194 | } |
| 190 | 195 | |
| 191 | 196 | $third_party_cookie_check_iframe = '<span style="display:none;"><iframe class="jetpack-notes-cookie-check" src="https://widgets.wp.com/3rd-party-cookie-check/index.html"></iframe></span>'; |
| @@ -190,18 +195,22 @@ | ||
| 190 | 195 | |
| 191 | 196 | $third_party_cookie_check_iframe = '<span style="display:none;"><iframe class="jetpack-notes-cookie-check" src="https://widgets.wp.com/3rd-party-cookie-check/index.html"></iframe></span>'; |
| 192 | 197 | |
| 193 | 198 | $title = self::get_notes_markup(); |
| 199 | + | |
| 200 | + // The default fallback is `en_US`. Remove underscore if present, noting that lang codes can be more than three chars. | |
| 201 | + $user_locale = strtolower( explode( '_', $user_locale, 2 )[0] ); | |
| 202 | + | |
| 194 | 203 | $wp_admin_bar->add_menu( |
| 195 | 204 | array( |
| 196 | 205 | 'id' => 'notes', |
| 197 | 206 | 'title' => $title, |
| 198 | 207 | 'meta' => array( |
| 199 | - 'html' => '<div id="wpnt-notes-panel2" class="intrinsic-ignore" style="display:none" lang="' . esc_attr( $wpcom_locale ) . '" dir="' . ( is_rtl() ? 'rtl' : 'ltr' ) . '"><div class="wpnt-notes-panel-header"><span class="wpnt-notes-header">' . __( 'Notifications', 'jetpack' ) . '</span><span class="wpnt-notes-panel-link"></span></div></div>' . $third_party_cookie_check_iframe, | |
| 208 | + 'html' => '<div id="wpnt-notes-panel2" class="intrinsic-ignore" style="display:none" lang="' . esc_attr( $user_locale ) . '" dir="' . ( is_rtl() ? 'rtl' : 'ltr' ) . '"><div class="wpnt-notes-panel-header"><span class="wpnt-notes-header">' . __( 'Notifications', 'jetpack' ) . '</span><span class="wpnt-notes-panel-link"></span></div></div>' . $third_party_cookie_check_iframe, | |
| 200 | 209 | 'class' => 'menupop', |
| 201 | 210 | ), |
| 202 | 211 | 'parent' => 'top-secondary', |
| 203 | - 'href' => 'https://wordpress.com/notifications', | |
| 212 | + 'href' => 'https://wordpress.com/reader/notifications', | |
| 204 | 213 | ) |
| 205 | 214 | ); |
| 206 | 215 | } |
| 207 | 216 | |
| @@ -211,9 +220,9 @@ | ||
| 211 | 220 | * @return string |
| 212 | 221 | */ |
| 213 | 222 | private static function get_notes_markup() { |
| 214 | 223 | return '<span id="wpnt-notes-unread-count" class="wpnt-loading wpn-read"></span> |
| 215 | -<span class="noticon noticon-bell"></span> | |
| 224 | +<span class="noticon noticon-bell ab-icon"></span> | |
| 216 | 225 | <span class="screen-reader-text">' . esc_html__( 'Notifications', 'jetpack' ) . '</span>'; |
| 217 | 226 | } |
| 218 | 227 | |
| 219 | 228 | /** |
| @@ -231,23 +240,8 @@ | ||
| 231 | 240 | <?php if ( $link_accounts_url ) : ?> |
| 232 | 241 | var wpNotesLinkAccountsURL = '<?php echo esc_url( $link_accounts_url ); ?>'; |
| 233 | 242 | <?php endif; ?> |
| 234 | 243 | /* ]]> */ |
| 235 | - window.addEventListener('message', function ( event ) { | |
| 236 | - // Confirm that the message is from the right origin. | |
| 237 | - if ('https://widgets.wp.com' !== event.origin) { | |
| 238 | - return; | |
| 239 | - } | |
| 240 | - // Check whether 3rd Party Cookies are blocked | |
| 241 | - var has3PCBlocked = 'WPCOM:3PC:blocked' === event.data; | |
| 242 | - | |
| 243 | - var tagerElement = document.getElementById('wp-admin-bar-notes'); | |
| 244 | - | |
| 245 | - if ( has3PCBlocked && tagerElement ) { | |
| 246 | - // Hide the notification button/icon | |
| 247 | - tagerElement.style.display = 'none'; | |
| 248 | - } | |
| 249 | - }, false ); | |
| 250 | 244 | </script> |
| 251 | 245 | <?php |
| 252 | 246 | } |
| 253 | 247 | |