'prefetch', 'eagerness' => in_array( $mode, array( 'conservative', 'moderate', 'eager' ), true ) ? $mode : 'moderate', ); } ); } elseif ( 'off' !== $mode ) { add_action( 'wp_footer', static function () use ( $mode ) { if ( is_user_logged_in() ) { return; } $path = wp_parse_url( home_url( '/' ), PHP_URL_PATH ) ?: '/'; $rules = array( 'prefetch' => array( array( 'source' => 'document', 'where' => array( 'and' => array( array( 'href_matches' => $path . '*' ), array( 'not' => array( 'href_matches' => array( '/wp-*.php', '/wp-admin/*', '/*\\?(.+)', '/cart/*', '/checkout/*', '/my-account/*' ) ) ), array( 'not' => array( 'selector_matches' => 'a[rel~="nofollow"],.no-prefetch,.no-prefetch a' ) ), ), ), 'eagerness' => in_array( $mode, array( 'conservative', 'moderate', 'eager' ), true ) ? $mode : 'moderate', ), ), ); wp_print_inline_script_tag( wp_json_encode( $rules, JSON_UNESCAPED_SLASHES ), array( 'type' => 'speculationrules' ) ); } ); } add_action( 'wp_enqueue_scripts', static function () { $css = ''; if ( Editor::canvas_id() || is_customize_preview() ) { return; // never inside the editor canvas or customizer previews } if ( Options::get( 'view_transitions', true ) ) { $css .= '@media (prefers-reduced-motion:no-preference){@view-transition{navigation:auto}::view-transition-old(root),::view-transition-new(root){animation-duration:.22s}}'; } if ( Options::get( 'smooth_scroll', false ) ) { $css .= '@media (prefers-reduced-motion:no-preference){html{scroll-behavior:smooth}}html{scroll-padding-top:var(--nx-sticky-h,0px)}'; } $pre = (string) Options::get( 'preloader', 'none' ); if ( $css ) { wp_register_style( 'akram-nav', false, array(), AKRAM_VERSION ); wp_enqueue_style( 'akram-nav' ); wp_add_inline_style( 'akram-nav', $css ); } if ( 'none' !== $pre ) { wp_enqueue_style( 'akram-preloader', AKRAM_URL . 'assets/css/preloader.css', array(), AKRAM_VERSION ); // Hides the preloader once the page has loaded (or after 2.5 s at most). wp_enqueue_script( 'akram-preloader', AKRAM_URL . 'assets/js/preloader.js', array(), AKRAM_VERSION, true ); } } ); if ( 'none' !== Options::get( 'preloader', 'none' ) ) { add_action( 'wp_body_open', static function () { if ( Editor::canvas_id() ) { return; } $pre = (string) Options::get( 'preloader', 'none' ); $inner = ''; if ( 'logo' === $pre && get_theme_mod( 'custom_logo' ) ) { $inner = wp_get_attachment_image( (int) get_theme_mod( 'custom_logo' ), 'medium', false, array( 'alt' => '', 'loading' => 'eager', ) ); } echo ''; }, 1 ); } } public static function apply() { if ( Options::get( 'disable_emojis' ) ) { remove_action( 'wp_head', 'print_emoji_detection_script', 7 ); remove_action( 'wp_print_styles', 'print_emoji_styles' ); remove_filter( 'the_content_feed', 'wp_staticize_emoji' ); remove_filter( 'comment_text_rss', 'wp_staticize_emoji' ); remove_filter( 'wp_mail', 'wp_staticize_emoji_for_email' ); add_filter( 'emoji_svg_url', '__return_false' ); } if ( Options::get( 'disable_embeds' ) ) { remove_action( 'wp_head', 'wp_oembed_add_discovery_links' ); remove_action( 'wp_head', 'wp_oembed_add_host_js' ); add_action( 'wp_footer', static function () { wp_dequeue_script( 'wp-embed' ); } ); } if ( Options::get( 'disable_dashicons' ) ) { add_action( 'wp_enqueue_scripts', static function () { if ( ! is_user_logged_in() ) { wp_dequeue_style( 'dashicons' ); } }, 100 ); } if ( ! Options::get( 'jquery_migrate' ) ) { add_action( 'wp_default_scripts', static function ( $scripts ) { if ( ! is_admin() && isset( $scripts->registered['jquery'] ) ) { $scripts->registered['jquery']->deps = array_diff( $scripts->registered['jquery']->deps, array( 'jquery-migrate' ) ); } } ); } } }