| @@ -1,8 +1,8 @@ | ||
| 1 | 1 | <?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName |
| 2 | 2 | /** |
| 3 | 3 | * Module Name: Notifications |
| 4 | - * Module Description: Receive real‑time notifications about site activity across your devices. | |
| 4 | + * Module Description: Receive instant notifications of site comments and likes. | |
| 5 | 5 | * Sort Order: 13 |
| 6 | 6 | * First Introduced: 1.9 |
| 7 | 7 | * Requires Connection: Yes |
| 8 | 8 | * Requires User Connection: Yes |
| @@ -16,12 +16,8 @@ | ||
| 16 | 16 | |
| 17 | 17 | use Automattic\Jetpack\Connection\Manager as Connection_Manager; |
| 18 | 18 | use Automattic\Jetpack\Status\Host; |
| 19 | 19 | |
| 20 | -if ( ! defined( 'ABSPATH' ) ) { | |
| 21 | - exit( 0 ); | |
| 22 | -} | |
| 23 | - | |
| 24 | 20 | if ( ! defined( 'JETPACK_NOTES__CACHE_BUSTER' ) ) { |
| 25 | 21 | define( 'JETPACK_NOTES__CACHE_BUSTER', JETPACK__VERSION . '-' . gmdate( 'oW' ) . '-lite' ); |
| 26 | 22 | } |
| 27 | 23 | |
| @@ -84,8 +80,22 @@ | ||
| 84 | 80 | if ( ! has_filter( 'show_admin_bar', '__return_true' ) && ! is_user_logged_in() ) { |
| 85 | 81 | return; |
| 86 | 82 | } |
| 87 | 83 | |
| 84 | + // Do not show notifications in the Site Editor, which is always in fullscreen mode. | |
| 85 | + global $pagenow; | |
| 86 | + | |
| 87 | + // Pre 13.7 pages that still need to be supported if < 13.7 is | |
| 88 | + // still installed. | |
| 89 | + $allowed_old_pages = array( 'admin.php', 'themes.php' ); | |
| 90 | + $is_old_site_editor_page = in_array( $pagenow, $allowed_old_pages, true ) && isset( $_GET['page'] ) && 'gutenberg-edit-site' === $_GET['page']; // phpcs:ignore WordPress.Security.NonceVerification.Recommended | |
| 91 | + // For Gutenberg > 13.7, the core `site-editor.php` route is used instead | |
| 92 | + $is_site_editor_page = 'site-editor.php' === $pagenow; | |
| 93 | + | |
| 94 | + if ( $is_site_editor_page || $is_old_site_editor_page ) { | |
| 95 | + return; | |
| 96 | + } | |
| 97 | + | |
| 88 | 98 | add_action( 'admin_bar_menu', array( $this, 'admin_bar_menu' ), 120 ); |
| 89 | 99 | add_action( 'wp_head', array( $this, 'styles_and_scripts' ), 120 ); |
| 90 | 100 | add_action( 'admin_head', array( $this, 'styles_and_scripts' ) ); |
| 91 | 101 | } |
| @@ -95,8 +105,11 @@ | ||
| 95 | 105 | * |
| 96 | 106 | * @return void |
| 97 | 107 | */ |
| 98 | 108 | public function styles_and_scripts() { |
| 109 | + if ( self::is_block_editor() ) { | |
| 110 | + return; | |
| 111 | + } | |
| 99 | 112 | $is_rtl = is_rtl(); |
| 100 | 113 | |
| 101 | 114 | if ( ( new Host() )->is_woa_site() ) { |
| 102 | 115 | /** |
| @@ -126,9 +139,9 @@ | ||
| 126 | 139 | $script_handles[] = 'wpcom-notes-common'; |
| 127 | 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 ); |
| 128 | 141 | $script_handles[] = 'wpcom-notes-admin-bar'; |
| 129 | 142 | |
| 130 | - $wp_notes_args = 'var wpNotesArgs = ' . wp_json_encode( array( 'cacheBuster' => JETPACK_NOTES__CACHE_BUSTER ), JSON_UNESCAPED_SLASHES | JSON_HEX_TAG | JSON_HEX_AMP ) . ';'; | |
| 143 | + $wp_notes_args = 'var wpNotesArgs = ' . wp_json_encode( array( 'cacheBuster' => JETPACK_NOTES__CACHE_BUSTER ) ) . ';'; | |
| 131 | 144 | wp_add_inline_script( 'wpcom-notes-admin-bar', $wp_notes_args, 'before' ); |
| 132 | 145 | |
| 133 | 146 | if ( class_exists( 'Jetpack_AMP_Support' ) && Jetpack_AMP_Support::is_amp_request() ) { |
| 134 | 147 | add_filter( |
| @@ -156,8 +169,12 @@ | ||
| 156 | 169 | if ( ! is_object( $wp_admin_bar ) ) { |
| 157 | 170 | return; |
| 158 | 171 | } |
| 159 | 172 | |
| 173 | + if ( self::is_block_editor() ) { | |
| 174 | + return; | |
| 175 | + } | |
| 176 | + | |
| 160 | 177 | $user_locale = get_user_locale(); |
| 161 | 178 | |
| 162 | 179 | if ( ! class_exists( 'GP_Locales' ) ) { |
| 163 | 180 | if ( defined( 'JETPACK__GLOTPRESS_LOCALES_PATH' ) && file_exists( JETPACK__GLOTPRESS_LOCALES_PATH ) ) { |
| @@ -173,27 +190,19 @@ | ||
| 173 | 190 | } |
| 174 | 191 | |
| 175 | 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>'; |
| 176 | 193 | |
| 177 | - // Opt into the v3 notifications panel/iframe via the `notifications=v3` query parameter. | |
| 178 | - $notifications_version = sanitize_key( wp_unslash( $_GET['notifications'] ?? '' ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended | |
| 179 | - $panel_id = 'v3' === $notifications_version ? 'wpnt-notes-panel3' : 'wpnt-notes-panel2'; | |
| 180 | - | |
| 181 | 194 | $title = self::get_notes_markup(); |
| 182 | - | |
| 183 | - // The default fallback is `en_US`. Remove underscore if present, noting that lang codes can be more than three chars. | |
| 184 | - $user_locale = strtolower( explode( '_', $user_locale, 2 )[0] ); | |
| 185 | - | |
| 186 | 195 | $wp_admin_bar->add_menu( |
| 187 | 196 | array( |
| 188 | 197 | 'id' => 'notes', |
| 189 | 198 | 'title' => $title, |
| 190 | 199 | 'meta' => array( |
| 191 | - 'html' => '<div id="' . esc_attr( $panel_id ) . '" 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 | + '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', |
| 195 | - 'href' => 'https://wordpress.com/reader/notifications', | |
| 204 | + 'href' => 'https://wordpress.com/notifications', | |
| 196 | 205 | ) |
| 197 | 206 | ); |
| 198 | 207 | } |
| 199 | 208 | |
| @@ -214,21 +223,19 @@ | ||
| 214 | 223 | * @return void |
| 215 | 224 | */ |
| 216 | 225 | public function print_js() { |
| 217 | 226 | $link_accounts_url = is_user_logged_in() && ! ( new Connection_Manager( 'jetpack' ) )->is_user_connected() ? Jetpack::admin_url() : false; |
| 218 | - $script_contents = <<<'JS' | |
| 219 | -var wpNotesIsJetpackClient = true; | |
| 220 | -var wpNotesIsJetpackClientV2 = true; | |
| 221 | -JS; | |
| 222 | - if ( $link_accounts_url ) { | |
| 223 | - $script_contents .= "\nvar wpNotesLinkAccountsURL = " . wp_json_encode( $link_accounts_url, JSON_UNESCAPED_SLASHES | JSON_HEX_TAG | JSON_HEX_AMP ) . ';'; | |
| 224 | - } | |
| 225 | - wp_print_inline_script_tag( | |
| 226 | - $script_contents, | |
| 227 | - array( | |
| 228 | - 'data-ampdevmode' => true, | |
| 229 | - ) | |
| 230 | - ); | |
| 227 | + ?> | |
| 228 | +<script data-ampdevmode type="text/javascript"> | |
| 229 | +/* <![CDATA[ */ | |
| 230 | + var wpNotesIsJetpackClient = true; | |
| 231 | + var wpNotesIsJetpackClientV2 = true; | |
| 232 | + <?php if ( $link_accounts_url ) : ?> | |
| 233 | + var wpNotesLinkAccountsURL = '<?php echo esc_url( $link_accounts_url ); ?>'; | |
| 234 | +<?php endif; ?> | |
| 235 | +/* ]]> */ | |
| 236 | +</script> | |
| 237 | + <?php | |
| 231 | 238 | } |
| 232 | 239 | |
| 233 | 240 | /** |
| 234 | 241 | * Checks to see if we're in the block editor. |