Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closes #728 Replace out of quota notice by upsell block #752

Merged
merged 13 commits into from
Nov 8, 2023
1 change: 1 addition & 0 deletions Tests/Unit/inc/classes/ImagifyUser/getError.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public function testShouldReturnFalseWhenFetchedUserData() {
'consumed_current_month_quota' => 123,
'next_date_update' => '',
'is_active' => 1,
'is_monthly' => true,
];

Functions\when( 'get_imagify_user' )->justReturn( $userData );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public function testShouldReturnQuotaWhenFetchedUserData() {
'consumed_current_month_quota' => 900, // Current consumed quota 90%.
'next_date_update' => '',
'is_active' => 1,
'is_monthly' => true,
];

Functions\when( 'get_imagify_user' )->justReturn( $userData );
Expand Down
3 changes: 3 additions & 0 deletions Tests/Unit/inc/classes/ImagifyUser/isOverQuota.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public function testShouldReturnFalseWhenPaidAccount() {
'consumed_current_month_quota' => 123,
'next_date_update' => '',
'is_active' => 1,
'is_monthly' => true,
];

Functions\when( 'get_imagify_user' )->justReturn( $userData );
Expand All @@ -64,6 +65,7 @@ public function testShouldReturnFalseWhenFreeNotOverQuota() {
'consumed_current_month_quota' => 900, // Current consumed quota 90%.
'next_date_update' => '',
'is_active' => 1,
'is_monthly' => true,
];

$this->createMocks( $userData, 90 );
Expand All @@ -86,6 +88,7 @@ public function testShouldReturnTrueWhenFreeOverQuota() {
'consumed_current_month_quota' => 1000, // Current consumed quota 100%.
'next_date_update' => '',
'is_active' => 1,
'is_monthly' => true,
];

$this->createMocks( $userData, 100 );
Expand Down
42 changes: 42 additions & 0 deletions assets/css/admin.css
Original file line number Diff line number Diff line change
Expand Up @@ -1543,3 +1543,45 @@ ul.imagify-datas-details.imagify-datas-details {
padding-right: 0em;
}
}

.imagify-upsell {
position:relative;
background: #c51161;
padding: 20px 40px;
}

.imagify-upsell p {
color: #fff !important;
}

.imagify-upsell-button {
display: block;
background: #fff;
border-radius: 5px;
color: #c51161 !important;
font-weight: bold;
padding: 10px;
text-align: center;
text-decoration: none;
text-transform: uppercase;
}

.imagify-upsell-arrow::after {
content: '\2192';
font-size: large;
margin-left: 5px;
vertical-align: top;
}

.imagify-upsell-dismiss::before {
position: absolute;
top: 5px;
right: 5px;
content: "\2715";
color: #2e3243;
font-size: 2em;
}

.imagify-upsell .imagify-meteo-icon {
filter: invert(100%) sepia(100%) saturate(0%) hue-rotate(104deg) brightness(103%) contrast(103%);
}
2 changes: 1 addition & 1 deletion assets/css/bulk.css
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ body[class*="_imagify-ngg-bulk-optimization"] .media-item .progress .bar {

.imagify-col-content .imagify-meteo-icon {
height: 64px;
margin: 15px 15px 15px 20px;
margin: 15px 15px 15px 0;
}

.imagify-col-content .imagify-section-title + p {
Expand Down
16 changes: 16 additions & 0 deletions assets/css/options.css
Original file line number Diff line number Diff line change
Expand Up @@ -936,3 +936,19 @@ input:checked + label .imagify-fake-checkbox:after,
margin-top: 20px;
}
}

.imagify-col-content .imagify-space-left {
margin: 15px 30px 15px 0;
}

.imagify-col-content .imagify-space-left p {
margin: 0 0 10px 0;
font-size: 19px;
font-weight: 500;
color: #343A49;
}

.imagify-col-content .imagify-meteo-icon {
height: 64px;
margin: 15px 15px 15px 0;
}
2 changes: 1 addition & 1 deletion assets/js/notices.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/
$( '.imagify-notice-dismiss' ).on( 'click.imagify', function( e ) {
var $this = $( this ),
$parent = $this.parents( '.imagify-welcome, .imagify-notice, .imagify-rkt-notice' ),
$parent = $this.parents( '.imagify-welcome, .imagify-notice, .imagify-rkt-notice, .imagify-upsell' ),
href = $this.attr( 'href' );

e.preventDefault();
Expand Down
44 changes: 2 additions & 42 deletions classes/Notices/Notices.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@ class Notices {
'http-block-external',
// This warning is displayed when the grid view is active on the library. Dismissible.
'grid-view',
// This warning is displayed to warn the user that the quota is almost consumed for the current month. Dismissible.
'almost-over-quota',
// This warning is displayed if the backup folder is not writable. NOT dismissible.
'backup-folder-not-writable',
// This notice is displayed to rate the plugin after 100 optimizations & 7 days after the first installation. Dismissible.
Expand All @@ -77,6 +75,7 @@ class Notices {
'wp-rocket',
'bulk-optimization-complete',
'bulk-optimization-running',
'upsell-banner',
];

/**
Expand Down Expand Up @@ -272,7 +271,7 @@ public function renew_almost_over_quota_notice() {

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

Expand Down Expand Up @@ -440,45 +439,6 @@ public function display_grid_view() {
return $display;
}

/**
* Tell if the 'almost-over-quota' notice should be displayed.
*
* @since 1.7.0
*
* @return bool|object An Imagify user object. False otherwise.
*/
public function display_almost_over_quota() {
remyperona marked this conversation as resolved.
Show resolved Hide resolved
static $display;

if ( isset( $display ) ) {
return $display;
}

$display = false;

if ( ! $this->user_can( 'almost-over-quota' ) ) {
return $display;
}

if ( ! imagify_is_screen( 'imagify-settings' ) && ! imagify_is_screen( 'bulk' ) ) {
return $display;
}

if ( self::notice_is_dismissed( 'almost-over-quota' ) ) {
return $display;
}

$user = new User();

// Don't display the notice if the user's unconsumed quota is superior to 20%.
if ( $user->get_percent_unconsumed_quota() > 20 ) {
return $display;
}

$display = $user;
return $display;
}

/**
* Tell if the 'backup-folder-not-writable' notice should be displayed.
*
Expand Down
26 changes: 26 additions & 0 deletions classes/User/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,13 @@ class User {
*/
public $is_active;

/**
* If the account is monthly or yearly.
*
* @var bool
*/
public $is_monthly;

/**
* Store a \WP_Error object if the request to fetch the user data failed.
* False overwise.
Expand Down Expand Up @@ -135,6 +142,7 @@ public function __construct() {
$this->consumed_current_month_quota = $user->consumed_current_month_quota;
$this->next_date_update = $user->next_date_update;
$this->is_active = $user->is_active;
$this->is_monthly = $user->is_monthly;
$this->error = false;
}

Expand Down Expand Up @@ -244,6 +252,24 @@ public function is_free() {
return 1 === $this->plan_id;
}

/**
* Check if the user is a growth account
*
* @return bool
*/
public function is_growth() {
return ( 16 === $this->plan_id || 18 === $this->plan_id );
}

/**
* Check if the user is an infinite account
*
* @return bool
*/
public function is_infinite() {
return ( 15 === $this->plan_id || 17 === $this->plan_id );
}

/**
* Check if the user has consumed all his/her quota.
*
Expand Down
39 changes: 0 additions & 39 deletions views/notice-almost-over-quota.php

This file was deleted.

62 changes: 6 additions & 56 deletions views/page-bulk.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,11 @@
<div class="imagify-col imagify-account-info-col">

<?php
if ( ( ! defined( 'IMAGIFY_HIDDEN_ACCOUNT' ) || ! IMAGIFY_HIDDEN_ACCOUNT ) && Imagify_Requirements::is_api_key_valid() ) {
$user = new User();
if (
( ! defined( 'IMAGIFY_HIDDEN_ACCOUNT' ) || ! IMAGIFY_HIDDEN_ACCOUNT )
&&
Imagify_Requirements::is_api_key_valid()
) {
?>
<div class="imagify-options-title">
<div class="imagify-th-titles imagify-flex imagify-vcenter">
Expand All @@ -100,60 +103,7 @@
</div>
<a href="<?php echo esc_url( imagify_get_external_url( 'subscription' ) ); ?>" target="_blank"><?php _e( 'View your profile', 'imagify' ); ?></a>
</div>

<?php if ( $user && 1 === $user->plan_id ) { ?>
<div class="imagify-col-content">
<div class="imagify-flex imagify-vcenter">
<span class="imagify-meteo-icon imagify-noshrink"><?php echo $this->get_quota_icon(); ?></span>
<div class="imagify-space-left imagify-full-width">

<p>
<?php
printf(
/* translators: %s is a data quota. */
__( 'You have %s space credit left', 'imagify' ),
'<span class="imagify-unconsumed-percent">' . $this->get_quota_percent() . '%</span>'
);
?>
</p>

<div class="<?php echo $this->get_quota_class(); ?>">
<div class="imagify-unconsumed-bar imagify-progress" style="width: <?php echo $this->get_quota_percent() . '%'; ?>;"></div>
</div>
</div>
</div>
<?php
/**
* Filter whether the plan chooser section is displayed.
*
* @param $show_new bool Default to true: display the section.
*/
if ( apply_filters( 'imagify_show_new_to_imagify', true ) ) {
?>
<div class="imagify-block-secondary">
<p class="imagify-section-title imagify-h3-like">
<?php
if ( ! $this->get_quota_percent() ) {
esc_html_e( 'Oops, It\'s Over!', 'imagify' );
} elseif ( $this->get_quota_percent() <= 20 ) {
esc_html_e( 'Oops, It\'s almost over!', 'imagify' );
} else {
esc_html_e( 'You\'re new to Imagify?', 'imagify' );
}
?>
</p>
<p><?php esc_html_e( 'Let us help you by analyzing your existing images and determine the best plan for you.', 'imagify' ); ?></p>

<button id="imagify-get-pricing-modal" data-nonce="<?php echo wp_create_nonce( 'imagify_get_pricing_' . get_current_user_id() ); ?>" data-target="#imagify-pricing-modal" type="button" class="imagify-modal-trigger imagify-button imagify-button-light imagify-button-big imagify-full-width">
<i class="dashicons dashicons-dashboard" aria-hidden="true"></i>
<span class="button-text"><?php _e( 'What plan do I need?', 'imagify' ); ?></span>
</button>
</div>
<?php
}
?>
</div><!-- .imagify-col-content -->
<?php } // End if(). ?>
<?php $this->print_template( 'part-upsell' ); ?>
<?php } // End if(). ?>

</div><!-- .imagify-account-info-col -->
Expand Down
Loading
Loading