$deps Registered dependency handles. * @return void */ /** * Register and enqueue the no-JavaScript fallback stylesheet. * * @param string $pluginFile Main plugin file used to build the URL. * @return void */ public static function enqueueNojsLayer( string $pluginFile ): void { self::enqueueStyle( self::NOJS_HANDLE, 'assets/css/admin-nojs.css', $pluginFile, [] ); } /** * Mark the document as JavaScript-capable before the admin body renders. * * The no-JavaScript fallback stylesheet is scoped to `html:not(.rk-js)`. * This tiny head script adds the class as early as possible so the * fallback rules stay inert for every JavaScript-enabled request. When * JavaScript is disabled the class never appears and the fallback rules * reveal panels that would otherwise depend on script-driven toggles. * * Registered as a source-less handle so WordPress prints only the inline * script, in the head, through the supported inline-script API. * * @return void */ public static function enqueueJsFlag(): void { if ( ! function_exists( 'wp_register_script' ) || ! function_exists( 'wp_enqueue_script' ) || ! function_exists( 'wp_add_inline_script' ) ) { return; } $handle = 'rankkernel-js-flag'; wp_register_script( $handle, false, [], Plugin::version(), false ); wp_enqueue_script( $handle ); wp_add_inline_script( $handle, 'document.documentElement.classList.add("rk-js");' ); } /** * Register and enqueue one stylesheet handle. * * @param string $handle Stylesheet handle. * @param string $path Path relative to the plugin root. * @param string $pluginFile Main plugin file used to build the URL. * @param array $deps Registered dependency handles. * @return void */ private static function enqueueStyle( string $handle, string $path, string $pluginFile, array $deps ): void { if ( ! function_exists( 'plugins_url' ) || ! function_exists( 'wp_register_style' ) ) { return; } wp_register_style( $handle, plugins_url( $path, $pluginFile ), $deps, Plugin::version() ); if ( function_exists( 'wp_enqueue_style' ) ) { wp_enqueue_style( $handle ); } if ( self::TOKEN_HANDLE === $handle ) { self::preloadMaterialSymbolsFont( $pluginFile ); } } /** * Emit a preload for the Material Symbols webfont on admin screens. * * The icons are ligature text spans, so without an early fetch every * page paint shows the raw ligature word until the woff2 arrives. The * link is printed from admin_head so it lands ahead of the stylesheets. * * @param string $pluginFile Main plugin file used to build the URL. * @return void */ private static function preloadMaterialSymbolsFont( string $pluginFile ): void { if ( ! function_exists( 'add_action' ) || ! function_exists( 'plugins_url' ) ) { return; } add_action( 'admin_head', static function () use ( $pluginFile ): void { $url = plugins_url( 'assets/fonts/material-symbols-outlined-variable.woff2', $pluginFile ); echo '' . "\n"; } ); } }