Skip to content

Commit

Permalink
2.2.2
Browse files Browse the repository at this point in the history
  • Loading branch information
remyperona authored Apr 23, 2024
2 parents 4f51e4e + 16bceab commit 33e23dd
Show file tree
Hide file tree
Showing 20 changed files with 214 additions and 56 deletions.
7 changes: 7 additions & 0 deletions assets/css/admin.css
Original file line number Diff line number Diff line change
Expand Up @@ -908,6 +908,7 @@ p.imagify-section-title.imagify-section-title {
z-index: 2;
-webkit-transition: all .275s;
transition: all .275s;
cursor: pointer;
}

.imagify-inline-options input[type="radio"]:not(:checked) + label:first-of-type,
Expand All @@ -924,6 +925,12 @@ p.imagify-section-title.imagify-section-title {
background: #8BC34A
}

.imagify-inline-options input[type="radio"]:disabled + label {
background: #ccc;
color: #999;
cursor:not-allowed;
}

.imagify-inline-options .imagify-info {
margin-top: 15px;
}
Expand Down
2 changes: 1 addition & 1 deletion assets/css/admin.min.css

Large diffs are not rendered by default.

20 changes: 17 additions & 3 deletions assets/css/options.css
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,22 @@ p.imagify-api-key-invite-title {
align-items: center;
}

.imagify-setting-optim-level {
padding: 8px 0 18px;
}
.imagify-setting-optim-level > p {
margin: 0;
}

.imagify-setting-optim-level .imagify-info {
margin-top: 10px;
}

.imagify-setting-optim-level .imagify-error {
margin: 10px 0 0 0;
}

.imagify-setting-optim-level .imagify-error a {
color: #fff;
}

.imagify-setting-optim-level .imagify-inline-options {
flex-basis: 60%;
flex-grow: 1;
Expand All @@ -141,6 +151,10 @@ p.imagify-api-key-invite-title {
background: #2E3243;
border-radius: 3px;
}
.imagify-setting-optim-level .imagify-inline-options-error {
background: #ccc;
}

.imagify-setting-optim-level .imagify-inline-options label {
display: block !important;
width: 100%;
Expand Down
2 changes: 1 addition & 1 deletion assets/css/options.min.css

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions classes/Bulk/AbstractBulk.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,10 @@ function_exists( 'set_time_limit' )
* @return int The number of media.
*/
public function has_optimized_media_without_nextgen() {
$format = 'webp';
$format = get_imagify_option( 'optimization_format' );

if ( get_imagify_option( 'convert_to_avif' ) ) {
$format = 'avif';
if ( 'off' === $format ) {
return 0;
}

return count( $this->get_optimized_media_ids_without_format( $format )['ids'] );
Expand Down
11 changes: 10 additions & 1 deletion classes/Bulk/Bulk.php
Original file line number Diff line number Diff line change
Expand Up @@ -586,11 +586,20 @@ public function bulk_get_stats_callback() {
* @return void
*/
public function maybe_generate_missing_nextgen( $old_value, $value ) {
if ( empty( $old_value['convert_to_avif'] ) === empty( $value['convert_to_avif'] ) ) {
if ( ! isset( $old_value['optimization_format'], $value['optimization_format'] ) ) {
return;
}

if ( $old_value['optimization_format'] === $value['optimization_format'] ) {
// Old value = new value so do nothing.
return;
}

if ( 'off' === $value['optimization_format'] ) {
// No need to generate next-gen images.
return;
}

$contexts = $this->get_contexts();
$formats = imagify_nextgen_images_formats();

Expand Down
6 changes: 3 additions & 3 deletions classes/Imagifybeat/Actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,10 @@ public function add_options_optimization_status_to_response( $response, $data )

$bulk = Bulk::get_instance();

$format = 'webp';
$format = get_imagify_option( 'optimization_format' );

if ( get_imagify_option( 'convert_to_avif' ) ) {
$format = 'avif';
if ( 'off' === $format ) {
return $response;
}

foreach ( $data[ $imagifybeat_id ] as $context ) {
Expand Down
5 changes: 2 additions & 3 deletions classes/Optimization/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -745,10 +745,9 @@ public function get_mime_type() {
/**
* Get the file extension.
*
* @since 1.9
* @author Grégory Viguier
* @since 1.9
*
* @return string|null
* @return string|false
*/
public function get_extension() {
return $this->get_file_type()->ext;
Expand Down
18 changes: 15 additions & 3 deletions classes/Optimization/Process/AbstractProcess.php
Original file line number Diff line number Diff line change
Expand Up @@ -581,11 +581,21 @@ public function optimize_size( $size, $optimization_level = null ) {
// This file type is not supported.
$extension = $file->get_extension();

if ( '' === $extension ) {
if ( ! $extension ) {
$response = new WP_Error(
'extension_not_mime',
__( 'This file has an extension that does not match a mime type.', 'imagify' )
);
} elseif ( '' === $extension ) {
$response = new WP_Error(
'no_extension',
__( 'With no extension, this file cannot be optimized.', 'imagify' )
);
} elseif ( ! $extension ) {
$response = new WP_Error(
'extension_not_mime',
__( 'This file has an extension that does not match a mime type.', 'imagify' )
);
} else {
$response = new WP_Error(
'extension_not_supported',
Expand Down Expand Up @@ -1532,7 +1542,9 @@ protected function delete_file( string $next_gen_path ) {
* @return string Current format we are targeting.
*/
public function get_current_format() {
return $this->get_option( 'convert_to_avif' ) ? static::AVIF_SUFFIX : static::WEBP_SUFFIX;
$format = get_imagify_option( 'optimization_format' );

return ( 'avif' === $format ) ? static::AVIF_SUFFIX : static::WEBP_SUFFIX;
}

/**
Expand All @@ -1551,7 +1563,7 @@ public function is_size_next_gen( $size_name ) {
foreach ( $formats as $format ) {
$suffix = preg_quote( $this->get_suffix_from_format( $format ), '/' );

if ( preg_match( '/^(?<size>.+)' . $suffix . '$/', $size_name, $matches ) ) {
if ( preg_match( '/^(?<size>.+)' . $suffix . '$/', (string) $size_name, $matches ) ) {
return $matches['size'];
}
}
Expand Down
10 changes: 5 additions & 5 deletions classes/Stats/OptimizedMediaWithoutNextGen.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public function maybe_clear_cache_after_optimization( $process, $item ) {
$new_sizes = array_intersect_key( $sizes, $new_sizes );
$size_name = 'full' . $process::WEBP_SUFFIX;

if ( get_imagify_option( 'convert_to_avif' ) ) {
if ( 'avif' === get_imagify_option( 'optimization_format' ) ) {
$size_name = 'full' . $process::AVIF_SUFFIX;
}

Expand Down Expand Up @@ -147,7 +147,7 @@ public function maybe_clear_cache_after_restoration( $process, $response, $files
$sizes = isset( $data['sizes'] ) ? (array) $data['sizes'] : [];
$size_name = 'full' . $process::WEBP_SUFFIX;

if ( get_imagify_option( 'convert_to_avif' ) ) {
if ( 'avif' === get_imagify_option( 'optimization_format' ) ) {
$size_name = 'full' . $process::AVIF_SUFFIX;
}

Expand Down Expand Up @@ -175,7 +175,7 @@ public function maybe_clear_cache_on_deletion( $process ) {
$sizes = isset( $data['sizes'] ) ? (array) $data['sizes'] : [];
$size_name = 'full' . $process::WEBP_SUFFIX;

if ( get_imagify_option( 'convert_to_avif' ) ) {
if ( 'avif' === get_imagify_option( 'optimization_format' ) ) {
$size_name = 'full' . $process::AVIF_SUFFIX;
}

Expand All @@ -198,11 +198,11 @@ public function maybe_clear_cache_on_deletion( $process ) {
* @return void
*/
public function maybe_clear_stat_cache( $old_value, $value ) {
if ( isset( $old_value['convert_to_avif'] ) && isset( $value['convert_to_avif'] ) ) {
if ( ! isset( $old_value['optimization_format'], $value['optimization_format'] ) ) {
return;
}

if ( ! isset( $old_value['convert_to_avif'] ) && ! isset( $value['convert_to_avif'] ) ) {
if ( $old_value['optimization_format'] === $value['optimization_format'] ) {
return;
}

Expand Down
4 changes: 2 additions & 2 deletions imagify.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Plugin Name: Imagify
* Plugin URI: https://wordpress.org/plugins/imagify/
* Description: Dramatically reduce image file sizes without losing quality, make your website load faster, boost your SEO and save money on your bandwidth using Imagify, the new most advanced image optimization tool.
* Version: 2.2.1
* Version: 2.2.2
* Requires at least: 5.3
* Requires PHP: 7.3
* Author: Imagify – Optimize Images & Convert WebP & Avif
Expand All @@ -19,7 +19,7 @@
defined( 'ABSPATH' ) || die( 'Cheatin’ uh?' );

// Imagify defines.
define( 'IMAGIFY_VERSION', '2.2.1' );
define( 'IMAGIFY_VERSION', '2.2.2' );
define( 'IMAGIFY_SLUG', 'imagify' );
define( 'IMAGIFY_FILE', __FILE__ );
define( 'IMAGIFY_PATH', realpath( plugin_dir_path( IMAGIFY_FILE ) ) . '/' );
Expand Down
4 changes: 2 additions & 2 deletions inc/3rd-party/nextgen-gallery/classes/Bulk/NGG.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public function get_optimized_media_ids_without_format( $format ) {
$data_table = DB::get_instance()->get_table_name();
$suffix = constant( imagify_get_optimization_process_class_name( 'ngg' ) . '::WEBP_SUFFIX' );

if ( get_imagify_option( 'convert_to_avif' ) ) {
if ( 'avif' === get_imagify_option( 'optimization_format' ) ) {
$suffix = constant( imagify_get_optimization_process_class_name( 'ngg' ) . '::AVIF_SUFFIX' );
}

Expand Down Expand Up @@ -194,7 +194,7 @@ public function has_optimized_media_without_nextgen() {
$data_table = DB::get_instance()->get_table_name();
$suffix = constant( imagify_get_optimization_process_class_name( 'ngg' ) . '::WEBP_SUFFIX' );

if ( get_imagify_option( 'convert_to_avif' ) ) {
if ( 'avif' === get_imagify_option( 'optimization_format' ) ) {
$suffix = constant( imagify_get_optimization_process_class_name( 'ngg' ) . '::AVIF_SUFFIX' );
}

Expand Down
16 changes: 12 additions & 4 deletions inc/admin/upgrader.php
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ function _imagify_new_upgrade( $network_version, $site_version ) {

// 1.8.2
if ( version_compare( $site_version, '1.8.2' ) < 0 ) {
Imagify_Options::get_instance()->set( 'partner_links', 1 );
$options->set( 'partner_links', 1 );
}

// 1.9.6
Expand All @@ -305,12 +305,20 @@ function _imagify_new_upgrade( $network_version, $site_version ) {
}

if ( version_compare( $site_version, '2.0' ) < 0 ) {
Imagify_Options::get_instance()->set( 'optimization_level', 2 );
$options->set( 'optimization_level', 2 );
}

if ( version_compare( $site_version, '2.2' ) < 0 ) {
Imagify_Options::get_instance()->set( 'display_nextgen', Imagify_Options::get_instance()->get( 'display_webp', 0 ) );
Imagify_Options::get_instance()->set( 'display_nextgen_method', Imagify_Options::get_instance()->get( 'display_webp_method' ) );
$options->set( 'display_nextgen', $options->get( 'display_webp', 0 ) );
$options->set( 'display_nextgen_method', $options->get( 'display_webp_method' ) );
}

if ( version_compare( $site_version, '2.2.2', '<' ) ) {
if ( $options->get( 'convert_to_avif' ) ) {
$options->set( 'optimization_format', 'avif' );
} else {
$options->set( 'optimization_format', 'webp' );
}
}
}
add_action( 'imagify_upgrade', '_imagify_new_upgrade', 10, 2 );
Expand Down
4 changes: 4 additions & 0 deletions inc/classes/class-imagify-files-list-table.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
<?php
defined( 'ABSPATH' ) || die( 'Cheatin’ uh?' );

if ( ! class_exists( 'WP_List_Table' ) ) {
require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
}

/**
* Class that display the "custom folders" files.
*
Expand Down
13 changes: 8 additions & 5 deletions inc/classes/class-imagify-options.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class Imagify_Options extends Imagify_Abstract_Options {
'partner_links' => 0,
'convert_to_avif' => 0,
'convert_to_webp' => 0,
'optimization_format' => 'webp',
];

/**
Expand Down Expand Up @@ -96,10 +97,6 @@ protected function __construct() {
parent::__construct();
}

/** ----------------------------------------------------------------------------------------- */
/** SANITIZATION, VALIDATION ================================================================ */
/** ----------------------------------------------------------------------------------------- */

/**
* Sanitize and validate an option value. Basic casts have been made.
*
Expand Down Expand Up @@ -127,7 +124,13 @@ public function sanitize_and_validate_value( $key, $value, $default ) {
return $reset_values[ $key ];
}
return $value;

case 'optimization_format':
if ( ! in_array( $value, [ 'off', 'webp', 'avif' ], true ) ) {
// For an invalid value, return the "reset" value.
$reset_values = $this->get_reset_values();
return $reset_values[ $key ];
}
return $value;
case 'auto_optimize':
case 'backup':
case 'lossless':
Expand Down
68 changes: 68 additions & 0 deletions inc/classes/class-imagify-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,74 @@ public function field_radio_list( $args ) {
<?php
}

/**
* Display styled radio list group.
*
* @param array $args Arguments:
* {option_name} string The option name. E.g. 'disallowed-sizes'. Mandatory.
* {values} array List of values to display, in the form of 'value' => 'Label'. Mandatory.
* {attributes} array A list of HTML attributes, as 'attribute' => 'value'.
* {current_value} int|bool USE ONLY WHEN DEALING WITH DATA THAT IS NOT SAVED IN THE PLUGIN OPTIONS. If not provided, the field will automatically get the value from the options.
*
* @return void
*/
public function field_inline_radio_list( $args ) {
$args = array_merge(
[
'option_name' => '',
'values' => [],
'info' => '',
'attributes' => [],
'current_value' => false,
],
$args
);

if ( ! $args['option_name'] || ! $args['values'] ) {
return;
}

if ( is_numeric( $args['current_value'] ) || is_string( $args['current_value'] ) ) {
$current_value = $args['current_value'];
} else {
$current_value = $this->options->get( $args['option_name'] );
}

$option_name_class = sanitize_html_class( $args['option_name'] );
$attributes = array_merge( [
'name' => $this->option_name . '[' . $args['option_name'] . ']',
'id' => 'imagify_' . $option_name_class . '_%s',
'class' => 'imagify-row-radio',
], $args['attributes'] );

$id_attribute = $attributes['id'];
unset( $attributes['id'] );
$args['attributes'] = self::build_attributes( $attributes );
?>
<div class="imagify-setting-optim-level">
<p class="imagify-inline-options imagify-inline-options-<?php echo esc_attr( $args['info_class'] ); ?>">
<?php
foreach ( $args['values'] as $value => $label ) {
$input_id = sprintf( $id_attribute, sanitize_html_class( $value ) );
?>
<input type="radio" value="<?php echo esc_attr( $value ); ?>" id="<?php echo $input_id; ?>"<?php echo $args['attributes']; ?> <?php checked( $current_value, $value ); ?> />
<label for="<?php echo $input_id; ?>" onclick=""><?php echo $label; ?></label>
<?php
}
?>
</p>
<span id="<?php
echo $attributes['aria-describedby'];
?>" class="imagify-<?php echo esc_attr( $args['info_class'] ); ?>">
<span class="dashicons dashicons-info"></span>
<?php
echo $args['info'];
?>
</span>
</div>
<?php
}

/**
* Display a text box.
*
Expand Down
Loading

0 comments on commit 33e23dd

Please sign in to comment.