Skip to content

Commit

Permalink
Merge pull request #29 from ilovepdf/feature/v2.2.5
Browse files Browse the repository at this point in the history
Feature/v2.2.5
  • Loading branch information
teamcrombie authored Nov 21, 2024
2 parents b61c76d + 9fbf3f7 commit e7e71e8
Show file tree
Hide file tree
Showing 27 changed files with 909 additions and 232 deletions.
15 changes: 3 additions & 12 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.4';
const VERSION = '2.2.5';

/**
* The unique identifier of this plugin.
Expand Down Expand Up @@ -109,20 +109,11 @@ public function enqueue_scripts() {

if ( ( 'upload.php' === $pagenow || 'iloveimg_page_iloveimg-compress-admin-page' === $hook_suffix || 'iloveimg_page_iloveimg-watermark-admin-page' === $hook_suffix || 'media-new.php' === $pagenow || 'post.php' === $pagenow ) && get_current_screen()->post_type !== 'product' ) {

// Enqueue the Sweet alert JavaScript file.
wp_enqueue_script(
self::NAME . '_sweetalert2',
plugins_url( '/assets/js/sweetalert2.all.min.js', __DIR__ ),
array(),
'11.11.0',
true
);

// Enqueue the main JavaScript file.
wp_enqueue_script(
self::NAME . '_admin',
plugins_url( '/assets/js/main.min.js', __DIR__ ),
array( self::NAME . '_sweetalert2' ),
array(),
self::VERSION,
true
);
Expand Down Expand Up @@ -509,7 +500,7 @@ public function ilove_img_restore() {
if ( false !== $key_founded ) {
unset( $images_restore[ $key_founded ] );
wp_delete_file( ILOVE_IMG_COMPRESS_BACKUP_FOLDER . basename( get_attached_file( $attachment_id ) ) );
update_option( 'iloveimg_images_to_restore', wp_json_encode( $images_restore ) );
Ilove_Img_Compress_Resources::update_option( 'iloveimg_images_to_restore', wp_json_encode( $images_restore ) );
}

wp_send_json_success( __( 'It was restored correctly', 'iloveimg' ), 200 );
Expand Down
2 changes: 1 addition & 1 deletion admin/Ilove_Img_Compress_Process.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public function compress( $images_id ) {

$images_restore = array_unique( $images_restore );

update_option( 'iloveimg_images_to_restore', wp_json_encode( $images_restore, JSON_FORCE_OBJECT ) );
Ilove_Img_Compress_Resources::update_option( 'iloveimg_images_to_restore', wp_json_encode( $images_restore, JSON_FORCE_OBJECT ) );
}

foreach ( $_sizes as $_size ) {
Expand Down
23 changes: 23 additions & 0 deletions admin/Ilove_Img_Compress_Resources.php
Original file line number Diff line number Diff line change
Expand Up @@ -567,4 +567,27 @@ public static function regenerate_attachment_data( $attachment_id ) {

wp_update_attachment_metadata( $attachment_id, $metadata ); // Update new attachment metadata
}

/**
* Update option, works with multisite if enabled
*
* @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|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 ) {

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();
}
}
}
32 changes: 16 additions & 16 deletions admin/Ilove_Img_Compress_Serializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function save() {
}
}

update_option( 'iloveimg_options_compress', wp_json_encode( $posts_value ) );
Ilove_Img_Compress_Resources::update_option( 'iloveimg_options_compress', wp_json_encode( $posts_value ) );
}

if ( 'iloveimg_action_logout' === $_POST['iloveimg_action'] ) {// phpcs:ignore WordPress.Security.NonceVerification.Missing
Expand All @@ -45,7 +45,7 @@ public function save() {
unset( $options['iloveimg_field_compress_activated'] );
unset( $options['iloveimg_field_autocompress'] );
unset( $options['iloveimg_field_resize_full'] );
update_option( 'iloveimg_options_compress', wp_json_encode( $options ) );
Ilove_Img_Compress_Resources::update_option( 'iloveimg_options_compress', wp_json_encode( $options ) );
}

if ( 'iloveimg_action_login' === $_POST['iloveimg_action'] ) {// phpcs:ignore WordPress.Security.NonceVerification.Missing
Expand All @@ -63,14 +63,14 @@ public function save() {
)
);
if ( wp_remote_retrieve_response_code( $response ) === 200 ) {
update_option( 'iloveimg_account', $response['body'] );
update_option( 'iloveimg_user_is_migrated', 1 );
Ilove_Img_Compress_Resources::update_option( 'iloveimg_account', $response['body'] );
Ilove_Img_Compress_Resources::update_option( 'iloveimg_user_is_migrated', 1 );
$options = json_decode( get_option( 'iloveimg_options_compress' ), true );
$options['iloveimg_field_compress_activated'] = 1;
$options['iloveimg_field_autocompress'] = 1;
update_option( 'iloveimg_options_compress', wp_json_encode( $options ) );
Ilove_Img_Compress_Resources::update_option( 'iloveimg_options_compress', wp_json_encode( $options ) );
} else {
update_option(
Ilove_Img_Compress_Resources::update_option(
'iloveimg_account_error',
wp_json_encode(
array(
Expand Down Expand Up @@ -103,27 +103,27 @@ public function save() {
if ( get_option( $key ) ) {
$num = (int) get_option( $key );
++$num;
update_option( $key, $num );
Ilove_Img_Compress_Resources::update_option( $key, $num );
} else {
update_option( $key, 1 );
Ilove_Img_Compress_Resources::update_option( $key, 1 );
}
if ( (int) get_option( $key ) <= 3 ) {
update_option( 'iloveimg_account', $response['body'] );
Ilove_Img_Compress_Resources::update_option( 'iloveimg_account', $response['body'] );
$options = json_decode( get_option( 'iloveimg_options_compress' ) );
$options['iloveimg_field_compress_activated'] = 1;
$options['iloveimg_field_autocompress'] = 1;
update_option( 'iloveimg_options_compress', wp_json_encode( $options ) );
Ilove_Img_Compress_Resources::update_option( 'iloveimg_options_compress', wp_json_encode( $options ) );
} else {
update_option( 'iloveimg_account_error', wp_json_encode( array( 'action' => 'register_limit' ) ) );
Ilove_Img_Compress_Resources::update_option( 'iloveimg_account_error', wp_json_encode( array( 'action' => 'register_limit' ) ) );
}
} else {
update_option(
Ilove_Img_Compress_Resources::update_option(
'iloveimg_account_error',
wp_json_encode(
array(
'action' => 'register',
'email' => sanitize_email( wp_unslash( $_POST['iloveimg_field_email'] ) ), // phpcs:ignore WordPress.Security.NonceVerification.Missing
'name' => sanitize_text_field( wp_unslash( $_POST['iloveimg_field_name'] ) ), // phpcs:ignore WordPress.Security.NonceVerification.Missing
'action' => 'register',
'email' => sanitize_email( wp_unslash( $_POST['iloveimg_field_email'] ) ), // phpcs:ignore WordPress.Security.NonceVerification.Missing
'name' => sanitize_text_field( wp_unslash( $_POST['iloveimg_field_name'] ) ), // phpcs:ignore WordPress.Security.NonceVerification.Missing
)
)
);
Expand All @@ -134,7 +134,7 @@ public function save() {
if ( ! isset( $_POST['iloveimg_field_proyect'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
$this->redirect();
}
update_option( 'iloveimg_proyect', sanitize_text_field( wp_unslash( $_POST['iloveimg_field_proyect'] ) ) ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
Ilove_Img_Compress_Resources::update_option( 'iloveimg_proyect', sanitize_text_field( wp_unslash( $_POST['iloveimg_field_proyect'] ) ) ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
}
}

Expand Down
8 changes: 5 additions & 3 deletions admin/views/account.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php
use Ilove_Img_Compress\Ilove_Img_Compress_Resources;

$ilove_img_is_logged = false;
$ilove_img_account = array();

Expand All @@ -12,7 +14,7 @@
unset( $ilove_img_options['iloveimg_field_compress_activated'] );
unset( $ilove_img_options['iloveimg_field_autocompress'] );
unset( $ilove_img_options['iloveimg_field_resize_full'] );
update_option( 'iloveimg_options_compress', wp_json_encode( $ilove_img_options ) );
Ilove_Img_Compress_Resources::update_option( 'iloveimg_options_compress', wp_json_encode( $ilove_img_options ) );

wp_safe_redirect( admin_url( 'admin.php?page=iloveimg-compress-admin-page' ) );
exit();
Expand All @@ -21,7 +23,7 @@
$ilove_img_account = json_decode( get_option( 'iloveimg_account' ), true );

$ilove_img_is_logged = true;
update_option( 'iloveimg_first_loggued', 1 );
Ilove_Img_Compress_Resources::update_option( 'iloveimg_first_loggued', 1 );
$ilove_img_token = $ilove_img_account['token'];
$ilove_img_response = wp_remote_get(
ILOVE_IMG_COMPRESS_USER_URL . '/' . $ilove_img_account['id'],
Expand All @@ -33,7 +35,7 @@
if ( isset( $ilove_img_response['response']['code'] ) && 200 === (int) $ilove_img_response['response']['code'] ) {
$ilove_img_account = json_decode( $ilove_img_response['body'], true );
$ilove_img_account['token'] = $ilove_img_token;
update_option( 'iloveimg_account', wp_json_encode( $ilove_img_account ) );
Ilove_Img_Compress_Resources::update_option( 'iloveimg_account', wp_json_encode( $ilove_img_account ) );
}
} elseif ( get_option( 'iloveimg_account_error' ) ) {
$ilove_img_account_error = json_decode( get_option( 'iloveimg_account_error' ), true );
Expand Down
4 changes: 2 additions & 2 deletions admin/views/compress.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,9 @@
<label>Restore Original Images</label>
<p>All backup images can be restored. This action will recover the original images as they were before being stamped with Compress or Watermark. <span style="color: red;">Warning: Any changes made AFTER Watermark/Compress would be also restored.</span></p>
<p>You can also clear all your backup images to free memory space. <span style="color: red;">Warning: Clear backups will prevent you to restore original images.</span></p>
<button type="button" class="button button-style-iloveimg" id="iloveimg_restore_all" <?php echo ( isset( $options_value['iloveimg_field_backup'] ) && Ilove_Img_Compress_Resources::is_there_backup() ) ? '' : 'disabled'; ?>>Restore All</button>
<button type="button" class="button button-style-iloveimg" id="iloveimg_restore_all" <?php echo ( isset( $options_value['iloveimg_field_backup'] ) && Ilove_Img_Compress_Resources::get_size_backup() ) ? '' : 'disabled'; ?>>Restore All</button>

<button type="button" class="button button-remove button-style-iloveimg" id="iloveimg_clear_backup" <?php echo ( isset( $options_value['iloveimg_field_backup'] ) && Ilove_Img_Compress_Resources::is_there_backup() ) ? '' : 'disabled'; ?>>Clear backup</button>
<button type="button" class="button button-remove button-style-iloveimg" id="iloveimg_clear_backup" <?php echo ( isset( $options_value['iloveimg_field_backup'] ) && Ilove_Img_Compress_Resources::get_size_backup() ) ? '' : 'disabled'; ?>>Clear backup</button>
<span><?php echo (float) round( Ilove_Img_Compress_Resources::get_size_backup(), 2 ); ?> MB</span>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion assets/css/app.min.css

Large diffs are not rendered by default.

Loading

0 comments on commit e7e71e8

Please sign in to comment.