',
esc_attr( $handle ),
$href_esc
);
$deferred .= sprintf(
'',
esc_attr( $handle ),
$href_esc
);
return $deferred;
}
public static function defer_handles() {
return (array) apply_filters( 'aieo_perf_defer_css_handles', self::$defer_handles_default );
}
public static function keep_deferred_linked( $inline, $handle ) {
return $inline && ! in_array( (string) $handle, self::defer_handles(), true );
}
public static function preload_lcp_image() {
if ( defined( 'AIEO_ENGINE_DIR' ) ) { return; }
if ( ! function_exists( 'is_product' ) || ! is_product() ) { return; }
if ( ! function_exists( 'wc_get_product' ) ) { return; }
global $post;
if ( ! $post ) { return; }
$product = wc_get_product( $post->ID );
if ( ! $product ) { return; }
$image_id = (int) $product->get_image_id();
if ( ! $image_id ) { return; }
$default_size = has_image_size( 'woocommerce_single' ) ? 'woocommerce_single' : 'medium_large';
$size = apply_filters( 'woocommerce_gallery_image_size', $default_size );
$src = wp_get_attachment_image_src( $image_id, $size );
if ( ! $src || empty( $src[0] ) ) { return; }
$href = $src[0];
$srcset = function_exists( 'wp_get_attachment_image_srcset' )
? wp_get_attachment_image_srcset( $image_id, $size )
: '';
$sizes = function_exists( 'wp_get_attachment_image_sizes' )
? wp_get_attachment_image_sizes( $image_id, $size )
: '';
$wc_gallery_renders = class_exists( 'AIEO_DMM_Product_Display' )
&& 'yes' === get_option( AIEO_DMM_Product_Display::GALLERY_RENDERS_OPTION );
if ( $wc_gallery_renders ) {
$full_size = apply_filters(
'woocommerce_gallery_full_size',
apply_filters( 'woocommerce_product_thumbnails_large_size', 'full' )
);
$full_src = wp_get_attachment_image_src( $image_id, $full_size );
$alt_text = trim( wp_strip_all_tags( (string) get_post_meta( $image_id, '_wp_attachment_image_alt', true ) ) );
$params = apply_filters(
'woocommerce_gallery_image_html_attachment_image_params',
array(
'title' => _wp_specialchars( get_post_field( 'post_title', $image_id ), ENT_QUOTES, 'UTF-8', true ),
'data-caption' => _wp_specialchars( get_post_field( 'post_excerpt', $image_id ), ENT_QUOTES, 'UTF-8', true ),
'data-src' => isset( $full_src[0] ) ? esc_url( $full_src[0] ) : '',
'data-large_image' => isset( $full_src[0] ) ? esc_url( $full_src[0] ) : '',
'data-large_image_width' => isset( $full_src[1] ) ? esc_attr( $full_src[1] ) : '',
'data-large_image_height' => isset( $full_src[2] ) ? esc_attr( $full_src[2] ) : '',
'class' => 'wp-post-image',
'alt' => esc_attr( $alt_text ),
),
$image_id,
$size,
true
);
if ( ! empty( $params['sizes'] ) && is_string( $params['sizes'] ) ) {
$sizes = $params['sizes'];
}
if ( ! empty( $params['srcset'] ) && is_string( $params['srcset'] ) ) {
$srcset = $params['srcset'];
}
}
$attrs = array(
'rel="preload"',
'as="image"',
'fetchpriority="high"',
'href="' . esc_url( $href ) . '"',
);
if ( $srcset ) {
$attrs[] = 'imagesrcset="' . esc_attr( $srcset ) . '"';
}
if ( $sizes ) {
$attrs[] = 'imagesizes="' . esc_attr( $sizes ) . '"';
}
echo '\n";
}
}
AIEO_Perf::init();