Advertisement
arie_cristianD

get_original_image_in_sliders

Oct 5th, 2023
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.19 KB | None | 0 0
  1. add_action(
  2.     'wp_loaded',
  3.     function () {
  4.         remove_filter( 'jnews_single_image_lazy_owl', array( JNews\Image\ImageLazyLoad::getInstance(), 'owl_lazy_single_image' ), null, 2 );
  5.         remove_filter( 'jnews_single_image_lazy_owl', array( JNews\Image\ImageBackgroundLoad::getInstance(), 'owl_lazy_single_image' ), null, 2 );
  6.         remove_filter( 'jnews_single_image_lazy_owl', array( JNews\Image\ImageNormalLoad::getInstance(), 'owl_lazy_single_image' ), null, 2 );
  7.         $mechanism = get_theme_mod( 'jnews_image_load', 'lazyload' );
  8.  
  9.         if ( $mechanism === 'lazyload' ) {
  10.             add_filter( 'jnews_single_image_lazy_owl', 'lazy_original_image', null, 2 );
  11.         } elseif ( $mechanism === 'background' ) {
  12.             add_filter( 'jnews_single_image_lazy_owl', 'normal_original_image', null, 2 );
  13.         } else {
  14.             add_filter( 'jnews_single_image_lazy_owl', 'background_original_image', null, 2 );
  15.         }
  16.     },
  17.     99
  18. );
  19.  
  20.  
  21. function lazy_original_image( $id, $size ) {
  22.     $image_size = JNews\Image\Image::getInstance()->get_image_size( $size );
  23.     $size       = 'full';
  24.     add_filter( 'wp_get_attachment_image_attributes', array( JNews\Image\ImageLazyLoad::getInstance(), 'owl_lazy_attr' ), 10, 2 );
  25.  
  26.     $thumbnail  = "<div class=\"thumbnail-container size-{$image_size['dimension']} \">";
  27.     $thumbnail .= wp_get_attachment_image( $id, $size );
  28.     $thumbnail .= '</div>';
  29.  
  30.     jnews_remove_filters( 'wp_get_attachment_image_attributes', array( JNews\Image\ImageLazyLoad::getInstance(), 'owl_lazy_attr' ), 10 );
  31.  
  32.     return $thumbnail;
  33. }
  34.  
  35. function normal_original_image( $id, $size ) {
  36.     add_filter( 'wp_lazy_loading_enabled', '__return_false' );
  37.     add_filter( 'wp_get_attachment_image_attributes', array( JNews\Image\ImageNormalLoad::getInstance(), 'normal_load_image' ), 10, 2 );
  38.  
  39.     $image_size = JNews\Image\Image::getInstance()->get_image_size( $size );
  40.     $size       = 'full';
  41.     $thumbnail  = "<div class=\"thumbnail-container size-{$image_size['dimension']} \">";
  42.     $thumbnail .= wp_get_attachment_image( $id, $size );
  43.     $thumbnail .= '</div>';
  44.  
  45.     jnews_remove_filters( 'wp_get_attachment_image_attributes', array( JNews\Image\ImageNormalLoad::getInstance(), 'normal_load_image' ), 10 );
  46.     jnews_remove_filters( 'wp_lazy_loading_enabled', '__return_false' );
  47.  
  48.     return $thumbnail;
  49. }
  50.  
  51. function background_original_image( $id, $size ) {
  52.         $image           = get_post( $id );
  53.         $image_size      = wp_get_attachment_metadata( $id );
  54.         $image_dimension = JNews\Image\Image::getInstance()->get_image_size( $size );
  55.         $size            = 'full';
  56.         $image_url       = JNews\Image\ImageBackgroundLoad::getInstance()->get_image_url( $id, $size );
  57.     if ( ! is_array( $image_size ) ) {
  58.         $image_size = array(
  59.             'width'  => '',
  60.             'height' => '',
  61.         );
  62.     }
  63.     $alt           = JNews\Image\ImageBackgroundLoad::getInstance()->alt_text( $id );
  64.     $expand_range  = 700;
  65.         $thumbnail = "<div class=\"thumbnail-container animate-lazy thumbnail-background size-{$image_dimension['dimension']}\">
  66.                        <div class=\"lazyload\" {$alt} data-bgset=\"{$image_url}\" data-expand='{$expand_range}' data-full-width=\"{$image_size['width']}\" data-full-height=\"{$image_size['height']}\" alt=\"{$image->post_excerpt}\"></div>
  67.                      </div>";
  68.  
  69.         return $thumbnail;
  70. }
  71.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement