| Server IP : 213.186.33.4 / Your IP : 216.73.216.222 Web Server : Apache System : Linux webm005.cluster103.gra.hosting.ovh.net 6.18.39-ovh-vps-grsec-zfs+ #1 SMP PREEMPT_DYNAMIC Tue Jul 21 12:03:15 CEST 2026 x86_64 User : karinebmkh ( 644538) PHP Version : 8.4.22 Disable Function : _dyuweyrj4,_dyuweyrj4r,dl MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /home/karinebmkh/www2/wp-content/themes/thevoux-wp/inc/ |
Upload File : |
<?php
/* Adding Lazyload Class */
function thb_add_lazy_class( $html = '', $new_class ) {
if ('on' === ot_get_option('lazy_load', 'on')) {
$pattern = '/class="([^"]*)"/';
// Class attribute set.
if ( preg_match( $pattern, $html, $matches ) ) {
$predefined_classes = explode( ' ', $matches[1] );
if ( ! in_array( $new_class, $predefined_classes, true ) ) {
$predefined_classes[] = $new_class;
$html = str_replace(
$matches[0],
sprintf( 'class="%s"', implode( ' ', $predefined_classes ) ),
$html
);
}
} else {
$html = preg_replace( '/(\<.+\s)/', sprintf( '$1class="%s" ', $new_class ), $html );
}
}
return $html;
}
/* Filter Images */
function thb_lazy_images_filter( $content ) {
if ('on' === ot_get_option('lazy_load', 'on')) {
if ( is_feed()
|| intval( get_query_var( 'print' ) ) === 1
|| intval( get_query_var( 'printpage' ) ) === 1
|| strpos( $_SERVER['HTTP_USER_AGENT'], 'Opera Mini' ) !== false
) {
return $content;
}
$matches = array();
$resp_replace = 'data-sizes="auto" data-srcset=';
$skip_images_regex = '/class=".*lazyload.*"/';
$placeholder = 'data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==';
preg_match_all( '/<img\s+.*?>/', $content, $matches );
$search = array();
$replace = array();
foreach ( $matches[0] as $img_html ) {
// Don't to the replacement if a skip class is provided and the image has the class.
if ( ! ( preg_match( $skip_images_regex, $img_html ) ) ) {
$replace_html = preg_replace( '/<img(.*?)src=/i', '<img$1src="' . $placeholder . '" data-src=', $img_html );
$replace_html = preg_replace( '/srcset=/i', $resp_replace, $replace_html );
$replace_html = thb_add_lazy_class( $replace_html, 'lazyload' );
array_push( $search, $img_html );
array_push( $replace, $replace_html );
}
} // End foreach().
$content = str_replace( $search, $replace, $content );
}
return $content;
}
/* Change source to low quality */
function thb_lazy_low_quality( $attr, $attachment, $size ) {
if ('on' === ot_get_option('lazy_load', 'on')) {
$placeholder = 'data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==';
// Low Quality Image Placeholders.
if (!is_string($size)) {
return $attr;
}
$name = explode( '-', $size );
if ( 'thevoux' === $name[0] ) {
$name[2] = 'mini';
$size = implode( '-', $name );
$placeholder = wp_get_attachment_image_src( $attachment->ID, $size );
$placeholder = $placeholder[0];
}
// Lazy Sizes.
$attr['data-src'] = $attr['src'];
$attr['data-sizes'] = 'auto';
$attr['src'] = $placeholder;
$attr['class'] .= ' thb-lazyload lazyload';
// Set Src Set.
if ( isset( $attr['srcset'] ) ) {
$attr['data-srcset'] = $attr['srcset'];
unset( $attr['srcset'] );
}
}
return $attr;
}
/* Filters */
if ( !is_admin() ) {
add_filter( 'the_content', 'thb_lazy_images_filter', 200 );
add_filter( 'wp_get_attachment_image_attributes', 'thb_lazy_low_quality', 10, 3 );
}