env()->is_front) // if is front.
{
$this->initWebpHooks();
}
}
protected function initWebpHooks()
{
$webp_option = \wpSPIO()->settings()->deliverWebp;
if ( $webp_option ) { // @tood Replace this function with the one in ENV.
if(UtilHelper::shortPixelIsPluginActive('shortpixel-adaptive-images/short-pixel-ai.php')) {
Notices::addWarning(__('Please deactivate the ShortPixel Image Optimizer\'s
Deliver the next generation versions of the images in the front-end
option when the ShortPixel Adaptive Images plugin is active.','shortpixel-image-optimiser'), true);
}
elseif( $webp_option == self::WEBP_GLOBAL ){
//add_action( 'wp_head', array($this, 'addPictureJs') ); // adds polyfill JS to the header || Removed. Browsers without picture support?
add_action( 'init', array($this, 'startOutputBuffer'), 1 ); // start output buffer to capture content
} elseif ($webp_option == self::WEBP_WP){
add_filter( 'the_content', array($this, 'convertImgToPictureAddWebp'), 10000 ); // priority big, so it will be executed last
add_filter( 'the_excerpt', array($this, 'convertImgToPictureAddWebp'), 10000 );
add_filter( 'post_thumbnail_html', array($this,'convertImgToPictureAddWebp') );
}
}
}
/* Picture generation, hooked on the_content filter
* @param $content String The content to check and convert
* @return String Converted content
*/
public function convertImgToPictureAddWebp($content) {
if(function_exists('is_amp_endpoint') && is_amp_endpoint()) {
//for AMP pages the