| @@ -14,8 +14,9 @@ | ||
| 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 | |
| 19 | 20 | if ( ! defined( 'JETPACK_NOTES__CACHE_BUSTER' ) ) { |
| 20 | 21 | define( 'JETPACK_NOTES__CACHE_BUSTER', JETPACK__VERSION . '-' . gmdate( 'oW' ) . '-lite' ); |
| 21 | 22 | } |
| @@ -104,11 +105,14 @@ | ||
| 104 | 105 | * |
| 105 | 106 | * @return void |
| 106 | 107 | */ |
| 107 | 108 | public function styles_and_scripts() { |
| 109 | + if ( self::is_block_editor() ) { | |
| 110 | + return; | |
| 111 | + } | |
| 108 | 112 | $is_rtl = is_rtl(); |
| 109 | 113 | |
| 110 | - if ( Jetpack::is_module_active( 'masterbar' ) ) { | |
| 114 | + if ( ( new Host() )->is_woa_site() ) { | |
| 111 | 115 | /** |
| 112 | 116 | * Can be used to force Notifications to display in RTL style. |
| 113 | 117 | * |
| 114 | 118 | * @module notes |
| @@ -135,8 +139,11 @@ | ||
| 135 | 139 | $script_handles[] = 'wpcom-notes-common'; |
| 136 | 140 | wp_enqueue_script( 'wpcom-notes-admin-bar', $this->wpcom_static_url( '/wp-content/mu-plugins/notes/admin-bar-v2.js' ), array( 'wpcom-notes-common' ), JETPACK_NOTES__CACHE_BUSTER, true ); |
| 137 | 141 | $script_handles[] = 'wpcom-notes-admin-bar'; |
| 138 | 142 | |
| 143 | + $wp_notes_args = 'var wpNotesArgs = ' . wp_json_encode( array( 'cacheBuster' => JETPACK_NOTES__CACHE_BUSTER ) ) . ';'; | |
| 144 | + wp_add_inline_script( 'wpcom-notes-admin-bar', $wp_notes_args, 'before' ); | |
| 145 | + | |
| 139 | 146 | if ( class_exists( 'Jetpack_AMP_Support' ) && Jetpack_AMP_Support::is_amp_request() ) { |
| 140 | 147 | add_filter( |
| 141 | 148 | 'script_loader_tag', |
| 142 | 149 | function ( $tag, $handle ) use ( $script_handles ) { |
| @@ -162,10 +169,14 @@ | ||
| 162 | 169 | if ( ! is_object( $wp_admin_bar ) ) { |
| 163 | 170 | return; |
| 164 | 171 | } |
| 165 | 172 | |
| 166 | - $wpcom_locale = get_locale(); | |
| 173 | + if ( self::is_block_editor() ) { | |
| 174 | + return; | |
| 175 | + } | |
| 167 | 176 | |
| 177 | + $user_locale = get_user_locale(); | |
| 178 | + | |
| 168 | 179 | if ( ! class_exists( 'GP_Locales' ) ) { |
| 169 | 180 | if ( defined( 'JETPACK__GLOTPRESS_LOCALES_PATH' ) && file_exists( JETPACK__GLOTPRESS_LOCALES_PATH ) ) { |
| 170 | 181 | require JETPACK__GLOTPRESS_LOCALES_PATH; |
| 171 | 182 | } |
| @@ -171,33 +182,47 @@ | ||
| 171 | 182 | } |
| 172 | 183 | } |
| 173 | 184 | |
| 174 | 185 | if ( class_exists( 'GP_Locales' ) ) { |
| 175 | - $wpcom_locale_object = GP_Locales::by_field( 'wp_locale', $wpcom_locale ); | |
| 176 | - if ( $wpcom_locale_object instanceof GP_Locale ) { | |
| 177 | - $wpcom_locale = $wpcom_locale_object->slug; | |
| 186 | + $jetpack_locale_object = GP_Locales::by_field( 'slug', $user_locale ); | |
| 187 | + if ( $jetpack_locale_object instanceof GP_Locale ) { | |
| 188 | + $user_locale = $jetpack_locale_object->slug; | |
| 178 | 189 | } |
| 179 | 190 | } |
| 180 | 191 | |
| 181 | 192 | $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>'; |
| 182 | 193 | |
| 183 | - $classes = 'wpnt-loading wpn-read'; | |
| 194 | + $title = self::get_notes_markup(); | |
| 195 | + | |
| 196 | + // The default fallback is `en_US`. Remove underscore if present, noting that lang codes can be more than three chars. | |
| 197 | + $user_locale = strtolower( explode( '_', $user_locale, 2 )[0] ); | |
| 198 | + | |
| 184 | 199 | $wp_admin_bar->add_menu( |
| 185 | 200 | array( |
| 186 | 201 | 'id' => 'notes', |
| 187 | - 'title' => '<span id="wpnt-notes-unread-count" class="' . esc_attr( $classes ) . '"> | |
| 188 | - <span class="noticon noticon-notification"></span> | |
| 189 | - </span>', | |
| 202 | + 'title' => $title, | |
| 190 | 203 | 'meta' => array( |
| 191 | - '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, | |
| 204 | + '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, | |
| 192 | 205 | 'class' => 'menupop', |
| 193 | 206 | ), |
| 194 | 207 | 'parent' => 'top-secondary', |
| 208 | + 'href' => 'https://wordpress.com/notifications', | |
| 195 | 209 | ) |
| 196 | 210 | ); |
| 197 | 211 | } |
| 198 | 212 | |
| 199 | 213 | /** |
| 214 | + * Returns the HTML markup for used by notification in top bar | |
| 215 | + * | |
| 216 | + * @return string | |
| 217 | + */ | |
| 218 | + private static function get_notes_markup() { | |
| 219 | + return '<span id="wpnt-notes-unread-count" class="wpnt-loading wpn-read"></span> | |
| 220 | +<span class="noticon noticon-bell ab-icon"></span> | |
| 221 | +<span class="screen-reader-text">' . esc_html__( 'Notifications', 'jetpack' ) . '</span>'; | |
| 222 | + } | |
| 223 | + | |
| 224 | + /** | |
| 200 | 225 | * Echos the Notes JS. |
| 201 | 226 | * |
| 202 | 227 | * @return void |
| 203 | 228 | */ |
| @@ -211,26 +236,23 @@ | ||
| 211 | 236 | <?php if ( $link_accounts_url ) : ?> |
| 212 | 237 | var wpNotesLinkAccountsURL = '<?php echo esc_url( $link_accounts_url ); ?>'; |
| 213 | 238 | <?php endif; ?> |
| 214 | 239 | /* ]]> */ |
| 215 | - window.addEventListener('message', function ( event ) { | |
| 216 | - // Confirm that the message is from the right origin. | |
| 217 | - if ('https://widgets.wp.com' !== event.origin) { | |
| 218 | - return; | |
| 219 | - } | |
| 220 | - // Check whether 3rd Party Cookies are blocked | |
| 221 | - var has3PCBlocked = 'WPCOM:3PC:blocked' === event.data; | |
| 222 | - | |
| 223 | - var tagerElement = document.getElementById('wp-admin-bar-notes'); | |
| 224 | - | |
| 225 | - if ( has3PCBlocked && tagerElement ) { | |
| 226 | - // Hide the notification button/icon | |
| 227 | - tagerElement.style.display = 'none'; | |
| 228 | - } | |
| 229 | - }, false ); | |
| 230 | 240 | </script> |
| 231 | 241 | <?php |
| 232 | 242 | } |
| 233 | 243 | |
| 244 | + /** | |
| 245 | + * Checks to see if we're in the block editor. | |
| 246 | + */ | |
| 247 | + public static function is_block_editor() { | |
| 248 | + if ( function_exists( 'get_current_screen' ) ) { | |
| 249 | + $current_screen = get_current_screen(); | |
| 250 | + if ( ! empty( $current_screen ) && $current_screen->is_block_editor() ) { | |
| 251 | + return true; | |
| 252 | + } | |
| 253 | + } | |
| 254 | + return false; | |
| 255 | + } | |
| 234 | 256 | } |
| 235 | 257 | |
| 236 | 258 | Jetpack_Notifications::init(); |