Skip to content

Commit

Permalink
update notice renewal
Browse files Browse the repository at this point in the history
  • Loading branch information
remyperona committed Nov 6, 2023
1 parent 1f9facb commit 35f0a72
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 15 deletions.
33 changes: 33 additions & 0 deletions classes/Notices/Notices.php
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,39 @@ public function deactivate_plugin() {
wp_send_json_success();
}

/**
* Renew the "almost-over-quota" notice when the consumed quota percent decreases back below 80%.
*
* @since 1.7
*/
public function renew_almost_over_quota_notice() {
global $wpdb;

$results = $wpdb->get_results( $wpdb->prepare( "SELECT umeta_id, user_id FROM $wpdb->usermeta WHERE meta_key = %s AND meta_value LIKE %s", self::DISMISS_META_NAME, '%almost-over-quota%' ) );

if ( ! $results ) {
return;
}

// Prevent multiple queries to the DB by caching user metas.
$not_cached = [];

foreach ( $results as $result ) {
if ( ! wp_cache_get( $result->umeta_id, 'user_meta' ) ) {
$not_cached[] = $result->umeta_id;
}
}

if ( $not_cached ) {
update_meta_cache( 'user', $not_cached );
}

// Renew the notice for all users.
foreach ( $results as $result ) {
self::renew_notice( 'upsell-banner', $result->user_id );
}
}


/** ----------------------------------------------------------------------------------------- */
/** NOTICES ================================================================================= */
Expand Down
17 changes: 2 additions & 15 deletions views/part-upsell.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,6 @@
$notices = get_user_meta( $user_id, '_imagify_ignore_notices', true );
$notices = $notices && is_array( $notices ) ? array_flip( $notices ) : [];

if (
$unconsumed_quota > 20
&&
isset( $notices['upsell-banner'] )
) {
unset( $notices['upsell-banner'] );
$notices = array_flip( $notices );
$notices = array_filter( $notices );
$notices = array_values( $notices );

update_user_meta( $user_id, '_imagify_ignore_notices', $notices );
}

if (
Imagify_Requirements::is_api_key_valid()
&&
Expand Down Expand Up @@ -62,7 +49,7 @@
$price = esc_html__( 'From $4.99/month only, keep going with image optimization!', 'imagify' );
$upgrade_link = IMAGIFY_APP_DOMAIN . '/subscription/?utm_source=plugin&utm_medium=upsell_banner';
} elseif ( $imagify_user->is_growth() ) {
$upgrade = esc_esc_html__html_e( 'Upgrade your plan now to keep optimizing your images.', 'imagify' );
$upgrade = esc_html__( 'Upgrade your plan now to keep optimizing your images.', 'imagify' );

if ( $imagify_user->is_monthly ) {
$price = esc_html__( 'For $9.99/month only, choose unlimited image optimization!', 'imagify' );
Expand All @@ -77,7 +64,7 @@
<p><?php echo $price; ?></p>

<a href="<?php echo esc_url( $upgrade_link ); ?>" target="_blank" rel="noopener noreferrer" class="imagify-upsell-button"><span class="imagify-upsell-arrow"><?php esc_html_e( 'Upgrade now', 'imagify' ); ?></span></a>
<a href="<?php echo esc_url( get_imagify_admin_url( 'dismiss-notice', 'upsell-banner' ) ); ?>" class="imagify-notice-dismiss imagify-upsell-dismiss" title="<?php esc_attr_e( 'Dismiss this notice', 'imagify' ); ?>"><span class="screen-reader-text"><?php _e( 'Dismiss this notice', 'imagify' ); ?></span></a>
<a href="<?php echo esc_url( get_imagify_admin_url( 'dismiss-notice', 'upsell-banner' ) ); ?>" class="imagify-notice-dismiss imagify-upsell-dismiss" title="<?php esc_attr_e( 'Dismiss this notice', 'imagify' ); ?>"><span class="screen-reader-text"><?php esc_html_e( 'Dismiss this notice', 'imagify' ); ?></span></a>
</div><!-- .imagify-col-content -->
<?php
}
Expand Down

0 comments on commit 35f0a72

Please sign in to comment.