Skip to content

Commit

Permalink
Merge pull request #32 from ilovepdf/develop
Browse files Browse the repository at this point in the history
v2.2.6
  • Loading branch information
teamcrombie authored Jan 17, 2025
2 parents 83a3449 + 01cc7eb commit ff994c3
Show file tree
Hide file tree
Showing 24 changed files with 200 additions and 375 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ jobs:
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Install SVN
run: sudo apt-get update && sudo apt-get install -y subversion
- name: WordPress Plugin Deploy
id: deploy
uses: 10up/action-wordpress-plugin-deploy@stable
Expand Down
46 changes: 42 additions & 4 deletions admin/Ilove_Img_Compress_Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Ilove_Img_Compress_Plugin {
* @access public
* @var string VERSION The current version of the plugin.
*/
const VERSION = '2.2.5';
const VERSION = '2.2.6';

/**
* The unique identifier of this plugin.
Expand All @@ -39,6 +39,15 @@ class Ilove_Img_Compress_Plugin {
*/
protected static $img_nonce;

/**
* File formats.
*
* @since 2.2.6
* @access public
* @var array $accepted_file_format List of accepted file formats.
*/
public static $accepted_file_format = array( 'image/jpeg', 'image/jpg', 'image/png', 'image/gif', 'image/svg+xml' );

/**
* This constructor defines the core functionality of the plugin.
*
Expand Down Expand Up @@ -80,7 +89,8 @@ public function admin_init() {
add_action( 'wp_ajax_ilove_img_compress_restore', array( $this, 'ilove_img_restore' ) );

// Process attachment metadata.
add_filter( 'wp_generate_attachment_metadata', array( $this, 'process_attachment' ), 10, 2 );
add_filter( 'wp_generate_attachment_metadata', array( $this, 'process_attachment' ), 11, 2 );
add_filter( 'delete_attachment', array( $this, 'before_delete_attachment' ) );

// Display media information in the attachment submit box.
add_action( 'attachment_submitbox_misc_actions', array( $this, 'show_media_info' ) );
Expand Down Expand Up @@ -248,6 +258,12 @@ public function column_id_row( $column_name, $column_id ) {
* @access public
*/
public function process_attachment( $metadata, $attachment_id ) {
$file = get_post( $attachment_id );

if ( ! in_array( $file->post_mime_type, self::$accepted_file_format, true ) ) {
return $metadata;
}

update_post_meta( $attachment_id, 'iloveimg_status_compress', 0 ); // status no compressed

$images_restore = null !== get_option( 'iloveimg_images_to_restore', null ) ? json_decode( get_option( 'iloveimg_images_to_restore' ), true ) : array();
Expand Down Expand Up @@ -364,9 +380,8 @@ public function show_notices() {
* @param \WP_Post $post Post object.
*/
public function show_media_info( $post ) {
$mime_type_accepted = array( 'image/jpeg', 'image/png', 'image/gif' );

if ( in_array( $post->post_mime_type, $mime_type_accepted, true ) ) {
if ( in_array( $post->post_mime_type, self::$accepted_file_format, true ) ) {

echo '<div class="misc-pub-section iloveimg-compress-images">';
echo '<h4>';
Expand Down Expand Up @@ -521,4 +536,27 @@ public function ilove_img_compress_clear_backup() {

wp_die();
}

/**
* Delete a file from the backup.
*
* It is activated before deleting an attached file. This allows us to delete the file from the backup.
*
* @since 2.2.6
* @param int $post_id Attachment ID.
*/
public function before_delete_attachment( $post_id ) {
$images_restore = null !== get_option( 'iloveimg_images_to_restore', null ) ? json_decode( get_option( 'iloveimg_images_to_restore' ), true ) : array();
$key_founded = array_search( $post_id, $images_restore, true );

if ( ! in_array( $post_id, $images_restore, true ) ) {
return;
}

if ( false !== $key_founded ) {
unset( $images_restore[ $key_founded ] );
wp_delete_file( ILOVE_IMG_COMPRESS_BACKUP_FOLDER . basename( get_attached_file( $post_id ) ) );
Ilove_Img_Compress_Resources::update_option( 'iloveimg_images_to_restore', wp_json_encode( $images_restore ) );
}
}
}
35 changes: 27 additions & 8 deletions admin/Ilove_Img_Compress_Resources.php
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ public static function get_status_of_column( $column_id ) {

$img_nonce = Ilove_Img_Compress_Plugin::get_img_nonce();

if ( strpos( $post->post_mime_type, 'image/jpg' ) !== false || strpos( $post->post_mime_type, 'image/jpeg' ) !== false || strpos( $post->post_mime_type, 'image/png' ) !== false || strpos( $post->post_mime_type, 'image/gif' ) !== false ) :
if ( in_array( $post->post_mime_type, Ilove_Img_Compress_Plugin::$accepted_file_format, true ) ) :
$_sizes = get_post_meta( $column_id, 'iloveimg_compress', true );
$status_compress = (int) get_post_meta( $column_id, 'iloveimg_status_compress', true );
$images_compressed = self::get_sizes_compressed( $column_id );
Expand Down Expand Up @@ -574,20 +574,39 @@ public static function regenerate_attachment_data( $attachment_id ) {
* @since 2.2.5
* @param string $option Name of the option to update. Expected to not be SQL-escaped.
* @param mixed $value Option value. Must be serializable if non-scalar. Expected to not be SQL-escaped.
* @param bool $update_all_sites Optional. Whether to update all sites in the network.
* @param bool|null $autoload Optional. Whether to load the option when WordPress starts up. Accepts a boolean, or null.
*/
public static function update_option( $option, $value, $autoload = null ) {
public static function update_option( $option, $value, $update_all_sites = false, $autoload = null ) {

if ( ! is_multisite() ) {
update_option( $option, $value, $autoload );
return;
}

$sites = get_sites();
foreach ( $sites as $site ) {
switch_to_blog( (int) $site->blog_id );
update_option( $option, $value, $autoload );
restore_current_blog();
}
if ( ! $update_all_sites ) {
self::switch_update_blog( get_current_blog_id(), $option, $value, $autoload );
return;
}

$sites = get_sites();
foreach ( $sites as $site ) {
self::switch_update_blog( (int) $site->blog_id, $option, $value, $autoload );
}
}

/**
* Switch to blog and update option
*
* @since 2.2.6
* @param int $blog_id ID of the blog to switch to.
* @param string $option Name of the option to update.
* @param mixed $value Option value.
* @param bool|null $autoload Whether to load the option when WordPress starts up.
*/
private static function switch_update_blog( $blog_id, $option, $value, $autoload ) {
switch_to_blog( $blog_id );
update_option( $option, $value, $autoload );
restore_current_blog();
}
}
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
"ilovepdf/iloveimg-php": "dev-master"
},
"require-dev": {
"phpstan/phpstan": "^1.12",
"szepeviktor/phpstan-wordpress": "^1.3",
"phpstan/phpstan": "^2.1",
"szepeviktor/phpstan-wordpress": "^2.0",
"phpstan/extension-installer": "^1.4",
"wp-coding-standards/wpcs": "^3.0"
},
Expand Down
9 changes: 5 additions & 4 deletions ilove-img-compress.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* Plugin Name: Image Compressor & Optimizer - iLoveIMG
* Plugin URI: https://iloveapi.com/
* Description: Get your images delivered quickly. Now you can get a powerful, easy to use, and reliable image compression plugin for your image optimization needs. With full automation and powerful features, iLoveIMG makes it easy to speed up your website by lightening past and new images with just a click. Compress JPG, PNG and GIF images in your WordPress to improve the positioning of your site, boost visitor’s engagement and ultimately increase sales.
* Version: 2.2.5
* Version: 2.2.6
* Requires at least: 5.3
* Requires PHP: 7.4
* Author: iLoveIMG
Expand Down Expand Up @@ -99,7 +99,7 @@ function ilove_img_compress_add_plugin_page_settings_link( $links ) {
* @since 1.0.0
*/
function ilove_img_compress_activate() {
Ilove_Img_Compress_Resources::update_option( 'ilove_img_compress_db_version', ILOVE_IMG_COMPRESS_DB_VERSION );
Ilove_Img_Compress_Resources::update_option( 'ilove_img_compress_db_version', ILOVE_IMG_COMPRESS_DB_VERSION, true );

if ( ! file_exists( ILOVE_IMG_COMPRESS_BACKUP_FOLDER ) ) {
wp_mkdir_p( ILOVE_IMG_COMPRESS_BACKUP_FOLDER );
Expand All @@ -121,14 +121,15 @@ function ilove_img_compress_activate() {
'iloveimg_field_size_full_height' => 2048,
'iloveimg_field_backup' => 'on',
)
)
),
true
);
} else {
$old_data = get_option( 'iloveimg_options_compress' );

if ( is_serialized( $old_data ) ) {
$old_data_serialize = unserialize( get_option( 'iloveimg_options_compress' ) ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_unserialize
Ilove_Img_Compress_Resources::update_option( 'iloveimg_options_compress', wp_json_encode( $old_data_serialize ) );
Ilove_Img_Compress_Resources::update_option( 'iloveimg_options_compress', wp_json_encode( $old_data_serialize ), true );
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
"gulp-clean-css": "^4.3.0",
"gulp-if": "^3.0.0",
"gulp-rename": "^2.0.0",
"gulp-sass": "^5.1.0",
"gulp-sass": "^6.0.0",
"gulp-sourcemaps": "^3.0.0",
"gulp-uglify": "^3.0.2",
"merge-stream": "^2.0.0",
"sass": "^1.81"
"sass": "^1.83"
}
}
2 changes: 1 addition & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ parameters:
excludePaths:
analyseAndScan:
- vendor
- node_modules
- node_modules?
analyse:
- vendor/ilovepdf/iloveimg-php
13 changes: 11 additions & 2 deletions readme.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
=== Image Compressor & Optimizer - iLoveIMG ===
Plugin Name: Image Compressor & Optimizer - iLoveIMG
Version: 2.2.5
Version: 2.2.6
Author: iLovePDF
Author URI: https://www.iloveimg.com/
Contributors: iLovePDF
Tags: compress, image, optimize, performance, image optimizer
Requires at least: 5.3
Tested up to: 6.7
Stable tag: 2.2.5
Stable tag: 2.2.6
Requires PHP: 7.4
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html
Expand Down Expand Up @@ -94,6 +94,15 @@ Moreover, all processed files are automatically deleted from our servers after b

== Changelog ==

= 2.2.6 =
Improved
* Update Libraries.
* Improved multisite support.
* If a file is deleted from wordpress, it will also be deleted from the iloveimg-backup folder.

Fixed
* Thumbnails and other intermediate sizes coming from a PDF file were compressed.

= 2.2.5 =
Improved
* Update Libraries.
Expand Down
2 changes: 1 addition & 1 deletion vendor/autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@

require_once __DIR__ . '/composer/autoload_real.php';

return ComposerAutoloaderInit8eb75759ed79481defcfa275893544da::getLoader();
return ComposerAutoloaderInitca264d8dde67813376c567ae25ecc7cd::getLoader();
11 changes: 7 additions & 4 deletions vendor/composer/InstalledVersions.php
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ private static function getInstalled()
}

$installed = array();
$copiedLocalDir = false;

if (self::$canGetVendors) {
foreach (ClassLoader::getRegisteredLoaders() as $vendorDir => $loader) {
Expand All @@ -330,9 +331,11 @@ private static function getInstalled()
} elseif (is_file($vendorDir.'/composer/installed.php')) {
/** @var array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>} $required */
$required = require $vendorDir.'/composer/installed.php';
$installed[] = self::$installedByVendor[$vendorDir] = $required;
if (null === self::$installed && strtr($vendorDir.'/composer', '\\', '/') === strtr(__DIR__, '\\', '/')) {
self::$installed = $installed[count($installed) - 1];
self::$installedByVendor[$vendorDir] = $required;
$installed[] = $required;
if (strtr($vendorDir.'/composer', '\\', '/') === strtr(__DIR__, '\\', '/')) {
self::$installed = $required;
$copiedLocalDir = true;
}
}
}
Expand All @@ -350,7 +353,7 @@ private static function getInstalled()
}
}

if (self::$installed !== array()) {
if (self::$installed !== array() && !$copiedLocalDir) {
$installed[] = self::$installed;
}

Expand Down
10 changes: 5 additions & 5 deletions vendor/composer/autoload_real.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

// autoload_real.php @generated by Composer

class ComposerAutoloaderInit8eb75759ed79481defcfa275893544da
class ComposerAutoloaderInitca264d8dde67813376c567ae25ecc7cd
{
private static $loader;

Expand All @@ -24,16 +24,16 @@ public static function getLoader()

require __DIR__ . '/platform_check.php';

spl_autoload_register(array('ComposerAutoloaderInit8eb75759ed79481defcfa275893544da', 'loadClassLoader'), true, true);
spl_autoload_register(array('ComposerAutoloaderInitca264d8dde67813376c567ae25ecc7cd', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
spl_autoload_unregister(array('ComposerAutoloaderInit8eb75759ed79481defcfa275893544da', 'loadClassLoader'));
spl_autoload_unregister(array('ComposerAutoloaderInitca264d8dde67813376c567ae25ecc7cd', 'loadClassLoader'));

require __DIR__ . '/autoload_static.php';
call_user_func(\Composer\Autoload\ComposerStaticInit8eb75759ed79481defcfa275893544da::getInitializer($loader));
call_user_func(\Composer\Autoload\ComposerStaticInitca264d8dde67813376c567ae25ecc7cd::getInitializer($loader));

$loader->register(true);

$filesToLoad = \Composer\Autoload\ComposerStaticInit8eb75759ed79481defcfa275893544da::$files;
$filesToLoad = \Composer\Autoload\ComposerStaticInitca264d8dde67813376c567ae25ecc7cd::$files;
$requireFile = \Closure::bind(static function ($fileIdentifier, $file) {
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
$GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;
Expand Down
8 changes: 4 additions & 4 deletions vendor/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Composer\Autoload;

class ComposerStaticInit8eb75759ed79481defcfa275893544da
class ComposerStaticInitca264d8dde67813376c567ae25ecc7cd
{
public static $files = array (
'7b11c4dc42b3b3023073cb14e519683c' => __DIR__ . '/..' . '/ralouphie/getallheaders/src/getallheaders.php',
Expand Down Expand Up @@ -78,9 +78,9 @@ class ComposerStaticInit8eb75759ed79481defcfa275893544da
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInit8eb75759ed79481defcfa275893544da::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit8eb75759ed79481defcfa275893544da::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit8eb75759ed79481defcfa275893544da::$classMap;
$loader->prefixLengthsPsr4 = ComposerStaticInitca264d8dde67813376c567ae25ecc7cd::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInitca264d8dde67813376c567ae25ecc7cd::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInitca264d8dde67813376c567ae25ecc7cd::$classMap;

}, null, ClassLoader::class);
}
Expand Down
Loading

0 comments on commit ff994c3

Please sign in to comment.