PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 14.2
Jetpack – WP Security, Backup, Speed, & Growth v14.2
16.2-beta 12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 13.7.2 13.8.3 13.9.2 14.0.1 14.1.1 14.2.2 14.3.1 All 501 releases
← All changes | modules/notes.php +44 -25 12.6.414.2 View file →
@@ -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,43 @@
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();
184 195 $wp_admin_bar->add_menu(
185 196 array(
186 197 'id' => 'notes',
187 - 'title' => '<span id="wpnt-notes-unread-count" class="' . esc_attr( $classes ) . '">
188 - <span class="noticon noticon-notification"></span>
189 - </span>',
198 + 'title' => $title,
190 199 '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,
200 + 'html' => '<div id="wpnt-notes-panel2" class="intrinsic-ignore" style="display:none" lang="' . esc_attr( strtolower( substr( $user_locale, 0, 2 ) ) ) . '" 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 201 'class' => 'menupop',
193 202 ),
194 203 'parent' => 'top-secondary',
204 + 'href' => 'https://wordpress.com/notifications',
195 205 )
196 206 );
197 207 }
198 208
199 209 /**
210 + * Returns the HTML markup for used by notification in top bar
211 + *
212 + * @return string
213 + */
214 + private static function get_notes_markup() {
215 + return '<span id="wpnt-notes-unread-count" class="wpnt-loading wpn-read"></span>
216 +<span class="noticon noticon-bell ab-icon"></span>
217 +<span class="screen-reader-text">' . esc_html__( 'Notifications', 'jetpack' ) . '</span>';
218 + }
219 +
220 + /**
200 221 * Echos the Notes JS.
201 222 *
202 223 * @return void
203 224 */
@@ -211,25 +232,23 @@
211 232 <?php if ( $link_accounts_url ) : ?>
212 233 var wpNotesLinkAccountsURL = '<?php echo esc_url( $link_accounts_url ); ?>';
213 234 <?php endif; ?>
214 235 /* ]]> */
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;
236 +</script>
237 + <?php
238 + }
222 239
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';
240 + /**
241 + * Checks to see if we're in the block editor.
242 + */
243 + public static function is_block_editor() {
244 + if ( function_exists( 'get_current_screen' ) ) {
245 + $current_screen = get_current_screen();
246 + if ( ! empty( $current_screen ) && $current_screen->is_block_editor() ) {
247 + return true;
248 + }
228 249 }
229 - }, false );
230 -</script>
231 - <?php
250 + return false;
232 251 }
233 252 }
234 253
235 254 Jetpack_Notifications::init();