-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
7 changed files
with
164 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' ); ?> <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> |