jetpack = Jetpack::init();
add_action( 'init', array( $this, 'action_init' ) );
}
/**
* Adds s0.wp.com to a file path.
*
* @param string $file File path.
*
* @return string
*/
public function wpcom_static_url( $file ) {
return 'https://s0.wp.com' . $file;
}
/**
* Init the notifications admin bar.
*
* @return void
*/
public function action_init() {
if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
return;
}
if ( ! has_filter( 'show_admin_bar', '__return_true' ) && ! is_user_logged_in() ) {
return;
}
// Do not show notifications in the Site Editor, which is always in fullscreen mode.
global $pagenow;
// Pre 13.7 pages that still need to be supported if < 13.7 is
// still installed.
$allowed_old_pages = array( 'admin.php', 'themes.php' );
$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
// For Gutenberg > 13.7, the core `site-editor.php` route is used instead
$is_site_editor_page = 'site-editor.php' === $pagenow;
if ( $is_site_editor_page || $is_old_site_editor_page ) {
return;
}
add_action( 'admin_bar_menu', array( $this, 'admin_bar_menu' ), 120 );
add_action( 'wp_head', array( $this, 'styles_and_scripts' ), 120 );
add_action( 'admin_head', array( $this, 'styles_and_scripts' ) );
}
/**
* Enqueues and registers styles/scripts for notifications.
*
* @return void
*/
public function styles_and_scripts() {
if ( self::is_block_editor() ) {
return;
}
$is_rtl = is_rtl();
if ( ( new Host() )->is_woa_site() ) {
/**
* Can be used to force Notifications to display in RTL style.
*
* @module notes
*
* @since 4.8.0
*
* @param bool true Should notifications be displayed in RTL style. Defaults to false.
*/
$is_rtl = apply_filters( 'a8c_wpcom_masterbar_enqueue_rtl_notification_styles', false );
}
if ( ! $is_rtl ) {
wp_enqueue_style( 'wpcom-notes-admin-bar', $this->wpcom_static_url( '/wp-content/mu-plugins/notes/admin-bar-v2.css' ), array( 'admin-bar' ), JETPACK_NOTES__CACHE_BUSTER );
} else {
wp_enqueue_style( 'wpcom-notes-admin-bar', $this->wpcom_static_url( '/wp-content/mu-plugins/notes/rtl/admin-bar-v2-rtl.css' ), array( 'admin-bar' ), JETPACK_NOTES__CACHE_BUSTER );
}
wp_enqueue_style( 'noticons', $this->wpcom_static_url( '/i/noticons/noticons.css' ), array( 'wpcom-notes-admin-bar' ), JETPACK_NOTES__CACHE_BUSTER );
$this->print_js();
$script_handles = array();
wp_register_script( 'wpcom-notes-common', $this->wpcom_static_url( '/wp-content/mu-plugins/notes/notes-common-lite.min.js' ), array(), JETPACK_NOTES__CACHE_BUSTER, true );
$script_handles[] = 'wpcom-notes-common';
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 );
$script_handles[] = 'wpcom-notes-admin-bar';
$wp_notes_args = 'var wpNotesArgs = ' . wp_json_encode( array( 'cacheBuster' => JETPACK_NOTES__CACHE_BUSTER ), JSON_UNESCAPED_SLASHES | JSON_HEX_TAG | JSON_HEX_AMP ) . ';';
wp_add_inline_script( 'wpcom-notes-admin-bar', $wp_notes_args, 'before' );
if ( class_exists( 'Jetpack_AMP_Support' ) && Jetpack_AMP_Support::is_amp_request() ) {
add_filter(
'script_loader_tag',
function ( $tag, $handle ) use ( $script_handles ) {
if ( in_array( $handle, $script_handles, true ) ) {
$tag = preg_replace( '/(?<=