Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Donate link: https://tinypng.com/
Tags: compress images, compression, image size, page speed, performance
Requires at least: 4.0
Tested up to: 6.8
Stable tag: 3.6.4
Stable tag: 3.6.5
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html

Expand Down Expand Up @@ -174,6 +174,9 @@ A: You can upgrade to a paid account by adding your *Payment details* on your [a
A: When the conversion feature is enabled (to convert images to AVIF or WebP), each image will use double the number of credits: one for compression and one for format conversion.

== Changelog ==
= 3.6.5 =
* fix: prevent picture element when using a page builder

= 3.6.4 =
* added a guard to prevent bulk processing to requeue already processed images

Expand Down
31 changes: 31 additions & 0 deletions src/class-tiny-helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

class Tiny_Helpers {


/**
* truncate_text will truncate a string to a given length.
* When text is longer than the given length, the string will be truncated and
Expand Down Expand Up @@ -108,4 +109,34 @@ public static function get_mimetype( $input ) {
throw new Exception( 'finfo extension is not available.' );
}
}


/**
* Checks wether a user is viewing from a page builder
*
* @since 3.6.5
*/
public static function is_pagebuilder_request() {
$pagebuilder_keys = array(
'fl_builder', // Beaver Builder
'et_fb', // Divi Builder
'bricks', // Bricks Builder
'breakdance', // Breakdance Builder
'breakdance_browser', // Breakdance Builder
'ct_builder', // Oxygen Builder
'fb-edit', // Avada Live Builder
'spio_no_cdn', // Site Origin
'tatsu', // Tatsu Builder
'tve', // Thrive Architect
'tcbf', // Thrive Architect
);

foreach ( $pagebuilder_keys as $key ) {
if ( isset( $_GET[ $key ] ) ) {
return true;
}
}

return false;
}
}
22 changes: 16 additions & 6 deletions src/class-tiny-picture.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class Tiny_Picture extends Tiny_WP_Base {




/** @var string */
private $base_dir;

Expand Down Expand Up @@ -59,6 +60,10 @@ function __construct( $base_dir = ABSPATH, $domains = array() ) {
return;
}

if ( Tiny_Helpers::is_pagebuilder_request() ) {
return;
}

add_action('template_redirect', function () {
ob_start( array( $this, 'replace_sources' ), 1000 );
});
Expand Down Expand Up @@ -189,6 +194,7 @@ private function filter_images( $content ) {
abstract class Tiny_Source_Base {



public $raw_html;
protected $base_dir;
protected $allowed_domains;
Expand Down Expand Up @@ -237,9 +243,9 @@ protected function get_element_by_tag( $html, $tagname ) {
$regex_tag = preg_quote( $tagname, '~' );
if ( preg_match_all(
'~<' . $regex_tag .
'\b(?:[^>"\']+|"[^"]*"|\'[^\']*\')*>.*?</' .
$regex_tag .
'>~is',
'\b(?:[^>"\']+|"[^"]*"|\'[^\']*\')*>.*?</' .
$regex_tag .
'>~is',
$html,
$matches
) ) {
Expand Down Expand Up @@ -379,11 +385,13 @@ protected function create_alternative_sources( $original_source_html ) {
}
}

if ( $width_descriptor &&
if (
$width_descriptor &&
! self::srcset_contains_width_descriptor(
$srcset_parts,
$width_descriptor
) ) {
)
) {
continue;
}

Expand Down Expand Up @@ -412,7 +420,7 @@ protected function create_alternative_sources( $original_source_html ) {
}
$source_parts[] = '/>';
$sources[] = implode( ' ', $source_parts );
}// End foreach().
} // End foreach().

return $sources;
}
Expand Down Expand Up @@ -472,6 +480,7 @@ class Tiny_Picture_Source extends Tiny_Source_Base {




/**
* Adds alternative format sources (e.g., image/webp, image/avif) to an existing
* <picture> element based on locally available converted files.
Expand Down Expand Up @@ -513,6 +522,7 @@ public function augment_picture_element() {

class Tiny_Image_Source extends Tiny_Source_Base {


/**
* Generates a formatted image source array if the corresponding local file exists.
*
Expand Down
2 changes: 1 addition & 1 deletion src/class-tiny-plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
class Tiny_Plugin extends Tiny_WP_Base {
const VERSION = '3.6.4';
const VERSION = '3.6.5';
const MEDIA_COLUMN = self::NAME;
const DATETIME_FORMAT = 'Y-m-d G:i:s';

Expand Down
20 changes: 20 additions & 0 deletions test/unit/TinyHelpersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,24 @@ public function test_uppercase_extension_and_mimetype_case_insensitive()
$expected = '/home/user/PICTURE.avif';
$this->assertEquals($expected, Tiny_Helpers::replace_file_extension('image/avif', $input));
}

public function test_is_pagebuilder_request_returns_false_when_no_pagebuilder_keys()
{
$_GET = array();
$this->assertFalse(Tiny_Helpers::is_pagebuilder_request());
}

public function test_is_pagebuilder_request_returns_true_for_beaver_builder()
{
$_GET = array('fl_builder' => '1');
$this->assertTrue(Tiny_Helpers::is_pagebuilder_request());
$_GET = array();
}

public function test_is_pagebuilder_request_returns_false_for_non_pagebuilder_keys()
{
$_GET = array('page' => 'settings', 'post_id' => '123');
$this->assertFalse(Tiny_Helpers::is_pagebuilder_request());
$_GET = array();
}
}
26 changes: 26 additions & 0 deletions test/unit/TinyPictureTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -327,4 +327,30 @@ public function test_mixed_descriptors_in_source()

$this->assertSame($expected, $output);
}

public function test_does_not_register_hooks_when_pagebuilder_request()
{
$_GET = array('fl_builder' => '1');

$this->wp->stub('is_admin', function () {
return false;
});

$tiny_picture = new Tiny_Picture($this->vfs->url(), array('https://www.tinifytest.com'));

$template_redirect_registered = false;
foreach ($this->wp->getCalls('add_action') as $call) {
if ($call[0] === 'template_redirect') {
$template_redirect_registered = true;
break;
}
}

$this->assertFalse(
$template_redirect_registered,
'Tiny_Picture should not register template_redirect hook when pagebuilder is active'
);

$_GET = array();
}
}
2 changes: 2 additions & 0 deletions test/unit/TinyPluginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,8 @@ public function test_conversion_enabled_but_filtered_off_not_load_picture()

public function test_conversion_enabled_and_not_filtered()
{
$_GET = array();

// Mock settings with compression count
$mock_settings = $this->createMock(Tiny_Settings::class);
$mock_settings->method('get_conversion_enabled')->willReturn(true);
Expand Down
2 changes: 1 addition & 1 deletion tiny-compress-images.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* Plugin Name: TinyPNG - JPEG, PNG & WebP image compression
* Description: Speed up your website. Optimize your JPEG, PNG, and WebP images automatically with TinyPNG.
* Version: 3.6.4
* Version: 3.6.5
* Author: TinyPNG
* Author URI: https://tinypng.com
* Text Domain: tiny-compress-images
Expand Down