= 15 ? $interval : 60; return $settings; } } // Frontend optimizations (skipped automatically when ?aio_no_opt=1 Safe Mode is active) if ( ! aio_is_speed_safe_mode() ) { // 3. Disable Emojis if ( ! empty( aio_get_option( 'opt-perf-disable-emoji' ) ) ) { add_action( 'init', 'aio_tools_disable_emojis' ); function aio_tools_disable_emojis() { remove_action( 'wp_head', 'print_emoji_detection_script', 7 ); remove_action( 'admin_print_scripts', 'print_emoji_detection_script' ); remove_action( 'wp_print_styles', 'print_emoji_styles' ); remove_action( 'admin_print_styles', 'print_emoji_styles' ); // WP 6.4+ / WP 7.0 compatibility remove_action( 'embed_head', 'print_emoji_detection_script' ); remove_action( 'wp_enqueue_scripts', 'wp_enqueue_emoji_styles' ); remove_action( 'admin_enqueue_scripts', 'wp_enqueue_emoji_styles' ); remove_action( 'enqueue_embed_scripts', 'wp_enqueue_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( 'tiny_mce_plugins', 'aio_tools_disable_emojis_tinymce' ); add_filter( 'wp_resource_hints', 'aio_tools_disable_emojis_dns_prefetch', 10, 2 ); } function aio_tools_disable_emojis_tinymce( $plugins ) { return is_array( $plugins ) ? array_diff( $plugins, array( 'wpemoji' ) ) : array(); } function aio_tools_disable_emojis_dns_prefetch( $urls, $relation_type ) { if ( 'dns-prefetch' === $relation_type && is_array( $urls ) ) { foreach ( $urls as $key => $url ) { $href = is_array( $url ) && isset( $url['href'] ) ? (string) $url['href'] : (string) $url; if ( false !== strpos( $href, 's.w.org' ) || false !== strpos( $href, 'images/core/emoji' ) ) { unset( $urls[ $key ] ); } } } return $urls; } } // 4. Disable OEmbed Script & Discovery Links if ( ! empty( aio_get_option( 'opt-perf-disable-embed' ) ) ) { add_action( 'init', 'aio_tools_disable_oembed_head', 20 ); add_action( 'wp_footer', 'aio_tools_deregister_scripts' ); function aio_tools_disable_oembed_head() { remove_action( 'wp_head', 'wp_oembed_add_discovery_links' ); remove_action( 'wp_head', 'wp_oembed_add_host_js' ); } function aio_tools_deregister_scripts() { wp_deregister_script( 'wp-embed' ); } } // 5. Disable Frontend Dashicons for Logged-out Visitors (preserves wp-login.php password eye toggle) if ( ! empty( aio_get_option( 'optDisableDashicons' ) ) ) { add_action( 'wp_enqueue_scripts', 'aio_tools_disable_guest_dashicons', 100 ); function aio_tools_disable_guest_dashicons() { if ( is_user_logged_in() ) { return; } $pagenow = isset( $GLOBALS['pagenow'] ) ? $GLOBALS['pagenow'] : ''; if ( $pagenow === 'wp-login.php' ) { return; } wp_dequeue_style( 'dashicons' ); wp_deregister_style( 'dashicons' ); } } // 6. Remove Frontend jQuery Migrate if ( ! empty( aio_get_option( 'optDisableJqueryMigrate' ) ) && ! is_admin() ) { add_action( 'wp_default_scripts', 'aio_tools_remove_jquery_migrate' ); function aio_tools_remove_jquery_migrate( $scripts ) { if ( ! is_admin() && isset( $scripts->registered['jquery'] ) ) { $script = $scripts->registered['jquery']; if ( ! empty( $script->deps ) ) { $script->deps = array_diff( $script->deps, array( 'jquery-migrate' ) ); } } } } // 7. Optional: Disable Gutenberg Block Library CSS on Frontend (for Classic / Elementor / Flatsome sites) if ( ! empty( aio_get_option( 'optDisableBlockCss' ) ) && ! is_admin() ) { add_action( 'wp_enqueue_scripts', 'aio_tools_disable_block_library_css', 100 ); function aio_tools_disable_block_library_css() { wp_dequeue_style( 'wp-block-library' ); wp_dequeue_style( 'wp-block-library-theme' ); wp_dequeue_style( 'wc-blocks-style' ); wp_dequeue_style( 'classic-theme-styles' ); } } // 8. Defer Non-Critical JavaScript (compatible with WP 6.3+ Script Strategy API) if ( ! empty( aio_get_option( 'optEnableDeferJS' ) ) && ! is_admin() ) { add_filter( 'script_loader_tag', 'aio_tools_defer_async_scripts', 10, 3 ); function aio_tools_defer_async_scripts( $tag, $handle, $src ) { if ( is_user_logged_in() || empty( $src ) ) { return $tag; } $exclude_handles = array( 'wp-polyfill', 'wc-checkout', 'wc-cart', 'wc-add-to-cart-variation', ); if ( in_array( $handle, $exclude_handles, true ) ) { return $tag; } // Skip if script already has defer, async, WP strategy attribute, or custom non-JS type if ( preg_match( '/(?:^|\s)(?:defer|async|data-wp-strategy)(?:=|>|\s)/i', $tag ) ) { return $tag; } if ( stripos( $tag, 'challenges.cloudflare.com' ) !== false || stripos( $tag, 'recaptcha' ) !== false ) { return $tag; } return str_replace( ' src=', ' defer src=', $tag ); } } // 9. Remove Query Strings (?ver=) from Static Resources for Guests if ( ! empty( aio_get_option( 'optEnableRemoveQueryString' ) ) && ! is_admin() ) { function aio_tools_remove_query_strings( $src ) { if ( ! is_user_logged_in() && is_string( $src ) && strpos( $src, '?ver=' ) !== false ) { $src = remove_query_arg( 'ver', $src ); } return $src; } add_filter( 'style_loader_src', 'aio_tools_remove_query_strings', 10, 2 ); add_filter( 'script_loader_src', 'aio_tools_remove_query_strings', 10, 2 ); } // 10. Smart WooCommerce Cart Fragments Optimizer (skips ?wc-ajax=get_refreshed_fragments when cart is empty) if ( ! empty( aio_get_option( 'optOptimizeWcFragments' ) ) && class_exists( 'WooCommerce' ) && ! is_admin() ) { add_action( 'wp_enqueue_scripts', 'aio_tools_smart_wc_cart_fragments', 999 ); function aio_tools_smart_wc_cart_fragments() { if ( function_exists( 'is_cart' ) && ( is_cart() || is_checkout() || is_account_page() ) ) { return; } if ( ! empty( $_COOKIE['woocommerce_items_in_cart'] ) ) { return; } if ( wp_script_is( 'wc-cart-fragments', 'enqueued' ) || wp_script_is( 'wc-cart-fragments', 'registered' ) ) { wp_dequeue_script( 'wc-cart-fragments' ); add_action( 'wp_footer', 'aio_tools_wc_fragments_empty_fallback', 99 ); } } function aio_tools_wc_fragments_empty_fallback() { ?>