WC_Email::prevent_lazy_loading_on_attachment
Prevent lazy loading on attachment images in email context by adding skip classes. This is hooked into the wp_get_attachment_image_attributes filter.
Метод класса: WC_Email{}
Хуков нет.
Возвращает
Массив. The modified image attributes array.
Использование
$WC_Email = new WC_Email(); $WC_Email->prevent_lazy_loading_on_attachment( $attributes );
- $attributes(массив) (обязательный)
- The image attributes array.
Код WC_Email::prevent_lazy_loading_on_attachment() WC Email::prevent lazy loading on attachment WC 10.3.4
public function prevent_lazy_loading_on_attachment( $attributes ) {
// Only process if we're currently sending an email.
if ( ! $this->sending ) {
return $attributes;
}
// Skip classes to prevent lazy loading plugins from applying lazy loading.
// These are the most common skip classes used by popular lazy loading plugins.
$skip_classes = array( 'skip-lazy', 'no-lazyload', 'lazyload-disabled', 'no-lazy', 'skip-lazyload' );
// Add skip classes to prevent lazy loading plugins from applying lazy loading.
if ( isset( $attributes['class'] ) ) {
$classes = array_filter( array_map( 'trim', explode( ' ', $attributes['class'] ) ) );
$classes = array_unique( array_merge( $classes, $skip_classes ) );
$attributes['class'] = implode( ' ', $classes );
} else {
// No class attribute exists, add one with skip classes.
$attributes['class'] = implode( ' ', $skip_classes );
}
// Add data-skip-lazy attribute as an additional safeguard.
$attributes['data-skip-lazy'] = 'true';
return $attributes;
}