Skip to content

Commit

Permalink
Closes #727 Update admin bar upsell (#754)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tabrisrp authored Nov 10, 2023
1 parent 1d202ce commit e5555a3
Show file tree
Hide file tree
Showing 7 changed files with 164 additions and 80 deletions.
37 changes: 37 additions & 0 deletions assets/css/admin-bar.css
Original file line number Diff line number Diff line change
Expand Up @@ -160,3 +160,40 @@
color: #FFF;
text-shadow: 0 0 2px rgba(0, 0, 0, 0.2);
}


#wp-admin-bar-imagify-profile .imagify-upsell-admin-bar {
position:relative ;
background: #c51161;
margin: 10px -13px -10px -13px;
padding: 20px;
}

#wp-admin-bar-imagify-profile .imagify-upsell-admin-bar p {
color: #fff;
}

#wp-admin-bar-imagify-profile a.imagify-upsell-admin-bar-button {
display: block;
height: auto !important;
border: 1px solid #fff;
border-radius: 5px;
color: #fff !important;
padding: 5px 10px !important;
text-align: center;
text-decoration: none;
margin-top: 10px;
}

#wpadminbar #wp-admin-bar-imagify-profile a.imagify-upsell-dismiss {
display: inline !important;
height: auto !important;
}

#wpadminbar #wp-admin-bar-imagify-profile .imagify-upsell-dismiss::before {
position: absolute;
top: 5px;
right: 10px;
content: "\2715";
color: #fff;
}
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, .imagify-upsell' ),
$parent = $this.parents( '.imagify-welcome, .imagify-notice, .imagify-rkt-notice, .imagify-upsell, .imagify-upsell-admin-bar' ),
href = $this.attr( 'href' );

e.preventDefault();
Expand Down
81 changes: 81 additions & 0 deletions classes/Admin/AdminBar.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?php

namespace Imagify\Admin;

use Imagify\Traits\InstanceGetterTrait;
use Imagify\User\User;
use Imagify_Views;

/**
* Admin bar handler
*/
class AdminBar {
use InstanceGetterTrait;

/**
* Launch the hooks.
*
* @return void
*/
public function init() {
if ( wp_doing_ajax() ) {
add_action( 'wp_ajax_imagify_get_admin_bar_profile', array( $this, 'get_admin_bar_profile_callback' ) );
}
}

/**
* Get admin bar profile output.
*
* @return void
*/
public function get_admin_bar_profile_callback() {
imagify_check_nonce( 'imagify-get-admin-bar-profile', 'imagifygetadminbarprofilenonce' );

if ( ! imagify_get_context( 'wp' )->current_user_can( 'manage' ) ) {
imagify_die();
}

$user = new User();
$views = Imagify_Views::get_instance();
$unconsumed_quota = $views->get_quota_percent();
$text = '';
$button_text = '';
$upgrade_link = '';

if ( $user->is_free() ) {
$text = esc_html__( 'Upgrade your plan now for more!', 'rocket' ) . '<br>' .
esc_html__( 'From $4.99/month only, keep going with image optimization!', 'rocket' );
$button_text = esc_html__( 'Upgrade My Plan', 'rocket' );
$upgrade_link = IMAGIFY_APP_DOMAIN . '/subscription/?utm_source=plugin&utm_medium=notification';
} elseif ( $user->is_growth() ) {
$text = esc_html__( 'Switch to Infinite plan for unlimited optimization:', 'rocket' ) . '<br>';

if ( $user->is_monthly ) {
$text .= esc_html__( 'For $9.99/month, optimize as many images as you like!', 'rocket' );
$upgrade_link = IMAGIFY_APP_DOMAIN . '/subscription/plan_switch/?label=infinite&payment_plan=1&utm_source=plugin&utm_medium=notification ';
} else {
$text .= esc_html__( 'For $99.9/year, optimize as many images as you like!', 'rocket' );
$upgrade_link = IMAGIFY_APP_DOMAIN . '/subscription/plan_switch/?label=infinite&payment_plan=2&utm_source=plugin&utm_medium=notification ';
}

$button_text = esc_html__( 'Switch To Infinite Plan', 'rocket' );
}

$data = [
'quota_icon' => $views->get_quota_icon(),
'quota_class' => $views->get_quota_class(),
'plan_label' => $user->plan_label,
'plan_with_quota' => $user->is_free() || $user->is_growth(),
'unconsumed_quota' => $unconsumed_quota,
'user_quota' => $user->quota,
'next_update' => $user->next_date_update,
'text' => $text,
'button_text' => $button_text,
'upgrade_link' => $upgrade_link,
];

$template = $views->get_template( 'admin/admin-bar-status', $data );

wp_send_json_success( $template );
}
}
2 changes: 2 additions & 0 deletions classes/Notices/Notices.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ class Notices {
'bulk-optimization-complete',
'bulk-optimization-running',
'upsell-banner',
'upsell-admin-bar',
];

/**
Expand Down Expand Up @@ -272,6 +273,7 @@ public function renew_almost_over_quota_notice() {
// Renew the notice for all users.
foreach ( $results as $result ) {
self::renew_notice( 'upsell-banner', $result->user_id );
self::renew_notice( 'upsell-admin-bar', $result->user_id );
}
}

Expand Down
2 changes: 2 additions & 0 deletions classes/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Imagify\CLI\BulkOptimizeCommand;
use Imagify\CLI\GenerateMissingWebpCommand;
use Imagify\Notices\Notices;
use Imagify\Admin\AdminBar;

/**
* Main plugin class.
Expand Down Expand Up @@ -56,6 +57,7 @@ class_alias( '\\Imagify\\Traits\\InstanceGetterTrait', '\\Imagify\\Traits\\FakeS
\Imagify\Job\MediaOptimization::get_instance()->init();
\Imagify\Stats\OptimizedMediaWithoutWebp::get_instance()->init();
Bulk::get_instance()->init();
AdminBar::get_instance()->init();

if ( is_admin() ) {
Notices::get_instance()->init();
Expand Down
79 changes: 0 additions & 79 deletions inc/classes/class-imagify-admin-ajax-post.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?php

use Imagify\Traits\InstanceGetterTrait;
use Imagify\User\User;

/**
* Class that handles admin ajax/post callbacks.
Expand Down Expand Up @@ -50,7 +49,6 @@ class Imagify_Admin_Ajax_Post extends Imagify_Admin_Ajax_Post_Deprecated {
// Account.
'imagify_signup',
'imagify_check_api_key_validity',
'imagify_get_admin_bar_profile',
'imagify_get_prices',
'imagify_check_coupon',
'imagify_get_discount',
Expand Down Expand Up @@ -830,83 +828,6 @@ public function imagify_check_api_key_validity_callback() {
wp_send_json_success();
}

/**
* Get admin bar profile output.
*
* @since 1.6.11
*/
public function imagify_get_admin_bar_profile_callback() {
imagify_check_nonce( 'imagify-get-admin-bar-profile', 'imagifygetadminbarprofilenonce' );

if ( ! imagify_get_context( 'wp' )->current_user_can( 'manage' ) ) {
imagify_die();
}

$user = new User();
$views = Imagify_Views::get_instance();
$unconsumed_quota = $views->get_quota_percent();
$message = '';

if ( $unconsumed_quota <= 20 ) {
$message = '<div class="imagify-error">';
$message .= '<p><i class="dashicons dashicons-warning" aria-hidden="true"></i><strong>' . __( 'Oops, It\'s almost over!', 'imagify' ) . '</strong></p>';
/* translators: %s is a line break. */
$message .= '<p>' . sprintf( __( 'You have almost used all your credit.%sDon\'t forget to upgrade your subscription to continue optimizing your images.', 'imagify' ), '<br/><br/>' ) . '</p>';
$message .= '<p class="center txt-center text-center"><a class="btn imagify-btn-ghost" href="' . esc_url( imagify_get_external_url( 'subscription' ) ) . '" target="_blank">' . __( 'View My Subscription', 'imagify' ) . '</a></p>';
$message .= '</div>';
}

if ( 0 === $unconsumed_quota ) {
$message = '<div class="imagify-error">';
$message .= '<p><i class="dashicons dashicons-warning" aria-hidden="true"></i><strong>' . __( 'Oops, It\'s Over!', 'imagify' ) . '</strong></p>';
$message .= '<p>' . sprintf(
/* translators: 1 is a data quota, 2 is a date. */
__( 'You have consumed all your credit for this month. You will have <strong>%1$s back on %2$s</strong>.', 'imagify' ),
imagify_size_format( $user->quota * pow( 1024, 2 ) ),
date_i18n( get_option( 'date_format' ), strtotime( $user->next_date_update ) )
) . '</p>';
$message .= '<p class="center txt-center text-center"><a class="btn imagify-btn-ghost" href="' . esc_url( imagify_get_external_url( 'subscription' ) ) . '" target="_blank">' . __( 'Upgrade My Subscription', 'imagify' ) . '</a></p>';
$message .= '</div>';
}

// Custom HTML.
$quota_section = '<div class="imagify-admin-bar-quota">';
$quota_section .= '<div class="imagify-abq-row">';

if ( 1 === $user->plan_id ) {
$quota_section .= '<div class="imagify-meteo-icon">' . $views->get_quota_icon() . '</div>';
}

$quota_section .= '<div class="imagify-account">';
$quota_section .= '<p class="imagify-meteo-title">' . __( 'Account status', 'imagify' ) . '</p>';
$quota_section .= '<p class="imagify-meteo-subs">' . __( 'Your subscription:', 'imagify' ) . '&nbsp;<strong class="imagify-user-plan">' . $user->plan_label . '</strong></p>';
$quota_section .= '</div>'; // .imagify-account
$quota_section .= '</div>'; // .imagify-abq-row

if ( 1 === $user->plan_id ) {
$quota_section .= '<div class="imagify-abq-row">';
$quota_section .= '<div class="imagify-space-left">';
/* translators: %s is a data quota. */
$quota_section .= '<p>' . sprintf( __( 'You have %s space credit left', 'imagify' ), '<span class="imagify-unconsumed-percent">' . $unconsumed_quota . '%</span>' ) . '</p>';
$quota_section .= '<div class="' . $views->get_quota_class() . '">';
$quota_section .= '<div style="width: ' . $unconsumed_quota . '%;" class="imagify-unconsumed-bar imagify-progress"></div>';
$quota_section .= '</div>'; // .imagify-bar-{negative|neutral|positive}
$quota_section .= '</div>'; // .imagify-space-left
$quota_section .= '</div>'; // .imagify-abq-row
}

$quota_section .= '<p class="imagify-abq-row">';
$quota_section .= '<a class="imagify-account-link" href="' . esc_url( imagify_get_external_url( 'subscription' ) ) . '" target="_blank">';
$quota_section .= '<span class="dashicons dashicons-admin-users"></span>';
$quota_section .= '<span class="button-text">' . __( 'View my subscription', 'imagify' ) . '</span>';
$quota_section .= '</a>'; // .imagify-account-link
$quota_section .= '</p>'; // .imagify-abq-row
$quota_section .= '</div>'; // .imagify-admin-bar-quota
$quota_section .= $message;

wp_send_json_success( $quota_section );
}

/**
* Get pricings from API for Onetime and Plans at the same time.
*
Expand Down
41 changes: 41 additions & 0 deletions views/admin/admin-bar-status.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php
defined( 'ABSPATH' ) || die( 'Cheatin’ uh?' );
?>

<div class="imagify-admin-bar-quota">
<div class="imagify-abq-row">
<?php if ( $data['plan_with_quota'] ) : ?>
<div class="imagify-meteo-icon"><?php echo $data['quota_icon']; ?></div>
<?php endif; ?>
<div class="imagify-account">
<p class="imagify-meteo-title"><?php esc_html_e( 'Account status', 'imagify' ); ?></p>
<p class="imagify-meteo-subs"><?php esc_html_e( 'Your subscription:', 'imagify' ); ?> &nbsp;<strong class="imagify-user-plan"><?php echo $data['plan_label']; ?></strong></p>
</div>
</div>
<?php if ( $data['plan_with_quota'] ) : ?>
<div class="imagify-abq-row">
<div class="imagify-space-left">
<p><?php
printf(
// translators: %s = percentage.
__( 'You have %s space credit left', 'imagify' ), '<span class="imagify-unconsumed-percent">' . $data['unconsumed_quota'] . '%</span>' );
?></p>
<div class="<?php echo esc_attr( $data['quota_class'] ); ?>">
<div style="width: <?php echo esc_attr( $data['unconsumed_quota'] ); ?>%;" class="imagify-unconsumed-bar imagify-progress"></div>
</div>
</div>
</div>
<?php endif; ?>
<?php if ( $data['plan_with_quota'] && $data['unconsumed_quota'] <= 20 ) : ?>
<div class="imagify-upsell-admin-bar">
<?php if ( $data['unconsumed_quota'] <= 20 ) : ?>
<p><i class="dashicons dashicons-warning" aria-hidden="true"></i><strong><?php esc_html_e( 'Oops, It\'s almost over!', 'imagify' ); ?></strong></p>
<?php elseif ( 0 === $data['unconsumed_quota'] ) : ?>
<p><i class="dashicons dashicons-warning" aria-hidden="true"></i><strong><?php esc_html_e( 'Oops, It\'s Over!', 'imagify' ); ?></strong></p>
<?php endif; ?>
<p><?php echo $data['text']; ?></p>
<p class="center txt-center text-center"><a class="imagify-upsell-admin-bar-button" href="<?php echo esc_url( $data['upgrade_link'] ); ?>" target="_blank"><?php echo $data['button_text']; ?></a></p>
<a href="<?php echo esc_url( get_imagify_admin_url( 'dismiss-notice', 'upsell-admin-bar' ) ); ?>" 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>
<?php endif; ?>
</div>

0 comments on commit e5555a3

Please sign in to comment.