diff --git a/assets/css/admin-bar.css b/assets/css/admin-bar.css index 6d299ac0..22c460d7 100755 --- a/assets/css/admin-bar.css +++ b/assets/css/admin-bar.css @@ -61,11 +61,10 @@ } #wpadminbar #wp-admin-bar-imagify-profile .ab-item { height: auto; - padding: 0 13px; + padding: 0; } #wpadminbar #wp-admin-bar-imagify-profile { min-width: 200px; - padding: 15px 0 10px; margin-top: 0.7em; background: #222; } @@ -200,3 +199,24 @@ color: #6f9c3b; font-weight: 600; } + +#wpadminbar #wp-admin-bar-imagify-upgrade-plan .ab-empty-item { + padding: 0; +} + +#wpadminbar .imagify-admin-bar-upgrade-plan { + background: #8bc34a; + box-sizing: border-box; + border:none; + color: #fff; + cursor: pointer; + display: block; + font-weight: bold !important; + padding: 0 10px; + text-align: left; + width: 100% !important; +} + +#wpadminbar #wp-admin-bar-imagify-profile .imagify-admin-bar-quota { + padding: 13px 15px; +} diff --git a/assets/css/admin-bar.min.css b/assets/css/admin-bar.min.css index 88e6e808..2e742e2b 100755 --- a/assets/css/admin-bar.min.css +++ b/assets/css/admin-bar.min.css @@ -1 +1 @@ -.imagify-account,.imagify-account-link{padding-right:15px}.imagify-meteo-icon{display:inline-block;height:38px;vertical-align:middle;margin-right:10px}.imagify-user-plan{color:#40b1d0}.imagify-meteo-title.imagify-meteo-title{color:#fff;font-size:17px}.imagify-space-left>p{color:#fff}#wp-admin-bar-imagify-profile [class^=imagify-bar-]{position:relative;height:1.5em;width:100%;background:#60758d;color:#fff;font-size:10px}#wp-admin-bar-imagify-profile .imagify-progress{height:1.5em;font-size:1em}.imagify-progress{-webkit-transition:width .3s;-o-transition:width .3s;transition:width .3s}.imagify-bar-positive .imagify-progress{background:#8cc152}.imagify-bar-positive .imagify-barnb{color:#8cc152}.imagify-bar-negative .imagify-progress{background:#73818c}.imagify-bar-negative .imagify-barnb{color:#73818c}.imagify-bar-neutral .imagify-progress{background:#f5a623}.imagify-space-left .imagify-bar-negative .imagify-progress{background:#d0021b}#wpadminbar #wp-admin-bar-imagify-profile *{line-height:1.5;white-space:initial}#wpadminbar #wp-admin-bar-imagify .ab-submenu{padding-bottom:0}#wpadminbar #wp-admin-bar-imagify-profile .ab-item{height:auto;padding:0 13px}#wpadminbar #wp-admin-bar-imagify-profile{min-width:200px;padding:15px 0 10px;margin-top:.7em;background:#222}#wp-admin-bar-imagify .dashicons{font-family:dashicons;font-size:18px;vertical-align:middle;margin:0 5px 0 0}#wp-admin-bar-imagify .button-text{display:inline-block;vertical-align:middle}#wp-admin-bar-imagify .imagify-abq-row{display:table;width:100%}#wp-admin-bar-imagify .imagify-abq-row+.imagify-abq-row{margin-top:.75em}#wp-admin-bar-imagify .imagify-abq-row>*{display:table-cell}#wp-admin-bar-imagify-profile .imagify-meteo-icon{padding-right:7px}#wp-admin-bar-imagify-profile .imagify-meteo-icon img{width:37px}#wp-admin-bar-imagify-profile .imagify-meteo-title{font-size:17px}#wp-admin-bar-imagify-profile .imagify-meteo-subs{color:#72889f}#wpadminbar #wp-admin-bar-imagify-profile strong{font-weight:700}#wpadminbar #wp-admin-bar-imagify-profile .imagify-user-plan,#wpadminbar #wp-admin-bar-imagify-profile a{padding:0;color:#40b1d0}#wpadminbar #wp-admin-bar-imagify-profile .imagify-account-link{display:table}#wpadminbar #wp-admin-bar-imagify-profile .imagify-account-link>*{display:table-cell}#wpadminbar #wp-admin-bar-imagify-profile .imagify-space-left{max-width:210px;min-width:210px;width:210px}#wpadminbar #wp-admin-bar-imagify-profile .imagify-space-left p{font-size:12px}#wp-admin-bar-imagify-profile .imagify-error,#wp-admin-bar-imagify-profile .imagify-warning{padding:10px;margin:0 -13px -13px}#wp-admin-bar-imagify-profile .imagify-error p+p,#wp-admin-bar-imagify-profile .imagify-warning p+p{margin-top:.5em}#wp-admin-bar-imagify-profile .imagify-error p+p+p,#wp-admin-bar-imagify-profile .imagify-warning p+p+p{margin-top:1em}#wpadminbar #wp-admin-bar-imagify-profile .imagify-btn-ghost{display:inline-block;height:auto;padding:7px 10px;border:1px solid #fff;text-align:center;background:0 0;color:#fff;border-radius:3px;-webkit-transition:all .275s;-o-transition:all .275s;transition:all .275s}#wpadminbar #wp-admin-bar-imagify-profile .imagify-btn-ghost:focus,#wpadminbar #wp-admin-bar-imagify-profile .imagify-btn-ghost:hover{background:#fff;color:#888}#wpadminbar .imagify-warning *{background:#f5a623;color:#fff;text-shadow:0 0 2px rgba(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:5px;color:#fff}.imagify-plugin-upgrade{color:#6f9c3b;font-weight:600} \ No newline at end of file +.imagify-account,.imagify-account-link{padding-right:15px}.imagify-meteo-icon{display:inline-block;height:38px;vertical-align:middle;margin-right:10px}.imagify-user-plan{color:#40b1d0}.imagify-meteo-title.imagify-meteo-title{color:#fff;font-size:17px}.imagify-space-left>p{color:#fff}#wp-admin-bar-imagify-profile [class^=imagify-bar-]{position:relative;height:1.5em;width:100%;background:#60758d;color:#fff;font-size:10px}#wp-admin-bar-imagify-profile .imagify-progress{height:1.5em;font-size:1em}.imagify-progress{-webkit-transition:width .3s;-o-transition:width .3s;transition:width .3s}.imagify-bar-positive .imagify-progress{background:#8cc152}.imagify-bar-positive .imagify-barnb{color:#8cc152}.imagify-bar-negative .imagify-progress{background:#73818c}.imagify-bar-negative .imagify-barnb{color:#73818c}.imagify-bar-neutral .imagify-progress{background:#f5a623}.imagify-space-left .imagify-bar-negative .imagify-progress{background:#d0021b}#wpadminbar #wp-admin-bar-imagify-profile *{line-height:1.5;white-space:initial}#wpadminbar #wp-admin-bar-imagify .ab-submenu{padding-bottom:0}#wpadminbar #wp-admin-bar-imagify-profile .ab-item{height:auto;padding:0}#wpadminbar #wp-admin-bar-imagify-profile{min-width:200px;margin-top:.7em;background:#222}#wp-admin-bar-imagify .dashicons{font-family:dashicons;font-size:18px;vertical-align:middle;margin:0 5px 0 0}#wp-admin-bar-imagify .button-text{display:inline-block;vertical-align:middle}#wp-admin-bar-imagify .imagify-abq-row{display:table;width:100%}#wp-admin-bar-imagify .imagify-abq-row+.imagify-abq-row{margin-top:.75em}#wp-admin-bar-imagify .imagify-abq-row>*{display:table-cell}#wp-admin-bar-imagify-profile .imagify-meteo-icon{padding-right:7px}#wp-admin-bar-imagify-profile .imagify-meteo-icon img{width:37px}#wp-admin-bar-imagify-profile .imagify-meteo-title{font-size:17px}#wp-admin-bar-imagify-profile .imagify-meteo-subs{color:#72889f}#wpadminbar #wp-admin-bar-imagify-profile strong{font-weight:700}#wpadminbar #wp-admin-bar-imagify-profile .imagify-user-plan,#wpadminbar #wp-admin-bar-imagify-profile a{padding:0;color:#40b1d0}#wpadminbar #wp-admin-bar-imagify-profile .imagify-account-link{display:table}#wpadminbar #wp-admin-bar-imagify-profile .imagify-account-link>*{display:table-cell}#wpadminbar #wp-admin-bar-imagify-profile .imagify-space-left{max-width:210px;min-width:210px;width:210px}#wpadminbar #wp-admin-bar-imagify-profile .imagify-space-left p{font-size:12px}#wp-admin-bar-imagify-profile .imagify-error,#wp-admin-bar-imagify-profile .imagify-warning{padding:10px;margin:0 -13px -13px}#wp-admin-bar-imagify-profile .imagify-error p+p,#wp-admin-bar-imagify-profile .imagify-warning p+p{margin-top:.5em}#wp-admin-bar-imagify-profile .imagify-error p+p+p,#wp-admin-bar-imagify-profile .imagify-warning p+p+p{margin-top:1em}#wpadminbar #wp-admin-bar-imagify-profile .imagify-btn-ghost{display:inline-block;height:auto;padding:7px 10px;border:1px solid #fff;text-align:center;background:0 0;color:#fff;border-radius:3px;-webkit-transition:all .275s;-o-transition:all .275s;transition:all .275s}#wpadminbar #wp-admin-bar-imagify-profile .imagify-btn-ghost:focus,#wpadminbar #wp-admin-bar-imagify-profile .imagify-btn-ghost:hover{background:#fff;color:#888}#wpadminbar .imagify-warning *{background:#f5a623;color:#fff;text-shadow:0 0 2px rgba(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:5px;color:#fff}.imagify-plugin-upgrade{color:#6f9c3b;font-weight:600}#wpadminbar #wp-admin-bar-imagify-upgrade-plan .ab-empty-item{padding:0}#wpadminbar .imagify-admin-bar-upgrade-plan{background:#8bc34a;-webkit-box-sizing:border-box;box-sizing:border-box;border:none;color:#fff;cursor:pointer;display:block;font-weight:700!important;padding:0 10px;text-align:left;width:100%!important}#wpadminbar #wp-admin-bar-imagify-profile .imagify-admin-bar-quota{padding:13px 15px} \ No newline at end of file diff --git a/assets/js/pricing-modal.js b/assets/js/pricing-modal.js index bc6d2dee..db7d72f6 100755 --- a/assets/js/pricing-modal.js +++ b/assets/js/pricing-modal.js @@ -1100,7 +1100,7 @@ * Get pricings on modal opening. * Build the pricing tables inside modal. */ - $('#imagify-get-pricing-modal').on('click.imagify-ajax', function () { + $('.imagify-get-pricing-modal').on('click.imagify-ajax', function () { imagifyModal.getPricing($(this)); }); diff --git a/assets/js/pricing-modal.min.js b/assets/js/pricing-modal.min.js index 763e601e..d6a3d760 100755 --- a/assets/js/pricing-modal.min.js +++ b/assets/js/pricing-modal.min.js @@ -1 +1 @@ -!function(t,i){t(i).on("click.imagify",".imagify-tab",function(i){var e=t(this),a="imagify-current";i.preventDefault(),e.hasClass("imagify-current")||(i=e.find("a").attr("href")||"#"+e.find("a").attr("aria-controls"),e.closest(".imagify-tabs").next(".imagify-tabs-contents").find(".imagify-tab-content").hide().attr("aria-hidden","true"),t(i).fadeIn(275).attr("aria-hidden","false"),e.closest(".imagify-tabs").find(".imagify-tab").removeClass(a).attr("aria-selected","false"),e.addClass(a).attr("aria-selected","true"))})}(jQuery,document,window),function(b,i,k){var _={};b("#imagify-pricing-modal").length&&((_={$modal:b("#imagify-pricing-modal"),$checkboxes:b(".imagify-offer-line .imagify-checkbox"),$radios:b(".imagify-payment-modal .imagify-radio-line input"),$preView:b("#imagify-pre-checkout-view"),$plansView:b("#imagify-plans-selection-view").hide(),$paymentView:b("#imagify-payment-process-view").hide(),$successView:b("#imagify-success-view").hide(),$anotherBtn:b(".imagify-choose-another-plan"),speedFadeIn:300,getHtmlPrice:function(i,e){var a,t;return e=e||null,"object"!=typeof i?((i=(i+="").split("."))[1]=1===i[1].length?i[1]+"0":(""+i[1]).substring(0,2),t=''+i[0]+" ",t+('.'+i[1])+""):(a=i.monthly+"",i=i.yearly+"",a="0"===a?["0","00"]:a.split("."),i="0"===i?["0","00"]:i.split("."),(t=(t=(t=(t='')+''+a[0]+" ")+'.'+(1===a[1].length?a[1]+"0":(""+a[1]).substring(0,2))+" ")+''+i[0]+" ")+'.'+(1===i[1].length?i[1]+"0":(""+i[1]).substring(0,2))+"")},getHtmlDiscountPrice:function(i,e){var a="";return e=e||null,a="object"==typeof i?(a=(a=(a+='$')+''+(i.monthly+"")+"")+'')+''+(i.yearly+"")+"":(a+='$')+''+(i+="")+""},populateOffer:function(i,e,a,t){var o,n=k.imagify_discount_datas,l=e.additional_gb,s=e.annual_cost,f=e.id,c=e.label,m=e.monthly_cost,r=e.quota,e=e.cost,d=-1===r?"Unlimited":1e3<=r?r/1e3+" GB":r+" MB",y="monthly"===a?{monthly:m,yearly:Math.round(s/12*100)/100}:e,g=y,p=[],p=_.getPromoAppliesTo(n);return n.is_active&&"percentage"===n.coupon_type&&"monthly"===a&&0

'+imagifyPricingModal.labels.errorPriceAPI+"

");else{if((k.imagify_discount_datas=e).is_active){if(e.applies_to instanceof Array){for(var d=[],y=[],g=0;gm.quota&&(m={index:i,selected:1,quota:e.quota,plan_id:e.id,plan_label:e.label}),0===e.monthly_cost&&0===e.annual_cost||e.quota<=0&&a.month>e.quota||a.total>e.quota||0<=e.quota&&a.monthe.quota)&&(o=e,r.mo={index:i,selected:t>a.month&&t>a.total?0:1,plan_id:e.id,plan_label:e.label}),!0}),!1===r.mo&&(r.mo=void 0!==n?n:m),c-=i.mo[r.mo.index].quota,0!==i.ot.length&&(c<=0?(b.each(i.ot,function(i,e){return e.quota'+a.find(".imagify-price-by").text()+"",c=a.find(".imagify-price-discount").html(),m=a.find(".imagify-approx-nb").text(),r=a.find(".imagify-offer-size").text(),d=b("#imagify-coupon-code");i.preventDefault(),_.switchToView(_.$preView),l.find(".imagify-number-block").html(s+f),c?(l.find(".imagify-price-discount").length<=0&&l.find(".imagify-col-price").prepend(''),l.find(".imagify-price-discount").html(c),l.find(".imagify-price-discount").show()):l.find(".imagify-price-discount").hide(),l.find(".imagify-approx-nb").text(m),l.find(".imagify-offer-size").text(r),l.attr("data-offer",o),n||(l.find(".imagify-price-add-data").text(a.find(".imagify-price-add-data").text()),("monthly"===e?l.find("#imagify-subscription-monthly"):l.find("#imagify-subscription-yearly")).trigger("click.imagify"),l.find(".imagify-inline-options").find("input:radio:checked").trigger("change.imagify")),(d=b("#imagify-coupon-code")).val(""),k.imagify_discount_datas&&((i=_.getPromoAppliesTo(k.imagify_discount_datas)).includes(t[Object.keys(t)[0]].label)||"all"===i[0])&&d.val(k.imagify_discount_datas.label),_.checkCoupon(),_.populatePayBtn()}),b("#imagify-modal-checkout-btn").on("click.imagify",function(i){var e,a;i.preventDefault(),b(this).hasClass("imagify-button-disabled")||(i=b(".imagify-offer-monthly"),e=b(".imagify-offer-onetime"),a={},i.hasClass("imagify-offer-selected")&&(a.monthly=JSON.parse(i.attr("data-offer"))),e.hasClass("imagify-offer-selected")&&(a.onetime=JSON.parse(e.attr("data-offer"))),imagifyPricingModal.userDataCache&&b.post(ajaxurl,{action:imagifyPricingModal.userDataCache.deleteAction,_wpnonce:imagifyPricingModal.userDataCache.deleteNonce}),_.switchToView(_.$paymentView),a.period=_.getPeriod(),_.iframeSetSrc(a))}),b(".imagify-back-to-plans").on("click.imagify",function(i){var e=b(this).closest(".imagify-cart-item").hasClass("imagify-cart-item-onetime");i.preventDefault(),b(e?".imagify-offer-onetime":".imagify-offer-monthly").find(".imagify-choose-another-plan").trigger("click.imagify")}),k.addEventListener("message",_.checkPluginMessage,!0))}(jQuery,document,window); \ No newline at end of file +!function(t,i){t(i).on("click.imagify",".imagify-tab",function(i){var e=t(this),a="imagify-current";i.preventDefault(),e.hasClass("imagify-current")||(i=e.find("a").attr("href")||"#"+e.find("a").attr("aria-controls"),e.closest(".imagify-tabs").next(".imagify-tabs-contents").find(".imagify-tab-content").hide().attr("aria-hidden","true"),t(i).fadeIn(275).attr("aria-hidden","false"),e.closest(".imagify-tabs").find(".imagify-tab").removeClass(a).attr("aria-selected","false"),e.addClass(a).attr("aria-selected","true"))})}(jQuery,document,window),function(b,i,k){var _={};b("#imagify-pricing-modal").length&&((_={$modal:b("#imagify-pricing-modal"),$checkboxes:b(".imagify-offer-line .imagify-checkbox"),$radios:b(".imagify-payment-modal .imagify-radio-line input"),$preView:b("#imagify-pre-checkout-view"),$plansView:b("#imagify-plans-selection-view").hide(),$paymentView:b("#imagify-payment-process-view").hide(),$successView:b("#imagify-success-view").hide(),$anotherBtn:b(".imagify-choose-another-plan"),speedFadeIn:300,getHtmlPrice:function(i,e){var a,t;return e=e||null,"object"!=typeof i?((i=(i+="").split("."))[1]=1===i[1].length?i[1]+"0":(""+i[1]).substring(0,2),t=''+i[0]+" ",t+('.'+i[1])+""):(a=i.monthly+"",i=i.yearly+"",a="0"===a?["0","00"]:a.split("."),i="0"===i?["0","00"]:i.split("."),(t=(t=(t=(t='')+''+a[0]+" ")+'.'+(1===a[1].length?a[1]+"0":(""+a[1]).substring(0,2))+" ")+''+i[0]+" ")+'.'+(1===i[1].length?i[1]+"0":(""+i[1]).substring(0,2))+"")},getHtmlDiscountPrice:function(i,e){var a="";return e=e||null,a="object"==typeof i?(a=(a=(a+='$')+''+(i.monthly+"")+"")+'')+''+(i.yearly+"")+"":(a+='$')+''+(i+="")+""},populateOffer:function(i,e,a,t){var o,n=k.imagify_discount_datas,l=e.additional_gb,s=e.annual_cost,f=e.id,c=e.label,m=e.monthly_cost,r=e.quota,e=e.cost,d=-1===r?"Unlimited":1e3<=r?r/1e3+" GB":r+" MB",y="monthly"===a?{monthly:m,yearly:Math.round(s/12*100)/100}:e,g=y,p=[],p=_.getPromoAppliesTo(n);return n.is_active&&"percentage"===n.coupon_type&&"monthly"===a&&0

'+imagifyPricingModal.labels.errorPriceAPI+"

");else{if((k.imagify_discount_datas=e).is_active){if(e.applies_to instanceof Array){for(var d=[],y=[],g=0;gm.quota&&(m={index:i,selected:1,quota:e.quota,plan_id:e.id,plan_label:e.label}),0===e.monthly_cost&&0===e.annual_cost||e.quota<=0&&a.month>e.quota||a.total>e.quota||0<=e.quota&&a.monthe.quota)&&(o=e,r.mo={index:i,selected:t>a.month&&t>a.total?0:1,plan_id:e.id,plan_label:e.label}),!0}),!1===r.mo&&(r.mo=void 0!==n?n:m),c-=i.mo[r.mo.index].quota,0!==i.ot.length&&(c<=0?(b.each(i.ot,function(i,e){return e.quota'+a.find(".imagify-price-by").text()+"",c=a.find(".imagify-price-discount").html(),m=a.find(".imagify-approx-nb").text(),r=a.find(".imagify-offer-size").text(),d=b("#imagify-coupon-code");i.preventDefault(),_.switchToView(_.$preView),l.find(".imagify-number-block").html(s+f),c?(l.find(".imagify-price-discount").length<=0&&l.find(".imagify-col-price").prepend(''),l.find(".imagify-price-discount").html(c),l.find(".imagify-price-discount").show()):l.find(".imagify-price-discount").hide(),l.find(".imagify-approx-nb").text(m),l.find(".imagify-offer-size").text(r),l.attr("data-offer",o),n||(l.find(".imagify-price-add-data").text(a.find(".imagify-price-add-data").text()),("monthly"===e?l.find("#imagify-subscription-monthly"):l.find("#imagify-subscription-yearly")).trigger("click.imagify"),l.find(".imagify-inline-options").find("input:radio:checked").trigger("change.imagify")),(d=b("#imagify-coupon-code")).val(""),k.imagify_discount_datas&&((i=_.getPromoAppliesTo(k.imagify_discount_datas)).includes(t[Object.keys(t)[0]].label)||"all"===i[0])&&d.val(k.imagify_discount_datas.label),_.checkCoupon(),_.populatePayBtn()}),b("#imagify-modal-checkout-btn").on("click.imagify",function(i){var e,a;i.preventDefault(),b(this).hasClass("imagify-button-disabled")||(i=b(".imagify-offer-monthly"),e=b(".imagify-offer-onetime"),a={},i.hasClass("imagify-offer-selected")&&(a.monthly=JSON.parse(i.attr("data-offer"))),e.hasClass("imagify-offer-selected")&&(a.onetime=JSON.parse(e.attr("data-offer"))),imagifyPricingModal.userDataCache&&b.post(ajaxurl,{action:imagifyPricingModal.userDataCache.deleteAction,_wpnonce:imagifyPricingModal.userDataCache.deleteNonce}),_.switchToView(_.$paymentView),a.period=_.getPeriod(),_.iframeSetSrc(a))}),b(".imagify-back-to-plans").on("click.imagify",function(i){var e=b(this).closest(".imagify-cart-item").hasClass("imagify-cart-item-onetime");i.preventDefault(),b(e?".imagify-offer-onetime":".imagify-offer-monthly").find(".imagify-choose-another-plan").trigger("click.imagify")}),k.addEventListener("message",_.checkPluginMessage,!0))}(jQuery,document,window); \ No newline at end of file diff --git a/classes/Admin/AdminBar.php b/classes/Admin/AdminBar.php index 145a4636..6796d750 100644 --- a/classes/Admin/AdminBar.php +++ b/classes/Admin/AdminBar.php @@ -1,26 +1,129 @@ user = $user; + } + + /** + * Returns an array of events this subscriber listens to + * + * @return array + */ + public static function get_subscribed_events(): array { + return [ + 'wp_ajax_imagify_get_admin_bar_profile' => 'get_admin_bar_profile_callback', + 'admin_bar_menu' => [ 'add_imagify_admin_bar_menu', IMAGIFY_INT_MAX ], + ]; + } + + /** + * Add Imagify menu in the admin bar. + * + * @param WP_Admin_Bar $wp_admin_bar WP_Admin_Bar instance, passed by reference. */ - public function init() { - if ( wp_doing_ajax() ) { - add_action( 'wp_ajax_imagify_get_admin_bar_profile', array( $this, 'get_admin_bar_profile_callback' ) ); + public function add_imagify_admin_bar_menu( $wp_admin_bar ) { + if ( ! imagify_get_context( 'wp' )->current_user_can( 'manage' ) ) { + return; + } + + if ( ! get_imagify_option( 'admin_bar_menu' ) ) { + return; + } + + // Parent. + $wp_admin_bar->add_menu( array( + 'id' => 'imagify', + 'title' => 'Imagify', + 'href' => get_imagify_admin_url(), + ) ); + + // Settings. + $wp_admin_bar->add_menu(array( + 'parent' => 'imagify', + 'id' => 'imagify-settings', + 'title' => __( 'Settings' ), + 'href' => get_imagify_admin_url(), + ) ); + + // Bulk Optimization. + if ( ! is_network_admin() ) { + $wp_admin_bar->add_menu(array( + 'parent' => 'imagify', + 'id' => 'imagify-bulk-optimization', + 'title' => __( 'Bulk Optimization', 'imagify' ), + 'href' => get_imagify_admin_url( 'bulk-optimization' ), + ) ); } + + // Documentation. + $wp_admin_bar->add_menu(array( + 'parent' => 'imagify', + 'id' => 'imagify-documentation', + 'title' => __( 'Documentation', 'imagify' ), + 'href' => imagify_get_external_url( 'documentation' ), + 'meta' => array( + 'target' => '_blank', + ), + ) ); + + // Rate it. + $wp_admin_bar->add_menu(array( + 'parent' => 'imagify', + 'id' => 'imagify-rate-it', + /* translators: %s is WordPress.org. */ + 'title' => sprintf( __( 'Rate Imagify on %s', 'imagify' ), 'WordPress.org' ), + 'href' => imagify_get_external_url( 'rate' ), + 'meta' => array( + 'target' => '_blank', + ), + ) ); + + // Quota & Profile informations. + if ( defined( 'IMAGIFY_HIDDEN_ACCOUNT' ) && IMAGIFY_HIDDEN_ACCOUNT || ! get_imagify_option( 'api_key' ) ) { + return; + } + + if ( + $this->user->is_free() + && + $this->user->get_percent_unconsumed_quota() > 20 + ) { + $wp_admin_bar->add_menu( [ + 'parent' => 'imagify', + 'id' => 'imagify-upgrade-plan', + 'title' => '', + ] ); + } + + $wp_admin_bar->add_menu( array( + 'parent' => 'imagify', + 'id' => 'imagify-profile', + 'title' => wp_nonce_field( 'imagify-get-admin-bar-profile', 'imagifygetadminbarprofilenonce', false, false ) . '
' . __( 'Loading...', 'imagify' ) . '
', + ) ); } /** @@ -35,22 +138,21 @@ public function get_admin_bar_profile_callback() { 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() ) { + if ( $this->user->is_free() ) { $text = esc_html__( 'Upgrade your plan now for more!', 'rocket' ) . '
' . esc_html__( 'From $5.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() ) { + } elseif ( $this->user->is_growth() ) { $text = esc_html__( 'Switch to Infinite plan for unlimited optimization:', 'rocket' ) . '
'; - if ( $user->is_monthly ) { + if ( $this->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 { @@ -64,11 +166,11 @@ public function get_admin_bar_profile_callback() { $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(), + 'plan_label' => $this->user->plan_label, + 'plan_with_quota' => $this->user->is_free() || $this->user->is_growth(), 'unconsumed_quota' => $unconsumed_quota, - 'user_quota' => $user->quota, - 'next_update' => $user->next_date_update, + 'user_quota' => $this->user->quota, + 'next_update' => $this->user->next_date_update, 'text' => $text, 'button_text' => $button_text, 'upgrade_link' => $upgrade_link, diff --git a/classes/Admin/ServiceProvider.php b/classes/Admin/ServiceProvider.php index 2d500f9b..013a809f 100644 --- a/classes/Admin/ServiceProvider.php +++ b/classes/Admin/ServiceProvider.php @@ -16,6 +16,7 @@ class ServiceProvider extends AbstractServiceProvider { * @var array */ protected $provides = [ + 'admin_bar', 'admin_subscriber', ]; @@ -25,6 +26,7 @@ class ServiceProvider extends AbstractServiceProvider { * @var array */ public $subscribers = [ + 'admin_bar', 'admin_subscriber', ]; @@ -34,6 +36,9 @@ class ServiceProvider extends AbstractServiceProvider { * @return void */ public function register() { + + $this->getContainer()->share( 'admin_bar', AdminBar::class ) + ->addArgument( $this->getContainer()->get( 'user' ) ); $this->getContainer()->share( 'admin_subscriber', AdminSubscriber::class ) ->addArgument( $this->getContainer()->get( 'user' ) ); } diff --git a/classes/Plugin.php b/classes/Plugin.php index 7f10bbfb..877fc0b9 100644 --- a/classes/Plugin.php +++ b/classes/Plugin.php @@ -115,7 +115,6 @@ class_alias( '\\Imagify\\Traits\\InstanceGetterTrait', '\\Imagify\\Traits\\FakeS \Imagify\Auth\Basic::get_instance()->init(); \Imagify\Job\MediaOptimization::get_instance()->init(); Bulk::get_instance()->init(); - AdminBar::get_instance()->init(); if ( is_admin() ) { Notices::get_instance()->init(); @@ -190,7 +189,6 @@ public function include_files() { require_once $inc_path . 'functions/i18n.php'; require_once $inc_path . 'functions/partners.php'; require_once $inc_path . 'common/attachments.php'; - require_once $inc_path . 'common/admin-bar.php'; require_once $inc_path . 'common/partners.php'; require_once $inc_path . '3rd-party/3rd-party.php'; diff --git a/config/providers.php b/config/providers.php index e0ae4eb9..9cdbbec9 100644 --- a/config/providers.php +++ b/config/providers.php @@ -1,10 +1,10 @@ enqueue_assets( [ 'pricing-modal', 'bulk' ] ); + $this->enqueue_assets( 'bulk' ); } /* * Loaded in the settings page. */ if ( imagify_is_screen( 'imagify-settings' ) ) { - $this->enqueue_assets( [ 'sweetalert', 'notices', 'twentytwenty', 'pricing-modal', 'options' ] ); + $this->enqueue_assets( [ 'sweetalert', 'notices', 'twentytwenty', 'options' ] ); } /* @@ -293,6 +293,8 @@ public function enqueue_styles_and_scripts() { $this->enqueue_assets( [ 'files-list', 'twentytwenty' ] ); } + $this->enqueue_assets( 'pricing-modal' ); + /** * Triggered after Imagify CSS and JS have been enqueued. * diff --git a/inc/classes/class-imagify-views.php b/inc/classes/class-imagify-views.php index 64b01508..16d56bf5 100644 --- a/inc/classes/class-imagify-views.php +++ b/inc/classes/class-imagify-views.php @@ -125,6 +125,7 @@ public function init() { // JS templates in footer. add_action( 'admin_print_footer_scripts', [ $this, 'print_js_templates' ] ); + add_action( 'admin_footer', [ $this, 'print_modal_payment' ] ); } @@ -625,6 +626,12 @@ public function print_js_templates() { } } + /** + * Print the payment modal. + */ + public function print_modal_payment() { + $this->print_template( 'modal-payment' ); + } /** ----------------------------------------------------------------------------------------- */ /** TOOLS =================================================================================== */ diff --git a/inc/common/admin-bar.php b/inc/common/admin-bar.php deleted file mode 100755 index af89ec43..00000000 --- a/inc/common/admin-bar.php +++ /dev/null @@ -1,79 +0,0 @@ -current_user_can( 'manage' ) ) { - return; - } - - if ( ! get_imagify_option( 'admin_bar_menu' ) ) { - return; - } - - // Parent. - $wp_admin_bar->add_menu( array( - 'id' => 'imagify', - 'title' => 'Imagify', - 'href' => get_imagify_admin_url(), - ) ); - - // Settings. - $wp_admin_bar->add_menu(array( - 'parent' => 'imagify', - 'id' => 'imagify-settings', - 'title' => __( 'Settings' ), - 'href' => get_imagify_admin_url(), - ) ); - - // Bulk Optimization. - if ( ! is_network_admin() ) { - $wp_admin_bar->add_menu(array( - 'parent' => 'imagify', - 'id' => 'imagify-bulk-optimization', - 'title' => __( 'Bulk Optimization', 'imagify' ), - 'href' => get_imagify_admin_url( 'bulk-optimization' ), - ) ); - } - - // Documentation. - $wp_admin_bar->add_menu(array( - 'parent' => 'imagify', - 'id' => 'imagify-documentation', - 'title' => __( 'Documentation', 'imagify' ), - 'href' => imagify_get_external_url( 'documentation' ), - 'meta' => array( - 'target' => '_blank', - ), - ) ); - - // Rate it. - $wp_admin_bar->add_menu(array( - 'parent' => 'imagify', - 'id' => 'imagify-rate-it', - /* translators: %s is WordPress.org. */ - 'title' => sprintf( __( 'Rate Imagify on %s', 'imagify' ), 'WordPress.org' ), - 'href' => imagify_get_external_url( 'rate' ), - 'meta' => array( - 'target' => '_blank', - ), - ) ); - - // Quota & Profile informations. - if ( defined( 'IMAGIFY_HIDDEN_ACCOUNT' ) && IMAGIFY_HIDDEN_ACCOUNT || ! get_imagify_option( 'api_key' ) ) { - return; - } - - $wp_admin_bar->add_menu( array( - 'parent' => 'imagify', - 'id' => 'imagify-profile', - 'title' => wp_nonce_field( 'imagify-get-admin-bar-profile', 'imagifygetadminbarprofilenonce', false, false ) . '
' . __( 'Loading...', 'imagify' ) . '
', - ) ); -} diff --git a/views/admin/admin-bar-status.php b/views/admin/admin-bar-status.php index f1b0e232..c688f8ec 100644 --- a/views/admin/admin-bar-status.php +++ b/views/admin/admin-bar-status.php @@ -1,7 +1,6 @@ -
diff --git a/views/page-bulk.php b/views/page-bulk.php index a6657ace..dd17010a 100755 --- a/views/page-bulk.php +++ b/views/page-bulk.php @@ -160,8 +160,6 @@
print_template( 'modal-payment' ); - if ( Imagify_Requirements::is_api_key_valid() ) { $display_infos = get_transient( 'imagify_bulk_optimization_infos' ); diff --git a/views/page-settings.php b/views/page-settings.php index abb1b5e0..6fd7747f 100755 --- a/views/page-settings.php +++ b/views/page-settings.php @@ -177,7 +177,6 @@ $this->print_template( 'modal-settings-infos' ); $this->print_template( 'modal-settings-partners-infos' ); $this->print_template( 'modal-settings-visual-comparison' ); - $this->print_template( 'modal-payment' ); ?>
diff --git a/views/part-upsell.php b/views/part-upsell.php index 89e7d7e6..2233a836 100644 --- a/views/part-upsell.php +++ b/views/part-upsell.php @@ -29,7 +29,7 @@

-