Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93
/home/sportsfe.../httpdocs/clone/wp-conte.../plugins/wp-smush.../core/integrat...
File: class-woocommerce.php
<?php
[0] Fix | Delete
[1] Fix | Delete
namespace Smush\Core\Integrations;
[2] Fix | Delete
[3] Fix | Delete
use Smush\Core\Controller;
[4] Fix | Delete
use Smush\Core\Transform\Transformer;
[5] Fix | Delete
use Smush\Core\Settings;
[6] Fix | Delete
[7] Fix | Delete
class WooCommerce extends Controller {
[8] Fix | Delete
public function __construct() {
[9] Fix | Delete
$this->register_filter( 'wp_smush_transform_rest_response_item', array(
[10] Fix | Delete
$this,
[11] Fix | Delete
'transform_rest_woo_product',
[12] Fix | Delete
), 10, 3 );
[13] Fix | Delete
[14] Fix | Delete
$this->register_filter( 'wp_smush_get_image_attribute_names', array( $this, 'allow_woo_image_attributes_to_convert' ) );
[15] Fix | Delete
[16] Fix | Delete
// WooCommerce's product gallery thumbnail CDN support.
[17] Fix | Delete
$this->register_filter( 'woocommerce_single_product_image_thumbnail_html', array( $this, 'maybe_native_lazyload_woo_product_gallery' ) );
[18] Fix | Delete
[19] Fix | Delete
$this->register_filter( 'wp_smush_should_skip_auto_smush', array( $this, 'maybe_skip_auto_smush' ) );
[20] Fix | Delete
}
[21] Fix | Delete
[22] Fix | Delete
public function should_run() {
[23] Fix | Delete
return function_exists( 'is_woocommerce' )
[24] Fix | Delete
&& class_exists( 'WooCommerce' );
[25] Fix | Delete
}
[26] Fix | Delete
[27] Fix | Delete
/**
[28] Fix | Delete
* @param $item array
[29] Fix | Delete
* @param $request \WP_REST_Request
[30] Fix | Delete
* @param $transformer Transformer
[31] Fix | Delete
*
[32] Fix | Delete
* @return array
[33] Fix | Delete
*/
[34] Fix | Delete
public function transform_rest_woo_product( $item, $request, $transformer ) {
[35] Fix | Delete
if ( ! str_starts_with( $request->get_route(), '/wc/v3/products' ) ) {
[36] Fix | Delete
return $item;
[37] Fix | Delete
}
[38] Fix | Delete
[39] Fix | Delete
$product_url = empty( $item['permalink'] ) ? '' : $item['permalink'];
[40] Fix | Delete
if ( ! empty( $item['description'] ) ) {
[41] Fix | Delete
$item['description'] = $transformer->transform_content( $item['description'], $product_url );
[42] Fix | Delete
}
[43] Fix | Delete
[44] Fix | Delete
if ( ! empty( $item['short_description'] ) ) {
[45] Fix | Delete
$item['short_description'] = $transformer->transform_content( $item['short_description'], $product_url );
[46] Fix | Delete
}
[47] Fix | Delete
[48] Fix | Delete
$images = empty( $item['images'] ) ? array() : $item['images'];
[49] Fix | Delete
foreach ( $images as $index => $image ) {
[50] Fix | Delete
if ( ! empty( $image['src'] ) ) {
[51] Fix | Delete
$item['images'][ $index ]['src'] = $transformer->transform_url( $image['src'] );
[52] Fix | Delete
}
[53] Fix | Delete
}
[54] Fix | Delete
[55] Fix | Delete
return $item;
[56] Fix | Delete
}
[57] Fix | Delete
[58] Fix | Delete
public function allow_woo_image_attributes_to_convert( $attribute_names ) {
[59] Fix | Delete
$attribute_names[] = 'data-large_image';
[60] Fix | Delete
return $attribute_names;
[61] Fix | Delete
}
[62] Fix | Delete
[63] Fix | Delete
public function maybe_native_lazyload_woo_product_gallery( $thumbnail_html ) {
[64] Fix | Delete
if ( ! Settings::get_instance()->is_lazyload_active() || strpos( $thumbnail_html, ' loading=' ) ) {
[65] Fix | Delete
return $thumbnail_html;
[66] Fix | Delete
}
[67] Fix | Delete
[68] Fix | Delete
// Woocommerce product gallery used `data-src` attribute which we excluded by default from lazyload
[69] Fix | Delete
// so we will always use native lazyload for it.
[70] Fix | Delete
$thumbnail_html = str_replace( '<img ', '<img loading="lazy" ', $thumbnail_html );
[71] Fix | Delete
[72] Fix | Delete
return $thumbnail_html;
[73] Fix | Delete
}
[74] Fix | Delete
[75] Fix | Delete
public function maybe_skip_auto_smush( $skip_auto_smush ) {
[76] Fix | Delete
if ( $skip_auto_smush ) {
[77] Fix | Delete
return true;
[78] Fix | Delete
}
[79] Fix | Delete
[80] Fix | Delete
// Skip auto Smush when woocommerce regenrate thumbnails via filter wp_get_attachment_image_src.
[81] Fix | Delete
$skip_auto_smush = doing_filter( 'wp_get_attachment_image_src' );
[82] Fix | Delete
[83] Fix | Delete
return $skip_auto_smush;
[84] Fix | Delete
}
[85] Fix | Delete
}
[86] Fix | Delete
[87] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function