*/ protected $gutenberg_bar_assets = []; /** * Initially Invoked * when its initialized. */ public function __construct() { Analytics::get_instance(); BarSpace::get_instance(); // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reviewed for the NotificationX codebase: acceptable in this context. if (!is_admin() || !empty($_GET['frontend'])) { add_action('init', [$this, 'init'], 10); } add_filter('nx_frontend_localize_data', [$this, 'get_localize_data']); Preview::get_instance(); } /** * This method is reponsible for Admin Menu of * NotificationX * * @return void */ public function init() { add_action('wp_enqueue_scripts', [$this, 'enqueue_scripts'], 10); add_filter('nx_fallback_data', [$this, 'fallback_data'], 10, 3); add_filter('nx_filtered_data', [$this, 'filtered_data'], 9999, 3); add_filter('nx_filtered_post', [$this, 'filtered_post'], 9999, 2); add_action('wp_print_footer_scripts', [$this, 'footer_scripts']); // After wp_enqueue_scripts (wp_head priority 1) has collected the page's bars. add_action('wp_head', [$this, 'print_bar_reserve'], 3); add_filter('body_class', [ $this, 'nx_add_body_class' ] ); add_filter('style_loader_tag', [$this, 'non_blocking_style_tag'], 10, 2); } /** * Third-party stylesheets used by the notification themes, keyed by style * handle. * * They used to be CSS `@import`s at the top of frontend.css, which the * browser only discovers once frontend.css has downloaded: a serial, * render-blocking chain to two more origins on every page. They are now * enqueued next to `notificationx-public` and loaded without blocking the * first paint (see non_blocking_style_tag()). * * @since 3.3.3 * @return array Style handle => URL. */ public function get_external_styles() { $styles = []; /** * Filters whether NotificationX loads Open Sans from Google Fonts. * * Return false if the site already loads Open Sans or must not * contact Google Fonts; the themes then fall back to sans-serif. * * @since 3.3.3 * @param bool $load Default true. */ if (apply_filters('notificationx_load_open_sans', true)) { $styles['notificationx-open-sans'] = 'https://fonts.googleapis.com/css2?family=Open+Sans:wght@400;500;600;700&display=swap'; } /** * Filters whether NotificationX loads FontAwesome 4.7 from cdnjs. * * The icons are drawn in pseudo-elements of a few themes only. Return * false if the site already loads FontAwesome 4. * * @since 3.3.3 * @param bool $load Default true. */ if (apply_filters('notificationx_load_fontawesome', true)) { $styles['notificationx-fontawesome-4'] = 'https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css'; } return $styles; } /** * Enqueue the third-party font and icon stylesheets (get_external_styles()). * * Call this wherever `notificationx-public` (or a stylesheet that bundles * the frontend themes) is enqueued. * * @since 3.3.3 * @return void */ public function enqueue_external_styles() { foreach ($this->get_external_styles() as $handle => $src) { // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion -- Third-party URL; a ?ver= query would only split the CDN cache. wp_enqueue_style($handle, $src, [], null); } } /** * Load some stylesheets without blocking the first paint. * * - `notificationx-public` styles only what the runtime renders — bars, * popups and shortcodes all mount from REST data after the page has * loaded (the bar's reserved space is a separate inline style), and the * runtime waits for this sheet before its first render (whenStyled()). * At ~600 KB it was the largest render-blocking stylesheet on every page. * - `notificationx-gdpr-modal` styles only the cookie-preferences modal, * which opens on a click. * - The font and icon stylesheets from get_external_styles(): the fonts * swap in, and the FontAwesome glyphs are drawn only in pseudo-elements * of notifications the runtime renders after the page has loaded. * * The stylesheet is requested as `print` and switched to `all` once it has * loaded; the