Skip to content

Commit

Permalink
Merge pull request #41 from ilovepdf/feature/v2.2.4
Browse files Browse the repository at this point in the history
Feature/v2.2.4
  • Loading branch information
teamcrombie authored Nov 25, 2024
2 parents b38e7bc + 701a03b commit de18d2f
Show file tree
Hide file tree
Showing 28 changed files with 940 additions and 237 deletions.
19 changes: 16 additions & 3 deletions README.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
=== Best Watermark - Protect images on your site with iLoveIMG ===
Plugin Name: Best Watermark - Protect images on your site with iLoveIMG
Version: 2.2.3
Version: 2.2.4
Author: iLovePDF
Author URI: https://www.iloveimg.com/
Contributors: iLovePDF
Tags: watermark, image protection, photography, picture, e-commerce
Requires at least: 5.3
Tested up to: 6.6.2
Stable tag: 2.2.3
Tested up to: 6.7
Stable tag: 2.2.4
Requires PHP: 7.4
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html
Expand Down Expand Up @@ -100,6 +100,19 @@ Moreover, all processed files are automatically deleted from our servers after b

== Changelog ==

= 2.2.4 =
Improved
* Compatibility with WordPress 6.7
* Update Libraries.
* Sweetalert library removed.
* Improved multisite support.

Fixed
* The 'Restore All' and 'Clear Backup' buttons were not disabled when there no files to restore.
* When editing files, when the functionality was disabled, the watermark button was still shown.
* The 'Position' button does not work correctly when a point in the final row is selected.
* Improved File URL handling in the multisite watermark process.

= 2.2.3 =
Fixed
* Fixed an issue with vendor dependencies.
Expand Down
22 changes: 8 additions & 14 deletions admin/Ilove_Img_Wm_Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class Ilove_Img_Wm_Plugin {
* @access public
* @var string VERSION The current version of the plugin.
*/
const VERSION = '2.2.3';
const VERSION = '2.2.4';

/**
* The unique identifier of this plugin.
Expand Down Expand Up @@ -104,17 +104,10 @@ public function enqueue_scripts() {
'1.8.0',
true
);
wp_enqueue_script(
self::NAME . '_sweetalert2',
plugins_url( '/assets/js/sweetalert2.all.min.js', __DIR__ ),
array(),
'11.11.0',
true
);
wp_enqueue_script(
self::NAME . '_admin',
plugins_url( '/assets/js/main.min.js', __DIR__ ),
array( self::NAME . '_spectrum_admin', self::NAME . '_sweetalert2' ),
array( self::NAME . '_spectrum_admin' ),
self::VERSION,
true
);
Expand Down Expand Up @@ -266,7 +259,7 @@ public function process_attachment( $metadata, $attachment_id ) {
$_wm_options = json_decode( get_option( 'iloveimg_options_watermark' ), true );
$_wm_options['iloveimg_field_autowatermark'] = 1;

update_option( 'iloveimg_options_watermark', wp_json_encode( $_wm_options ) );
Ilove_Img_Wm_Resources::update_option( 'iloveimg_options_watermark', wp_json_encode( $_wm_options ) );
delete_option( 'iloveimg_options_is_watermark_image' );
}

Expand All @@ -282,8 +275,8 @@ public function ilove_img_wm_library_set_watermark_image() {
$_wm_options = json_decode( get_option( 'iloveimg_options_watermark' ), true );
unset( $_wm_options['iloveimg_field_autowatermark'] );

update_option( 'iloveimg_options_watermark', wp_json_encode( $_wm_options ) );
update_option( 'iloveimg_options_is_watermark_image', 1 );
Ilove_Img_Wm_Resources::update_option( 'iloveimg_options_watermark', wp_json_encode( $_wm_options ) );
Ilove_Img_Wm_Resources::update_option( 'iloveimg_options_is_watermark_image', 1 );

wp_die();
}
Expand Down Expand Up @@ -430,8 +423,9 @@ public function show_notices() {
*/
public function show_media_info( $post ) {
$mime_type_accepted = array( 'image/jpeg', 'image/png', 'image/gif' );
$options = json_decode( get_option( 'iloveimg_options_watermark' ), true );

if ( in_array( $post->post_mime_type, $mime_type_accepted, true ) ) {
if ( in_array( $post->post_mime_type, $mime_type_accepted, true ) && isset( $options['iloveimg_field_watermark_activated'] ) ) {

echo '<div class="misc-pub-section iloveimg-compress-images">';
echo '<h4>';
Expand Down Expand Up @@ -535,7 +529,7 @@ public function ilove_img_restore() {
if ( false !== $key_founded ) {
unset( $images_restore[ $key_founded ] );
wp_delete_file( ILOVE_IMG_WM_BACKUP_FOLDER . basename( get_attached_file( $attachment_id ) ) );
update_option( 'iloveimg_images_to_restore', wp_json_encode( $images_restore ) );
Ilove_Img_Wm_Resources::update_option( 'iloveimg_images_to_restore', wp_json_encode( $images_restore ) );
}

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

$images_restore = array_unique( $images_restore );

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

foreach ( $_sizes as $_size ) {
Expand All @@ -107,7 +107,7 @@ public function watermark( $images_id ) {
$document_root = str_replace( sanitize_url( wp_unslash( $_SERVER['SCRIPT_NAME'] ) ), '', sanitize_url( wp_unslash( $_SERVER['SCRIPT_FILENAME'] ) ) );
}

$path_file = $document_root . str_replace( site_url(), '', $image[0] );
$path_file = $document_root . str_replace( site_url( '', $parse_image_url['scheme'] ), '', $image[0] );

if ( in_array( $_size, $_wm_options['iloveimg_field_sizes'], true ) ) {

Expand Down
42 changes: 42 additions & 0 deletions admin/Ilove_Img_Wm_Resources.php
Original file line number Diff line number Diff line change
Expand Up @@ -523,4 +523,46 @@ 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.4
* @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, $update_all_sites = false, $autoload = null ) {

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

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.4
* @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();
}
}
34 changes: 18 additions & 16 deletions admin/Ilove_Img_Wm_Serializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ public function save() {
$posts_value[ $key ] = wp_unslash( $post_value );
}
}
update_option( 'iloveimg_options_watermark', wp_json_encode( $posts_value ) );

Ilove_Img_Wm_Resources::update_option( 'iloveimg_options_watermark', wp_json_encode( $posts_value ) );
}

if ( 'iloveimg_action_logout' === $_POST['iloveimg_action'] ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
Expand All @@ -62,7 +63,7 @@ public function save() {
unset( $options['iloveimg_field_watermark_activated'] );
unset( $options['iloveimg_field_autowatermark'] );
unset( $options['iloveimg_field_resize_full'] );
update_option( 'iloveimg_options_watermark', wp_json_encode( $options ) );
Ilove_Img_Wm_Resources::update_option( 'iloveimg_options_watermark', wp_json_encode( $options ) );
}

if ( 'iloveimg_action_login' === $_POST['iloveimg_action'] ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
Expand All @@ -80,14 +81,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_Wm_Resources::update_option( 'iloveimg_account', $response['body'] );
Ilove_Img_Wm_Resources::update_option( 'iloveimg_user_is_migrated', 1 );
$options = json_decode( get_option( 'iloveimg_options_watermark' ), true );
$options['iloveimg_field_watermark_activated'] = 1;
$options['iloveimg_field_autowatermark'] = 1;
update_option( 'iloveimg_options_watermark', wp_json_encode( $options ) );
Ilove_Img_Wm_Resources::update_option( 'iloveimg_options_watermark', wp_json_encode( $options ) );
} else {
update_option(
Ilove_Img_Wm_Resources::update_option(
'iloveimg_account_error',
wp_json_encode(
array(
Expand Down Expand Up @@ -120,27 +121,27 @@ public function save() {
if ( get_option( $key ) ) {
$num = (int) get_option( $key );
++$num;
update_option( $key, $num );
Ilove_Img_Wm_Resources::update_option( $key, $num );
} else {
update_option( $key, 1 );
Ilove_Img_Wm_Resources::update_option( $key, 1 );
}
if ( (int) get_option( $key ) <= 3 ) {
update_option( 'iloveimg_account', $response['body'] );
Ilove_Img_Wm_Resources::update_option( 'iloveimg_account', $response['body'] );
$options = json_decode( get_option( 'iloveimg_options_watermark' ), true );
$options['iloveimg_field_watermark_activated'] = 1;
$options['iloveimg_field_autowatermark'] = 1;
update_option( 'iloveimg_options_watermark', wp_json_encode( $options ) );
Ilove_Img_Wm_Resources::update_option( 'iloveimg_options_watermark', wp_json_encode( $options ) );
} else {
update_option( 'iloveimg_account_error', wp_json_encode( array( 'action' => 'register_limit' ) ) );
Ilove_Img_Wm_Resources::update_option( 'iloveimg_account_error', wp_json_encode( array( 'action' => 'register_limit' ) ) );
}
} else {
update_option(
Ilove_Img_Wm_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 @@ -151,7 +152,8 @@ 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_Wm_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_Wm\Ilove_Img_Wm_Resources;

$ilove_img_wm_is_logged = false;
$ilove_img_wm_account = array();

Expand All @@ -12,7 +14,7 @@
unset( $options['iloveimg_field_watermark_activated'] );
unset( $options['iloveimg_field_autowatermark'] );
unset( $options['iloveimg_field_resize_full'] );
update_option( 'iloveimg_options_watermark', wp_json_encode( $ilove_img_wm_options ) );
Ilove_Img_Wm_Resources::update_option( 'iloveimg_options_watermark', wp_json_encode( $ilove_img_wm_options ) );

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

$ilove_img_wm_is_logged = true;
update_option( 'iloveimg_first_loggued', 1 );
Ilove_Img_Wm_Resources::update_option( 'iloveimg_first_loggued', 1 );
$ilove_img_wm_token = $ilove_img_wm_account['token'];

$ilove_img_wm_response = wp_remote_get(
Expand All @@ -35,7 +37,7 @@
if ( 200 === $ilove_img_wm_response['response']['code'] ) {
$ilove_img_wm_account = json_decode( $ilove_img_wm_response['body'], true );
$ilove_img_wm_account['token'] = $ilove_img_wm_token;
update_option( 'iloveimg_account', wp_json_encode( $ilove_img_wm_account ) );
Ilove_Img_Wm_Resources::update_option( 'iloveimg_account', wp_json_encode( $ilove_img_wm_account ) );
}
} else {
?>
Expand Down
10 changes: 5 additions & 5 deletions admin/views/watermark.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,9 @@
<td><input type="radio" name="iloveimg_field_position" value="6" <?php echo ( 6 === (int) $options_value['iloveimg_field_position'] ) ? 'checked' : ''; // @phpstan-ignore-line ?>></td>
</tr>
<tr>
<td><input type="radio" name="iloveimg_field_position" value="7" <?php echo ( 7 === $options_value['iloveimg_field_position'] ) ? 'checked' : ''; // @phpstan-ignore-line ?>></td>
<td><input type="radio" name="iloveimg_field_position" value="8" <?php echo ( 8 === $options_value['iloveimg_field_position'] ) ? 'checked' : ''; // @phpstan-ignore-line ?>></td>
<td><input type="radio" name="iloveimg_field_position" value="9" <?php echo ( 9 === $options_value['iloveimg_field_position'] ) ? 'checked' : ''; // @phpstan-ignore-line ?>></td>
<td><input type="radio" name="iloveimg_field_position" value="7" <?php echo ( 7 === (int) $options_value['iloveimg_field_position'] ) ? 'checked' : ''; // @phpstan-ignore-line ?>></td>
<td><input type="radio" name="iloveimg_field_position" value="8" <?php echo ( 8 === (int) $options_value['iloveimg_field_position'] ) ? 'checked' : ''; // @phpstan-ignore-line ?>></td>
<td><input type="radio" name="iloveimg_field_position" value="9" <?php echo ( 9 === (int) $options_value['iloveimg_field_position'] ) ? 'checked' : ''; // @phpstan-ignore-line ?>></td>
</tr>
</table>
<input type="checkbox" name="iloveimg_field_mosaic" id="iloveimg_field_mosaic" <?php echo ( isset( $options_value['iloveimg_field_mosaic'] ) ) ? 'checked' : ''; ?>>
Expand Down Expand Up @@ -250,9 +250,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 Watermark or Compress. <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_Wm_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_Wm_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_Wm_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_Wm_Resources::get_size_backup() ) ? '' : 'disabled'; ?>>Clear backup</button>
<span><?php echo (float) round( Ilove_Img_Wm_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 de18d2f

Please sign in to comment.