$path, ); } } return $config; } /** * Output preconnect and preload hints. * * @return void */ public static function output_preloads() { if ( ! I365_PO_Plugin::is_frontend_context() ) { return; } $settings = I365_PO_Plugin::get_settings(); foreach ( $settings['preconnect_hosts'] as $host ) { $is_cross = ( wp_parse_url( $host, PHP_URL_HOST ) !== wp_parse_url( home_url(), PHP_URL_HOST ) ); $cross = $is_cross ? ' crossorigin' : ''; printf( '%3$s', esc_url( $host ), $cross, "\n" ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped } if ( ! empty( $settings['preload_font'] ) ) { printf( '%s', esc_url( $settings['preload_font'] ), "\n" ); } if ( ! empty( $settings['preload_hero'] ) ) { if ( ! $settings['hero_preload_on_front'] || is_front_page() ) { printf( '%s', esc_url( $settings['preload_hero'] ), "\n" ); } } } /** * Clean REST and oEmbed link tags on the front end. * * @return void */ public static function clean_head_links() { if ( is_admin() ) { return; } $settings = I365_PO_Plugin::get_settings(); if ( $settings['remove_rest_link'] ) { remove_action( 'wp_head', 'rest_output_link_wp_head' ); } if ( $settings['remove_oembed_link'] ) { remove_action( 'wp_head', 'wp_oembed_add_discovery_links' ); } } /** * Mark LCP images as high priority when applicable. * * @param array $attr Attributes. * @param WP_Post $attachment Attachment. * @param string|array $size Size. * * @return array */ public static function lcp_priority( $attr, $attachment, $size ) { if ( ! I365_PO_Plugin::is_frontend_context() ) { return $attr; } if ( empty( $attr['loading'] ) && empty( $attr['fetchpriority'] ) ) { $attr['fetchpriority'] = 'high'; } return $attr; } /** * Disable lazy-loading on front page images for sanity. * * @param bool $default Default value. * @param string $tag Tag name. * * @return bool */ public static function lazy_loading_sanity( $default, $tag ) { if ( ! I365_PO_Plugin::is_frontend_context() ) { return $default; } if ( 'img' === $tag && is_front_page() ) { return false; } return $default; } /** * Enqueue stylesheet with preload metadata to satisfy plugin checks. * * @return void */ public static function enqueue_stylesheet_preload() { if ( ! I365_PO_Plugin::is_frontend_context() ) { return; } $settings = I365_PO_Plugin::get_settings(); if ( empty( $settings['preload_stylesheet'] ) ) { return; } $url = esc_url_raw( $settings['preload_stylesheet'] ); $handle = 'i365-po-preload-style'; wp_enqueue_style( $handle, $url, array(), I365_PO_VERSION ); // Inform WordPress this should be preloaded. wp_style_add_data( $handle, 'preload', true ); } }