Skip to content

Commit

Permalink
Cache attachments number count in payment modal for one day (PR #920)
Browse files Browse the repository at this point in the history
Co-authored-by: WordPressFan <[email protected]>
  • Loading branch information
remyperona and wordpressfan authored Nov 13, 2024
1 parent 9c12b1a commit 4597689
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 9 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,9 @@ When the plugin is disabled, your existing images remain optimized. Backups of t
Please report security bugs found in the site-reviews plugin's source code through the [Patchstack Vulnerability Disclosure Program](https://patchstack.com/database/vdp/imagify). The Patchstack team will assist you with verification, CVE assignment and take care of notifying the developers of this plugin.

## Changelog
### 2.2.3.2
- Enhancement: Optimize and cache the modal attachment counter database query.

### 2.2.3.1
- Enhancement: Decrease the amount of requests to imagify servers.

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.3.1
* Version: 2.2.3.2
* Requires at least: 5.3
* Requires PHP: 7.3
* Author: Imagify Image Optimizer – Optimize Images & Convert WebP & Avif
Expand All @@ -19,7 +19,7 @@
defined( 'ABSPATH' ) || die( 'Cheatin’ uh?' );

// Imagify defines.
define( 'IMAGIFY_VERSION', '2.2.3' );
define( 'IMAGIFY_VERSION', '2.2.3.2' );
define( 'IMAGIFY_SLUG', 'imagify' );
define( 'IMAGIFY_FILE', __FILE__ );
define( 'IMAGIFY_PATH', realpath( plugin_dir_path( IMAGIFY_FILE ) ) . '/' );
Expand Down
26 changes: 25 additions & 1 deletion inc/classes/class-imagify-views.php
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,31 @@ public function print_js_templates() {
* Print the payment modal.
*/
public function print_modal_payment() {
$this->print_template( 'modal-payment' );
$this->print_template(
'modal-payment',
[
'attachments_number' => $this->get_attachments_number_modal(),
]
);
}

/**
* Get the number of attachments to display in the payment modal.
*
* @return int
*/
private function get_attachments_number_modal() {
$transient = get_transient( 'imagify_attachments_number_modal' );

if ( false !== $transient ) {
return $transient;
}

$attachments_number = imagify_count_attachments() + Imagify_Files_Stats::count_all_files();

set_transient( 'imagify_attachments_number_modal', $attachments_number, 1 * DAY_IN_SECONDS );

return $attachments_number;
}

/** ----------------------------------------------------------------------------------------- */
Expand Down
7 changes: 5 additions & 2 deletions readme.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
=== Imagify – Optimize Images & Convert WebP & AVIF | Compress Images Easily ===
Contributors: wp_rocket, imagify
Tags: optimize images, image optimization, compress images, convert webp, convert AVIF
Tested up to: 6.6
Stable tag: 2.2.3.1
Tested up to: 6.7
Stable tag: 2.2.3.2
Requires PHP: 7.3
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Expand Down Expand Up @@ -266,6 +266,9 @@ You can report any security bugs found in the source code of the site-reviews pl
4. Other Media Page

== Changelog ==
= 2.2.3.2 =
- Enhancement: Optimize and cache the modal attachment counter database query.

= 2.2.3.1 =
- Enhancement: Decrease the amount of requests to imagify servers.

Expand Down
2 changes: 2 additions & 0 deletions uninstall.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
delete_transient( 'imagify_max_image_size' );
delete_transient( 'imagify_user' );
delete_transient( 'imagify_stat_without_next_gen' );
delete_transient( 'imagify_attachments_number_modal' );
delete_transient( 'imagify_user_cache' );

// Delete transients.
$transients = implode( '" OR option_name LIKE "', array(
Expand Down
6 changes: 2 additions & 4 deletions views/modal-payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,10 @@
<p>
<span class="imagify-border-styled">
<?php
$attachments_number = imagify_count_attachments() + Imagify_Files_Stats::count_all_files();

printf(
/* translators: %s is a formatted number (don't use %d). */
_n( 'You have %s original image', 'You have %s original images', $attachments_number, 'imagify' ),
'</span><span class="imagify-big-number">' . number_format_i18n( $attachments_number ) . '</span><span class="imagify-border-styled">'
_n( 'You have %s original image', 'You have %s original images', $data['attachments_number'], 'imagify' ),
'</span><span class="imagify-big-number">' . number_format_i18n( $data['attachments_number'] ) . '</span><span class="imagify-border-styled">'
);
?>
</span>
Expand Down

0 comments on commit 4597689

Please sign in to comment.