This commit is contained in:
2026-10-06 18:51:23 -06:00
parent 8424dacd03
commit e2c26b7f21
4223 changed files with 737986 additions and 53 deletions
@@ -0,0 +1,324 @@
<?php
namespace WP_Rocket\Engine\License\API;
class Pricing {
/**
* The pricing data object
*
* @var object
*/
private $pricing;
/**
* Instantiate the class
*
* @param object $pricing The pricing object.
*/
public function __construct( $pricing ) {
$this->pricing = $pricing;
}
/**
* Gets the single license pricing data
*
* @return null|object
*/
public function get_single_pricing() {
if (
! isset( $this->pricing->licenses->single )
||
! is_object( $this->pricing->licenses->single )
) {
return null;
}
return $this->pricing->licenses->single;
}
/**
* Gets the plus license pricing data
*
* @return null|object
*/
public function get_plus_pricing() {
if (
! isset( $this->pricing->licenses->plus )
||
! is_object( $this->pricing->licenses->plus )
) {
return null;
}
return $this->pricing->licenses->plus;
}
/**
* Gets the infinite license pricing data
*
* @return null|object
*/
public function get_infinite_pricing() {
if (
! isset( $this->pricing->licenses->infinite )
||
! is_object( $this->pricing->licenses->infinite )
) {
return null;
}
return $this->pricing->licenses->infinite;
}
/**
* Gets the license renewal pricing data
*
* @return null|object
*/
public function get_renewals_data() {
if (
! isset( $this->pricing->renewals )
||
! is_object( $this->pricing->renewals )
) {
return null;
}
return $this->pricing->renewals;
}
/**
* Gets the promotion data
*
* @return null|object
*/
public function get_promo_data() {
if (
! isset( $this->pricing->promo )
||
! is_object( $this->pricing->promo )
) {
return null;
}
return $this->pricing->promo;
}
/**
* Checks if a promotion is currently active
*
* @return boolean
*/
public function is_promo_active() {
$promo_data = $this->get_promo_data();
if ( is_null( $promo_data ) ) {
return false;
}
if ( ! isset( $promo_data->start_date, $promo_data->end_date ) ) {
return false;
}
$current_time = time();
return (
absint( $promo_data->start_date ) < $current_time
&&
absint( $promo_data->end_date ) > $current_time
);
}
/**
* Gets promotion end date
*
* @return int
*/
public function get_promo_end() {
$promo = $this->get_promo_data();
if (
is_null( $promo )
||
! isset( $promo->end_date )
) {
return 0;
}
return absint( $promo->end_date );
}
/**
* Gets the regular upgrade price from single to plus
*
* @return int
*/
public function get_regular_single_to_plus_price() {
$plus_pricing = $this->get_plus_pricing();
if (
is_null( $plus_pricing )
||
! isset( $plus_pricing->prices->from_single->regular )
) {
return 0;
}
return $plus_pricing->prices->from_single->regular;
}
/**
* Gets the current upgrade price from single to plus
*
* @return int
*/
public function get_single_to_plus_price() {
$plus_pricing = $this->get_plus_pricing();
$regular = $this->get_regular_single_to_plus_price();
if (
is_null( $plus_pricing )
||
! isset( $plus_pricing->prices->from_single->sale )
) {
return $regular;
}
return $this->is_promo_active() ? $plus_pricing->prices->from_single->sale : $regular;
}
/**
* Gets the regular upgrade price from single to infinite
*
* @return int
*/
public function get_regular_single_to_infinite_price() {
$infinite_pricing = $this->get_infinite_pricing();
if (
is_null( $infinite_pricing )
||
! isset( $infinite_pricing->prices->from_single->regular )
) {
return 0;
}
return $infinite_pricing->prices->from_single->regular;
}
/**
* Gets the current upgrade price from single to plus
*
* @return int
*/
public function get_single_to_infinite_price() {
$infinite_pricing = $this->get_infinite_pricing();
$regular = $this->get_regular_single_to_infinite_price();
if (
is_null( $infinite_pricing )
||
! isset( $infinite_pricing->prices->from_single->sale )
) {
return $regular;
}
return $this->is_promo_active() ? $infinite_pricing->prices->from_single->sale : $regular;
}
/**
* Gets the regular upgrade price from plus to infinite
*
* @return int
*/
public function get_regular_plus_to_infinite_price() {
$infinite_pricing = $this->get_infinite_pricing();
if (
is_null( $infinite_pricing )
||
! isset( $infinite_pricing->prices->from_plus->regular )
) {
return 0;
}
return $infinite_pricing->prices->from_plus->regular;
}
/**
* Gets the current upgrade price from plus to infinite
*
* @return int
*/
public function get_plus_to_infinite_price() {
$infinite_pricing = $this->get_infinite_pricing();
$regular = $this->get_regular_plus_to_infinite_price();
if (
is_null( $infinite_pricing )
||
! isset( $infinite_pricing->prices->from_plus->sale )
) {
return $regular;
}
return $this->is_promo_active() ? $infinite_pricing->prices->from_plus->sale : $regular;
}
/**
* Gets the number of websites allowed for the single license
*
* @return int
*/
public function get_single_websites_count() {
$single_pricing = $this->get_single_pricing();
if (
is_null( $single_pricing )
||
! isset( $single_pricing->websites )
) {
return 0;
}
return (int) $single_pricing->websites;
}
/**
* Gets the number of websites allowed for the plus license
*
* @return int
*/
public function get_plus_websites_count() {
$plus_pricing = $this->get_plus_pricing();
if (
is_null( $plus_pricing )
||
! isset( $plus_pricing->websites )
) {
return 0;
}
return (int) $plus_pricing->websites;
}
/**
* Gets the number of websites allowed for the infinite license
*
* @return int
*/
public function get_infinite_websites_count() {
$infinite_pricing = $this->get_infinite_pricing();
if (
is_null( $infinite_pricing )
||
! isset( $infinite_pricing->websites )
) {
return 0;
}
return (int) $infinite_pricing->websites;
}
}
@@ -0,0 +1,90 @@
<?php
namespace WP_Rocket\Engine\License\API;
class PricingClient {
const PRICING_ENDPOINT = 'https://wp-rocket.me/stat/1.0/wp-rocket/pricing-2023.php';
/**
* Gets pricing data from cache if it exists, else gets it from the pricing endpoint
*
* Cache the pricing data for 6 hours in a transient
*
* @since 3.7.3
*
* @return bool|object
*/
public function get_pricing_data() {
$cached_data = get_transient( 'wp_rocket_pricing' );
if ( false !== $cached_data ) {
return $cached_data;
}
$data = $this->get_raw_pricing_data();
if ( false === $data ) {
return false;
}
set_transient( 'wp_rocket_pricing', $data, 12 * HOUR_IN_SECONDS );
return $data;
}
/**
* Gets the pricing data from the pricing endpoint
*
* @since 3.7.3
*
* @return bool|object
*/
private function get_raw_pricing_data() {
if ( (bool) get_transient( 'wp_rocket_pricing_timeout_active' ) ) {
return false;
}
$response = wp_safe_remote_get(
self::PRICING_ENDPOINT
);
if ( 200 !== wp_remote_retrieve_response_code( $response ) ) {
$this->set_timeout_transients();
return false;
}
$body = wp_remote_retrieve_body( $response );
if ( empty( $body ) ) {
$this->set_timeout_transients();
return false;
}
delete_transient( 'wp_rocket_pricing_timeout' );
delete_transient( 'wp_rocket_pricing_timeout_active' );
return json_decode( $body );
}
/**
* Set pricing timeout transients.
*
* @since 3.8.4
*
* @return void
*/
private function set_timeout_transients() {
$timeout = (int) get_transient( 'wp_rocket_pricing_timeout' );
$timeout = ( 0 === $timeout )
? 300
: ( 2 * $timeout <= DAY_IN_SECONDS
? 2 * $timeout :
DAY_IN_SECONDS
);
set_transient( 'wp_rocket_pricing_timeout', $timeout, WEEK_IN_SECONDS );
set_transient( 'wp_rocket_pricing_timeout_active', true, $timeout );
}
}
@@ -0,0 +1,123 @@
<?php
namespace WP_Rocket\Engine\License\API;
class User {
/**
* The user object
*
* @var object
*/
private $user;
/**
* Instantiate the class
*
* @param object $user The user object.
*/
public function __construct( $user ) {
$this->user = is_object( $user ) ? $user : new \stdClass();
}
/**
* Gets the user license type
*
* @return int
*/
public function get_license_type() {
if ( ! isset( $this->user->licence_account ) ) {
return 0;
}
return (int) $this->user->licence_account;
}
/**
* Gets the user license expiration timestamp
*
* @return int
*/
public function get_license_expiration() {
if ( ! isset( $this->user->licence_expiration ) ) {
return 0;
}
return (int) $this->user->licence_expiration;
}
/**
* Checks if the user license is expired
*
* @return boolean
*/
public function is_license_expired() {
return time() > $this->get_license_expiration();
}
/**
* Gets the user license creation date
*
* @return int
*/
public function get_creation_date() {
if ( ! isset( $this->user->date_created ) ) {
return time();
}
return (int) $this->user->date_created > 0
? (int) $this->user->date_created
: time();
}
/**
* Checks if user has auto-renew enabled
*
* @return boolean
*/
public function is_auto_renew() {
if ( ! isset( $this->user->has_auto_renew ) ) {
return false;
}
return (bool) $this->user->has_auto_renew;
}
/**
* Gets the upgrade to plus URL
*
* @return string
*/
public function get_upgrade_plus_url() {
if ( ! isset( $this->user->upgrade_plus_url ) ) {
return '';
}
return $this->user->upgrade_plus_url;
}
/**
* Gets the upgrade to infinite url
*
* @return string
*/
public function get_upgrade_infinite_url() {
if ( ! isset( $this->user->upgrade_infinite_url ) ) {
return '';
}
return $this->user->upgrade_infinite_url;
}
/**
* Gets the renewal url
*
* @return string
*/
public function get_renewal_url() {
if ( ! isset( $this->user->renewal_url ) ) {
return '';
}
return $this->user->renewal_url;
}
}
@@ -0,0 +1,87 @@
<?php
namespace WP_Rocket\Engine\License\API;
use WP_Rocket\Admin\Options_Data;
class UserClient {
const USER_ENDPOINT = 'https://wp-rocket.me/stat/1.0/wp-rocket/user.php';
/**
* WP Rocket options instance
*
* @var Options_Data
*/
private $options;
/**
* Instantiate the class
*
* @param Options_Data $options WP Rocket options instance.
*/
public function __construct( Options_Data $options ) {
$this->options = $options;
}
/**
* Gets user data from cache if it exists, else gets it from the user endpoint
*
* Cache the user data for 24 hours in a transient
*
* @since 3.7.3
*
* @return bool|object
*/
public function get_user_data() {
$cached_data = get_transient( 'wp_rocket_customer_data' );
if ( false !== $cached_data ) {
return $cached_data;
}
$data = $this->get_raw_user_data();
if ( false === $data ) {
return false;
}
set_transient( 'wp_rocket_customer_data', $data, DAY_IN_SECONDS );
return $data;
}
/**
* Gets the user data from the user endpoint
*
* @since 3.7.3
*
* @return bool|object
*/
private function get_raw_user_data() {
$customer_key = ! empty( $this->options->get( 'consumer_key', '' ) )
? $this->options->get( 'consumer_key', '' )
: rocket_get_constant( 'WP_ROCKET_KEY', '' );
$customer_email = ! empty( $this->options->get( 'consumer_email', '' ) )
? $this->options->get( 'consumer_email', '' )
: rocket_get_constant( 'WP_ROCKET_EMAIL', '' );
$response = wp_safe_remote_post(
self::USER_ENDPOINT,
[
'body' => 'user_id=' . rawurlencode( $customer_email ) . '&consumer_key=' . sanitize_key( $customer_key ),
]
);
if ( 200 !== wp_remote_retrieve_response_code( $response ) ) {
return false;
}
$body = wp_remote_retrieve_body( $response );
if ( empty( $body ) ) {
return false;
}
return json_decode( $body );
}
}
@@ -0,0 +1,760 @@
<?php
declare(strict_types=1);
namespace WP_Rocket\Engine\License;
use WP_Rocket\Abstract_Render;
use WP_Rocket\Admin\Options_Data;
use WP_Rocket\Engine\License\API\Pricing;
use WP_Rocket\Engine\License\API\User;
class Renewal extends Abstract_Render {
/**
* Pricing instance
*
* @var Pricing
*/
private $pricing;
/**
* User instance
*
* @var User
*/
private $user;
/**
* Options_Data instance
*
* @var Options_Data
*/
private $options;
/**
* Instantiate the class
*
* @param Pricing $pricing Pricing instance.
* @param User $user User instance.
* @param Options_Data $options Options_Data instance.
* @param string $template_path Path to the views.
*/
public function __construct( Pricing $pricing, User $user, Options_Data $options, $template_path ) {
parent::__construct( $template_path );
$this->pricing = $pricing;
$this->user = $user;
$this->options = $options;
}
/**
* Displays the renewal banner for users expiring in less than 30 days
*
* @since 3.7.5
*
* @return void
*/
public function display_renewal_soon_banner() {
if ( rocket_get_constant( 'WP_ROCKET_WHITE_LABEL_ACCOUNT' ) ) {
return;
}
if ( $this->user->is_license_expired() ) {
return;
}
if ( ! $this->is_expired_soon() ) {
return;
}
$data = $this->get_banner_data();
$data['countdown'] = $this->get_countdown_data();
$discount = esc_html( '$' . number_format_i18n( $this->get_discount_percent(), 2 ) );
$price = esc_html( '$' . number_format_i18n( $this->get_price(), 2 ) );
$data['message'] = sprintf(
// translators: %1$s = <strong>, %2$s = price, %3$s = </strong>.
esc_html__( 'Renew before it is too late, you will only pay %1$s%2$s%3$s!', 'rocket' ),
'<strong>',
$price,
'</strong>'
);
if ( $this->get_discount_percent() ) {
$data['message'] = sprintf(
// translators: %1$s = <strong>, %2$s = discount, %3$s = </strong>,%4$s = <strong>, %5$s = price, %6$s=</strong>.
esc_html__( 'Renew with a %1$s%2$s discount%3$s before it is too late, you will only pay %4$s%5$s%6$s!', 'rocket' ),
'<strong>',
$discount,
'</strong>',
'<strong>',
$price,
'</strong>'
);
}
echo $this->generate( 'renewal-soon-banner', $data ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
}
/**
* Displays the renewal banner for expired users
*
* @since 3.7.5
*
* @return void
*/
public function display_renewal_expired_banner() {
if ( rocket_get_constant( 'WP_ROCKET_WHITE_LABEL_ACCOUNT' ) ) {
return;
}
if ( 0 === $this->user->get_license_expiration() ) {
return;
}
if ( ! $this->user->is_license_expired() ) {
return;
}
if ( false !== get_transient( 'rocket_renewal_banner_' . get_current_user_id() ) ) {
return;
}
$expiration = $this->user->get_license_expiration();
$expired_since = ( time() - $expiration ) / DAY_IN_SECONDS;
if (
$this->user->is_auto_renew()
&&
4 > $expired_since
) {
return;
}
$ocd_enabled = $this->options->get( 'optimize_css_delivery', 0 );
$renewal_url = $this->user->get_renewal_url();
$price = esc_html( '$' . number_format_i18n( $this->get_price(), 2 ) );
$message = sprintf(
// translators: %1$s = <strong>, %2$s = </strong>, %3$s = price.
esc_html__( 'Renew your license for 1 year now at %1$s%3$s%2$s.', 'rocket' ),
'<strong>',
'</strong>',
$price
);
if (
( $this->is_grandfather() || $this->has_grandmother() )
&&
$expired_since < 15
) {
$message = sprintf(
// translators: %1$s = <strong>, %2$s = </strong>, %3$s = discount percentage, %4$s = price.
esc_html__( 'Renew your license for 1 year now and get %1$s%3$s OFF%2$s immediately: you will only pay %1$s%4$s%2$s!', 'rocket' ),
'<strong>',
'</strong>',
esc_html( '$' . number_format_i18n( $this->get_discount_percent(), 2 ) ),
$price
);
}
if ( $ocd_enabled ) {
if ( 15 > $expired_since ) {
// phpcs:disable WordPress.Security.EscapeOutput.OutputNotEscaped
echo $this->generate(
'renewal-expired-banner-ocd',
[
'renewal_url' => $renewal_url,
'message' => $message,
'disabled_date' => date_i18n( get_option( 'date_format' ), $expiration + 15 * DAY_IN_SECONDS ),
]
);
// phpcs:enable WordPress.Security.EscapeOutput.OutputNotEscaped
} elseif ( 90 > $expired_since ) {
// phpcs:disable WordPress.Security.EscapeOutput.OutputNotEscaped
echo $this->generate(
'renewal-expired-banner-ocd-disabled',
[
'renewal_url' => $renewal_url,
'message' => $message,
]
);
// phpcs:enable WordPress.Security.EscapeOutput.OutputNotEscaped
} elseif ( 90 < $expired_since ) {
// phpcs:disable WordPress.Security.EscapeOutput.OutputNotEscaped
echo $this->generate(
'renewal-expired-banner',
[
'renewal_url' => $renewal_url,
'message' => $message,
]
);
// phpcs:enable WordPress.Security.EscapeOutput.OutputNotEscaped
}
} elseif ( ! $ocd_enabled ) {
// phpcs:disable WordPress.Security.EscapeOutput.OutputNotEscaped
echo $this->generate(
'renewal-expired-banner',
[
'renewal_url' => $renewal_url,
'message' => $message,
]
);
// phpcs:enable WordPress.Security.EscapeOutput.OutputNotEscaped
}
}
/**
* Get base data to display in the banners
*
* @since 3.7.5
*
* @return array
*/
private function get_banner_data() {
$price = esc_html( '$' . number_format_i18n( $this->get_price(), 2 ) );
$message = sprintf(
// translators: %1$s = <strong>, %2$s = </strong>, %3$s = discount price.
esc_html__( 'Renew before it is too late, you will pay %1$s%3$s%2$s.', 'rocket' ),
'<strong>',
'</strong>',
$price
);
if ( $this->is_grandfather() ) {
$message = sprintf(
// translators: %1$s = <strong>, %2$s = discount percentage, %3$s = </strong>, %4$s = discount price.
esc_html__( 'Renew with a %1$s%2$s discount%3$s before it is too late, you will only pay %1$s%4$s%3$s!', 'rocket' ),
'<strong>',
esc_html( '$' . number_format_i18n( $this->get_discount_percent(), 2 ) ),
'</strong>',
$price
);
}
return [
'message' => $message,
'renewal_url' => $this->user->get_renewal_url(),
];
}
/**
* AJAX callback to dismiss the renewal banner for expired users
*
* @since 3.7.5
*
* @return void
*/
public function dismiss_renewal_expired_banner() {
check_ajax_referer( 'rocket-ajax', 'nonce', true );
if ( ! current_user_can( 'rocket_manage_options' ) ) {
return;
}
$transient = 'rocket_renewal_banner_' . get_current_user_id();
if ( false !== get_transient( $transient ) ) {
return;
}
set_transient( $transient, 1, MONTH_IN_SECONDS );
wp_send_json_success();
}
/**
* Adds the license expiration time to WP Rocket localize script data
*
* @since 3.7.5
*
* @param array $data Localize script data.
* @return array
*/
public function add_localize_script_data( $data ) {
if ( ! is_array( $data ) ) {
$data = (array) $data;
}
if ( $this->user->is_license_expired() ) {
return $data;
}
if ( ! $this->is_expired_soon() ) {
return $data;
}
$data['license_expiration'] = $this->user->get_license_expiration();
return $data;
}
/**
* Checks if the license expires in less than 30 days
*
* @since 3.7.5
*
* @return boolean
*/
private function is_expired_soon() {
if ( $this->user->is_auto_renew() ) {
return false;
}
$expiration_delay = $this->user->get_license_expiration() - time();
return 30 * DAY_IN_SECONDS > $expiration_delay;
}
/**
* Gets the discount corresponding to the current user status
*
* @since 3.7.5
*
* @return int
*/
private function get_discount_percent() {
$prices = $this->get_license_pricing_data();
$renewals = $this->get_user_renewal_status();
if ( false === $renewals || ! isset( $prices->prices, $prices->prices->renewal ) ) {
return 0;
}
$prices = $prices->prices;
if ( $renewals['is_grandfather'] ) {
return isset( $prices->renewal->is_grandfather, $prices->renewal->not_grandfather ) ? $prices->renewal->not_grandfather - $prices->renewal->is_grandfather : 0;
}
if ( $renewals['is_grandmother'] ) {
return isset( $prices->renewal->is_grandmother, $prices->renewal->not_grandfather ) ? $prices->renewal->not_grandfather - $prices->renewal->is_grandmother : 0;
}
return 0;
}
/**
* Is user grandfathered
*
* @return bool
*/
private function is_grandfather(): bool {
$renewals = $this->get_user_renewal_status();
if ( ! is_array( $renewals ) ) {
return false;
}
return key_exists( 'is_grandfather', $renewals ) && $renewals['is_grandfather'];
}
/**
* Is user grandmothered
*
* @return bool
*/
private function has_grandmother(): bool {
$renewals = $this->get_user_renewal_status();
if ( ! is_array( $renewals ) ) {
return false;
}
return key_exists( 'is_grandmother', $renewals ) && $renewals['is_grandmother'];
}
/**
* Gets the price corresponding to the current user status
*
* @since 3.7.5
*
* @return int
*/
private function get_price() {
$renewals = $this->get_user_renewal_status();
if ( false === $renewals ) {
return 0;
}
$license = $this->get_license_pricing_data();
if (
$renewals['is_grandfather']
&&
! $renewals['is_expired']
) {
return isset( $license->prices->renewal->is_grandfather ) ? $license->prices->renewal->is_grandfather : 0;
}
if ( $renewals['is_grandmother'] &&
! $renewals['is_expired'] ) {
return isset( $license->prices->renewal->is_grandmother ) ? $license->prices->renewal->is_grandmother : 0;
}
return isset( $license->prices->renewal->not_grandfather ) ? $license->prices->renewal->not_grandfather : 0;
}
/**
* Gets the user renewal status
*
* @since 3.7.5
*
* @return array
*/
private function get_user_renewal_status() {
$renewals = $this->pricing->get_renewals_data();
if ( ! isset( $renewals->extra_days, $renewals->grandfather_date, $renewals->discount_percent, $renewals->grandmother_date ) ) {
return false;
}
return [
'discount_percent' => $renewals->discount_percent,
'is_expired' => time() > ( $this->user->get_license_expiration() + ( $renewals->extra_days * DAY_IN_SECONDS ) ),
'is_grandfather' => $renewals->grandfather_date > $this->user->get_creation_date(),
'is_grandmother' => $renewals->grandmother_date > $this->user->get_creation_date(),
];
}
/**
* Gets the license pricing data corresponding to the user license
*
* @since 3.7.5
*
* @return object|null
*/
private function get_license_pricing_data() {
$license = $this->user->get_license_type();
$plus_websites = $this->pricing->get_plus_websites_count();
if ( $license === $plus_websites ) {
return $this->pricing->get_plus_pricing();
} elseif (
$license >= $this->pricing->get_single_websites_count()
&&
$license < $plus_websites
) {
return $this->pricing->get_single_pricing();
}
return $this->pricing->get_infinite_pricing();
}
/**
* Gets the countdown data to display for the renewal soon banner
*
* @since 3.7.5
*
* @return array
*/
private function get_countdown_data() {
$data = [
'days' => 0,
'hours' => 0,
'minutes' => 0,
'seconds' => 0,
];
if ( rocket_get_constant( 'WP_ROCKET_IS_TESTING', false ) ) {
return $data;
}
$expiration = $this->user->get_license_expiration();
if ( 0 === $expiration ) {
return $data;
}
$now = date_create();
$end = date_timestamp_set( date_create(), $expiration );
if ( $now > $end ) {
return $data;
}
$remaining = date_diff( $now, $end );
$format = explode( ' ', $remaining->format( '%d %H %i %s' ) );
$data['days'] = $format[0];
$data['hours'] = $format[1];
$data['minutes'] = $format[2];
$data['seconds'] = $format[3];
return $data;
}
/**
* Add license expiring warning to OCD label
*
* @param array $args Setting field arguments.
*
* @return array
*/
public function add_license_expire_warning( $args ): array {
if ( 'optimize_css_delivery' !== $args['id'] ) {
return $args;
}
if ( ! $this->user->is_license_expired() ) {
return $args;
}
$ocd = $this->options->get( 'optimize_css_delivery', 0 );
$whitelabel = rocket_get_constant( 'WP_ROCKET_WHITE_LABEL_ACCOUNT', false );
$expired_since = ( time() - $this->user->get_license_expiration() ) / DAY_IN_SECONDS;
$message = ' <span class="wpr-icon-important wpr-checkbox-warning">';
if (
(
$whitelabel
&&
15 > $expired_since
&&
$ocd
)
||
(
! $whitelabel
&&
$this->user->is_auto_renew()
&&
4 > $expired_since
)
||
(
$whitelabel
&&
$this->user->is_auto_renew()
&&
4 > $expired_since
&&
! $ocd
)
) {
return $args;
} elseif (
! $whitelabel
&&
15 > $expired_since
&&
$ocd
) {
$message .= sprintf(
// translators: %1$s = <a>, %2$s = </a>.
__( 'You need a valid license to continue using this feature. %1$sRenew now%2$s before losing access.', 'rocket' ),
'<a href="' . esc_url( $this->user->get_renewal_url() ) . '" target="_blank">',
'</a>'
);
} elseif (
(
! $whitelabel
&&
15 < $expired_since
)
||
(
! $whitelabel
&&
15 > $expired_since
&&
! $ocd
)
) {
$message .= sprintf(
// translators: %1$s = <a>, %2$s = </a>.
__( 'You need an active license to enable this option. %1$sRenew now%2$s.', 'rocket' ),
'<a href="' . esc_url( $this->user->get_renewal_url() ) . '" target="_blank">',
'</a>'
);
} elseif (
(
$whitelabel
&&
15 < $expired_since
)
||
(
$whitelabel
&&
15 > $expired_since
&&
! $ocd
)
) {
$doc = 'https://docs.wp-rocket.me/article/1711-what-happens-if-my-license-expires';
$locale = current( array_slice( explode( '_', get_user_locale() ), 0, 1 ) );
if ( 'fr' === $locale ) {
$doc = 'https://fr.docs.wp-rocket.me/article/1712-que-se-passe-t-il-si-ma-licence-expire';
}
$message .= sprintf(
// translators: %1$s = <a>, %2$s = </a>.
__( 'You need an active license to enable this option. %1$sMore info%2$s.', 'rocket' ),
'<a href="' . $doc . '?utm_source=wp_plugin&utm_medium=wp_rocket" target="_blank">',
'</a>'
);
}
$message .= '</span>';
$args['label'] = $args['label'] . $message;
return $args;
}
/**
* Adds the notification bubble to WP Rocket menu item when expired
*
* @param string $menu_title Menu title.
*
* @return string
*/
public function add_expired_bubble( $menu_title ): string {
if ( rocket_get_constant( 'WP_ROCKET_WHITE_LABEL_ACCOUNT', false ) ) {
return $menu_title;
}
if ( ! $this->user->is_license_expired() ) {
return $menu_title;
}
if ( false !== get_transient( 'wpr_dashboard_seen_' . get_current_user_id() ) ) {
return $menu_title;
}
$expired_since = ( time() - $this->user->get_license_expiration() ) / DAY_IN_SECONDS;
$auto_renew = $this->user->is_auto_renew();
$ocd_enabled = $this->options->get( 'optimize_css_delivery', 0 );
if (
$ocd_enabled
&&
$auto_renew
&&
4 > $expired_since
) {
return $menu_title;
}
if (
! $auto_renew
&&
! $ocd_enabled
&&
4 < $expired_since
) {
return $menu_title;
}
if (
$auto_renew
&&
! $ocd_enabled
&&
(
4 > $expired_since
||
15 < $expired_since
)
) {
return $menu_title;
}
return $menu_title . ' <span class="awaiting-mod">!</span>';
}
/**
* Sets the dashboard seen transient to hide the expired bubble
*
* @return void
*/
public function set_dashboard_seen_transient() {
if ( ! $this->user->is_license_expired() ) {
return;
}
if ( ! $this->options->get( 'optimize_css_delivery', 0 ) ) {
return;
}
$current_user = get_current_user_id();
if ( false !== get_transient( "wpr_dashboard_seen_{$current_user}" ) ) {
return;
}
$expired_since = ( time() - $this->user->get_license_expiration() ) / DAY_IN_SECONDS;
if ( 15 > $expired_since ) {
set_transient( "wpr_dashboard_seen_{$current_user}", 1, 15 * DAY_IN_SECONDS );
} elseif ( 15 < $expired_since ) {
set_transient( "wpr_dashboard_seen_{$current_user}", 1, YEAR_IN_SECONDS );
}
}
/**
* Disable optimize CSS delivery setting
*
* @param array $args Array of setting field arguments.
*
* @return array
*/
public function maybe_disable_ocd( $args ) {
if ( 'optimize_css_delivery' !== $args['id'] ) {
return $args;
}
if ( ! $this->user->is_license_expired() ) {
return $args;
}
$expired_since = ( time() - $this->user->get_license_expiration() ) / DAY_IN_SECONDS;
if (
15 > $expired_since
||
(
$this->user->is_auto_renew()
&&
4 > $expired_since
)
) {
return $args;
}
$args['value'] = 0;
if (
isset( $args['container_class'] )
&&
! in_array( 'wpr-isDisabled', $args['container_class'], true )
) {
$args['container_class'][] = 'wpr-isDisabled';
}
$args['input_attr']['disabled'] = 1;
return $args;
}
/**
* Disables the RUCSS & Async CSS options if license is expired since more than 15 days
*
* @param mixed $value Current option value.
*
* @return mixed
*/
public function maybe_disable_option( $value ) {
$expired_since = ( time() - $this->user->get_license_expiration() ) / DAY_IN_SECONDS;
if ( 15 > $expired_since ) {
return $value;
}
return 0;
}
}
@@ -0,0 +1,64 @@
<?php
namespace WP_Rocket\Engine\License;
use WP_Rocket\Dependencies\League\Container\ServiceProvider\AbstractServiceProvider;
use WP_Rocket\Engine\License\API\PricingClient;
use WP_Rocket\Engine\License\API\Pricing;
use WP_Rocket\Engine\License\API\UserClient;
use WP_Rocket\Engine\License\API\User;
use WP_Rocket\Engine\License\Renewal;
use WP_Rocket\Engine\License\Subscriber;
use WP_Rocket\Engine\License\Upgrade;
/**
* Service Provider for the License module
*
* @since 3.7.3
*/
class ServiceProvider extends AbstractServiceProvider {
/**
* Aliases the service provider provides
*
* @var array
*/
protected $provides = [
'pricing_client',
'user_client',
'pricing',
'user',
'upgrade',
'renewal',
'license_subscriber',
];
/**
* Registers items with the container
*
* @return void
*/
public function register() {
$views = __DIR__ . '/views';
$this->getContainer()->add( 'pricing_client', PricingClient::class );
$this->getContainer()->add( 'user_client', UserClient::class )
->addArgument( $this->getContainer()->get( 'options' ) );
$this->getContainer()->share( 'pricing', Pricing::class )
->addArgument( $this->getContainer()->get( 'pricing_client' )->get_pricing_data() );
$this->getContainer()->share( 'user', User::class )
->addArgument( $this->getContainer()->get( 'user_client' )->get_user_data() );
$this->getContainer()->add( 'upgrade', Upgrade::class )
->addArgument( $this->getContainer()->get( 'pricing' ) )
->addArgument( $this->getContainer()->get( 'user' ) )
->addArgument( $views );
$this->getContainer()->add( 'renewal', Renewal::class )
->addArgument( $this->getContainer()->get( 'pricing' ) )
->addArgument( $this->getContainer()->get( 'user' ) )
->addArgument( $this->getContainer()->get( 'options' ) )
->addArgument( $views );
$this->getContainer()->share( 'license_subscriber', Subscriber::class )
->addArgument( $this->getContainer()->get( 'upgrade' ) )
->addArgument( $this->getContainer()->get( 'renewal' ) )
->addTag( 'admin_subscriber' );
}
}
@@ -0,0 +1,253 @@
<?php
declare(strict_types=1);
namespace WP_Rocket\Engine\License;
use WP_Rocket\Event_Management\Subscriber_Interface;
class Subscriber implements Subscriber_Interface {
/**
* Upgrade instance
*
* @var Upgrade
*/
private $upgrade;
/**
* Renewal instance
*
* @var Renewal
*/
private $renewal;
/**
* Instantiate the class
*
* @param Upgrade $upgrade Upgrade instance.
* @param Renewal $renewal Renewal instance.
*/
public function __construct( Upgrade $upgrade, Renewal $renewal ) {
$this->upgrade = $upgrade;
$this->renewal = $renewal;
}
/**
* Events this subscriber listens to.
*
* @return array
*/
public static function get_subscribed_events() {
return [
'rocket_dashboard_license_info' => 'display_upgrade_section',
'rocket_settings_page_footer' => 'display_upgrade_popin',
'rocket_menu_title' => [
[ 'add_notification_bubble' ],
[ 'add_notification_bubble_expired' ],
],
'admin_footer-settings_page_wprocket' => [
[ 'dismiss_notification_bubble' ],
[ 'set_dashboard_seen_transient' ],
],
'rocket_before_dashboard_content' => [
[ 'display_promo_banner' ],
[ 'display_renewal_soon_banner', 11 ],
[ 'display_renewal_expired_banner', 12 ],
],
'wp_ajax_rocket_dismiss_promo' => 'dismiss_promo_banner',
'wp_ajax_rocket_dismiss_renewal' => 'dismiss_renewal_banner',
'rocket_localize_admin_script' => 'add_localize_script_data',
'wp_rocket_upgrade' => [ 'clean_user_transient', 15, 2 ],
'rocket_before_add_field_to_settings' => [
[ 'maybe_disable_ocd', 11 ],
[ 'add_license_expire_warning' ],
],
'get_rocket_option_remove_unused_css' => [ 'maybe_disable_option', PHP_INT_MAX ],
'get_rocket_option_async_css' => [ 'maybe_disable_option', PHP_INT_MAX ],
];
}
/**
* Displays the upgrade section in the license info block
*
* @since 3.7.3
*
* @return void
*/
public function display_upgrade_section() {
$this->upgrade->display_upgrade_section();
}
/**
* Displays the upgrade popin
*
* @since 3.7.3
*
* @return void
*/
public function display_upgrade_popin() {
$this->upgrade->display_upgrade_popin();
}
/**
* Adds the notification bubble to the menu title if a promotion is active
*
* @since 3.7.4
*
* @param string $menu_title The text to be used for the menu.
* @return string
*/
public function add_notification_bubble( $menu_title ) {
return $this->upgrade->add_notification_bubble( $menu_title );
}
/**
* Prevents the notification bubble from showing once the user accessed the dashboard once
*
* @since 3.7.4
*
* @return void
*/
public function dismiss_notification_bubble() {
$this->upgrade->dismiss_notification_bubble();
}
/**
* Displays the promotions banner when a promotion is active
*
* @since 3.7.4
*
* @return void
*/
public function display_promo_banner() {
$this->upgrade->display_promo_banner();
}
/**
* AJAX callback to dismiss the promotion banner
*
* @since 3.7.4
*
* @return void
*/
public function dismiss_promo_banner() {
$this->upgrade->dismiss_promo_banner();
}
/**
* Adds the current time and promotion end time to WP Rocket localize script data
*
* @since 3.7.5 Add the renewal localize data
* @since 3.7.4
*
* @param array $data Localize script data.
* @return array
*/
public function add_localize_script_data( $data ) {
$data = $this->upgrade->add_localize_script_data( $data );
return $this->renewal->add_localize_script_data( $data );
}
/**
* Deletes the user data transient on 3.7.4 update
*
* @since 3.7.4
*
* @param string $new_version New version of the plugin.
* @param string $old_version Installed version of the plugin.
* @return void
*/
public function clean_user_transient( $new_version, $old_version ) {
if ( version_compare( $old_version, '3.7.4', '>' ) ) {
return;
}
delete_transient( 'wp_rocket_customer_data' );
}
/**
* Displays the renewal banner for users expiring in less than 30 days
*
* @since 3.7.5
*
* @return void
*/
public function display_renewal_soon_banner() {
$this->renewal->display_renewal_soon_banner();
}
/**
* Displays the renewal banner for expired users
*
* @since 3.7.5
*
* @return void
*/
public function display_renewal_expired_banner() {
$this->renewal->display_renewal_expired_banner();
}
/**
* AJAX callback to dismiss the renewal banner
*
* @since 3.7.5
*
* @return void
*/
public function dismiss_renewal_banner() {
$this->renewal->dismiss_renewal_expired_banner();
}
/**
* Add license expiring warning to OCD label
*
* @param array $args Setting field arguments.
*
* @return array
*/
public function add_license_expire_warning( $args ): array {
return $this->renewal->add_license_expire_warning( $args );
}
/**
* Adds the notification bubble to WP Rocket menu item when expired
*
* @param string $menu_title Menu title.
*
* @return string
*/
public function add_notification_bubble_expired( $menu_title ) {
return $this->renewal->add_expired_bubble( $menu_title );
}
/**
* Sets the dashboard seen transient to hide the expired bubble
*
* @return void
*/
public function set_dashboard_seen_transient() {
$this->renewal->set_dashboard_seen_transient();
}
/**
* Disable optimize CSS delivery setting
*
* @param array $args Array of setting field arguments.
*
* @return array
*/
public function maybe_disable_ocd( $args ) {
return $this->renewal->maybe_disable_ocd( $args );
}
/**
* Disables the RUCSS & Async CSS options if license is expired
*
* @param mixed $value Current option value.
*
* @return mixed
*/
public function maybe_disable_option( $value ) {
return $this->renewal->maybe_disable_option( $value );
}
}
@@ -0,0 +1,417 @@
<?php
namespace WP_Rocket\Engine\License;
use WP_Rocket\Abstract_Render;
use WP_Rocket\Engine\License\API\Pricing;
use WP_Rocket\Engine\License\API\User;
class Upgrade extends Abstract_Render {
/**
* Pricing instance
*
* @var Pricing
*/
private $pricing;
/**
* User instance
*
* @var User
*/
private $user;
/**
* Instantiate the class
*
* @param Pricing $pricing Pricing instance.
* @param User $user User instance.
* @param string $template_path Path to the views.
*/
public function __construct( Pricing $pricing, User $user, $template_path ) {
parent::__construct( $template_path );
$this->pricing = $pricing;
$this->user = $user;
}
/**
* Displays the upgrade section in the license block on the dashboard
*
* @return void
*/
public function display_upgrade_section() {
if ( ! $this->can_upgrade() ) {
return;
}
echo $this->generate( 'upgrade-section' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
}
/**
* Displays the upgrade pop on the dashboard
*
* @return void
*/
public function display_upgrade_popin() {
if ( rocket_get_constant( 'WP_ROCKET_WHITE_LABEL_ACCOUNT' ) ) {
return;
}
if ( ! $this->can_upgrade() ) {
return;
}
$data = [
'is_promo_active' => $this->pricing->is_promo_active(),
'upgrades' => $this->get_upgrade_choices(),
];
echo $this->generate( 'upgrade-popin', $data ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
}
/**
* Adds the notification bubble to WP Rocket menu item when a promo is active
*
* @param string $menu_title Menu title.
* @return string
*/
public function add_notification_bubble( $menu_title ) {
if ( ! $this->can_use_promo() ) {
return $menu_title;
}
if ( false !== get_transient( 'rocket_promo_seen_' . get_current_user_id() ) ) {
return $menu_title;
}
return $menu_title . ' <span class="rocket-promo-bubble">!</span>';
}
/**
* Prevents the notification bubble from showing once the user accessed the dashboard once
*
* @return void
*/
public function dismiss_notification_bubble() {
if ( ! $this->can_use_promo() ) {
return;
}
$user_id = get_current_user_id();
if ( false !== get_transient( "rocket_promo_seen_{$user_id}" ) ) {
return;
}
set_transient( "rocket_promo_seen_{$user_id}", 1, 2 * WEEK_IN_SECONDS );
}
/**
* Displays the promotion banner
*
* @return void
*/
public function display_promo_banner() {
if ( ! $this->can_use_promo() ) {
return;
}
if ( false !== get_transient( 'rocket_promo_banner_' . get_current_user_id() ) ) {
return;
}
$promo = $this->pricing->get_promo_data();
$promo_name = isset( $promo->name ) ? $promo->name : '';
$promo_discount = isset( $promo->discount_percent ) ? $promo->discount_percent : 0;
$data = [
'name' => $promo_name,
'discount_percent' => $promo_discount,
'countdown' => $this->get_countdown_data(),
'message' => $this->get_promo_message( $promo_name, $promo_discount ),
];
echo $this->generate( 'promo-banner', $data ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
}
/**
* AJAX callback to dismiss the promotion banner
*
* @return void
*/
public function dismiss_promo_banner() {
check_ajax_referer( 'rocket-ajax', 'nonce', true );
if ( ! current_user_can( 'rocket_manage_options' ) ) {
return;
}
$user = get_current_user_id();
if ( false !== get_transient( "rocket_promo_banner_{$user}" ) ) {
return;
}
set_transient( "rocket_promo_banner_{$user}", 1, 2 * WEEK_IN_SECONDS );
wp_send_json_success();
}
/**
* Adds the promotion end time to WP Rocket localize script data
*
* @since 3.7.4
*
* @param array $data Localize script data.
* @return array
*/
public function add_localize_script_data( $data ) {
if ( ! is_array( $data ) ) {
$data = (array) $data;
}
if ( ! $this->can_use_promo() ) {
return $data;
}
$data['promo_end'] = $this->pricing->get_promo_end();
return $data;
}
/**
* Returns an array containing the remaining days, hours, minutes & seconds for the promotion
*
* @since 3.7.4
*
* @return array
*/
private function get_countdown_data() {
$data = [
'days' => 0,
'hours' => 0,
'minutes' => 0,
'seconds' => 0,
];
if ( rocket_get_constant( 'WP_ROCKET_IS_TESTING', false ) ) {
return $data;
}
$promo_end = $this->pricing->get_promo_end();
if ( 0 === $promo_end ) {
return $data;
}
$now = date_create();
$end = date_timestamp_set( date_create(), $promo_end );
if ( $now > $end ) {
return $data;
}
$remaining = date_diff( $now, $end );
$format = explode( ' ', $remaining->format( '%d %H %i %s' ) );
$data['days'] = $format[0];
$data['hours'] = $format[1];
$data['minutes'] = $format[2];
$data['seconds'] = $format[3];
return $data;
}
/**
* Returns the promotion message to display in the banner
*
* @param string $promo_name Name of the promotion.
* @param int $promo_discount Discount percentage.
*
* @return string
*/
private function get_promo_message( $promo_name = '', $promo_discount = 0 ) {
$choices = 0;
$license = $this->user->get_license_type();
$plus_websites = $this->pricing->get_plus_websites_count();
if ( $license === $plus_websites ) {
$choices = 2;
} elseif (
$license >= $this->pricing->get_single_websites_count()
&&
$license < $plus_websites
) {
$choices = 1;
}
return sprintf(
// translators: %1$s = promotion name, %2$s = <br>, %3$s = <strong>, %4$s = promotion discount percentage, %5$s = </strong>.
_n(
'Take advantage of %1$s to speed up more websites:%2$s get a %3$s%4$s off%5$s for %3$supgrading your license to Plus or Infinite!%5$s',
'Take advantage of %1$s to speed up more websites:%2$s get a %3$s%4$s off%5$s for %3$supgrading your license to Infinite!%5$s',
$choices,
'rocket'
),
$promo_name,
'<br>',
'<strong>',
$promo_discount . '%',
'</strong>'
);
}
/**
* Checks if current user can use the promotion
*
* @since 3.7.4
*
* @return boolean
*/
private function can_use_promo() {
if ( rocket_get_constant( 'WP_ROCKET_WHITE_LABEL_ACCOUNT' ) ) {
return false;
}
if ( ! $this->can_upgrade() ) {
return false;
}
if ( $this->is_expired_soon() ) {
return false;
}
if ( $this->is_new_user() ) {
return false;
}
return $this->pricing->is_promo_active();
}
/**
* Checks if the license expires in less than 30 days
*
* @return boolean
*/
private function is_expired_soon() {
$expiration_delay = $this->user->get_license_expiration() - time();
return 30 * DAY_IN_SECONDS > $expiration_delay;
}
/**
* Checks if the User license bought less than 14 days
*
* @return boolean
*/
private function is_new_user() {
return ( 14 * DAY_IN_SECONDS ) > time() - $this->user->get_creation_date();
}
/**
* Checks if the current license can upgrade
*
* @return boolean
*/
private function can_upgrade() {
return (
-1 !== $this->user->get_license_type()
&&
! $this->user->is_license_expired()
);
}
/**
* Gets the upgrade choices depending on the current license level
*
* @return array
*/
private function get_upgrade_choices() {
$choices = [];
$license = $this->user->get_license_type();
$plus_websites = $this->pricing->get_plus_websites_count();
if ( $license === $plus_websites ) {
$choices['infinite'] = $this->get_upgrade_from_plus_to_infinite_data();
} elseif (
$license >= $this->pricing->get_single_websites_count()
&&
$license < $plus_websites
) {
$choices['plus'] = $this->get_upgrade_from_single_to_plus_data();
$choices['infinite'] = $this->get_upgrade_from_single_to_infinite_data();
}
return $choices;
}
/**
* Gets the data to upgrade from single to plus
*
* @return array
*/
private function get_upgrade_from_single_to_plus_data() {
$price = $this->pricing->get_single_to_plus_price();
$data = [
'name' => 'Plus',
'price' => $price,
'websites' => $this->pricing->get_plus_websites_count(),
'upgrade_url' => $this->user->get_upgrade_plus_url(),
];
if ( $this->pricing->is_promo_active() ) {
$regular_price = $this->pricing->get_regular_single_to_plus_price();
$data['saving'] = $regular_price - $price;
$data['regular_price'] = $regular_price;
}
return $data;
}
/**
* Gets the data to upgrade from single to infinite
*
* @return array
*/
private function get_upgrade_from_single_to_infinite_data() {
$price = $this->pricing->get_single_to_infinite_price();
$data = [
'name' => 'Infinite',
'price' => $price,
'websites' => __( 'Unlimited', 'rocket' ),
'upgrade_url' => $this->user->get_upgrade_infinite_url(),
];
if ( $this->pricing->is_promo_active() ) {
$regular_price = $this->pricing->get_regular_single_to_infinite_price();
$data['saving'] = $regular_price - $price;
$data['regular_price'] = $regular_price;
}
return $data;
}
/**
* Gets the data to upgrade from plus to infinite
*
* @return array
*/
private function get_upgrade_from_plus_to_infinite_data() {
$price = $this->pricing->get_plus_to_infinite_price();
$data = [
'name' => 'Infinite',
'price' => $price,
'websites' => __( 'Unlimited', 'rocket' ),
'upgrade_url' => $this->user->get_upgrade_infinite_url(),
];
if ( $this->pricing->is_promo_active() ) {
$regular_price = $this->pricing->get_regular_plus_to_infinite_price();
$data['saving'] = $regular_price - $price;
$data['regular_price'] = $regular_price;
}
return $data;
}
}
@@ -0,0 +1,37 @@
<?php
/**
* Promo banner.
*
* @since 3.7.4
*/
defined( 'ABSPATH' ) || exit;
?>
<div class="rocket-promo-banner" id="rocket-promo-banner">
<div>
<h3 class="rocket-promo-title">
<span class="rocket-promo-discount">
<?php
// translators: %s = promotion discount percentage.
printf( esc_html__( '%s off', 'rocket' ), esc_html( $data['discount_percent'] . '%' ) );
?>
</span>
<?php
// translators: %s = promotion name.
printf( esc_html__( '%s promotion is live!', 'rocket' ), esc_html( $data['name'] ) );
?>
</h3>
<p class="rocket-promo-message"><?php echo wp_kses_post( $data['message'] ); ?></p>
</div>
<div class="rocket-promo-cta-block">
<p class="rocket-promo-deal"><?php esc_html_e( 'Hurry Up! Deal ends in:', 'rocket' ); ?></p>
<ul class="rocket-promo-countdown" id="rocket-promo-countdown">
<li class="rocket-countdown-item"><span class="rocket-countdown-value rocket-countdown-days"><?php echo esc_html( $data['countdown']['days'] ); ?></span> <?php esc_html_e( 'Days', 'rocket' ); ?></li>
<li class="rocket-countdown-item"><span class="rocket-countdown-value rocket-countdown-hours"><?php echo esc_html( $data['countdown']['hours'] ); ?></span> <?php esc_html_e( 'Hours', 'rocket' ); ?></li>
<li class="rocket-countdown-item"><span class="rocket-countdown-value rocket-countdown-minutes"><?php echo esc_html( $data['countdown']['minutes'] ); ?></span> <?php esc_html_e( 'Minutes', 'rocket' ); ?></li>
<li class="rocket-countdown-item"><span class="rocket-countdown-value rocket-countdown-seconds"><?php echo esc_html( $data['countdown']['seconds'] ); ?></span> <?php esc_html_e( 'Seconds', 'rocket' ); ?></li>
</ul>
<button class="rocket-promo-cta wpr-popin-upgrade-toggle"><?php esc_html_e( 'Upgrade now', 'rocket' ); ?></button>
</div>
<button class="wpr-notice-close wpr-icon-close" id="rocket-dismiss-promotion"><span class="screen-reader-text"><?php esc_html_e( 'Dismiss this notice', 'rocket' ); ?></span></button>
</div>
@@ -0,0 +1,33 @@
<?php
/**
* Renewal expired banner with OCD disabled.
*
* @since 3.11.5
*/
defined( 'ABSPATH' ) || exit;
?>
<section class="rocket-renewal-expired-banner" id="rocket-renewal-banner">
<h3 class="rocket-expired-title"><?php esc_html_e( 'The Optimize CSS Delivery feature is disabled.', 'rocket' ); ?></h3>
<div class="rocket-renewal-expired-banner-container">
<div class="rocket-expired-message">
<p>
<?php esc_html_e( 'You can no longer use the Remove Unused CSS or Load CSS asynchronously options.', 'rocket' ); ?>
<br>
<?php
printf(
// translators: %1$s = <strong>, %2$s = </strong>.
esc_html__( 'You need an %1$sactive license%2$s to keep optimizing your CSS delivery, which addresses a PageSpeed Insights recommendation and improves your page performance.', 'rocket' ),
'<strong>',
'</strong>'
);
?>
</p>
<p><?php echo $data['message']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></p>
</div>
<div class="rocket-expired-cta-container">
<a href="<?php echo esc_url( $data['renewal_url'] ); ?>" class="rocket-renew-cta" target="_blank" rel="noopener noreferrer"><?php esc_html_e( 'Renew now', 'rocket' ); ?></a>
</div>
</div>
<button class="wpr-notice-close wpr-icon-close" id="rocket-dismiss-renewal"><span class="screen-reader-text"><?php esc_html_e( 'Dismiss this notice', 'rocket' ); ?></span></button>
</section>
@@ -0,0 +1,43 @@
<?php
/**
* Renewal expired banner with OCD.
*
* @since 3.11.5
*/
defined( 'ABSPATH' ) || exit;
?>
<section class="rocket-renewal-expired-banner" id="rocket-renewal-banner">
<h3 class="rocket-expired-title"><?php esc_html_e( 'You will soon lose access to some features', 'rocket' ); ?></h3>
<div class="rocket-renewal-expired-banner-container">
<div class="rocket-expired-message">
<p>
<?php
printf(
// translators: %1$s = <strong>, %2$s = </strong>.
esc_html__( 'You need an %1$sactive license to continue optimizing your CSS delivery%2$s.', 'rocket' ),
'<strong>',
'</strong>'
);
?>
<br>
<?php esc_html_e( 'The Remove Unused CSS and Load CSS asynchronously features are great options to address the PageSpeed Insights recommendations and improve your website performance.', 'rocket' ); ?>
<br>
<?php
printf(
// translators: %1$s = <strong>, %2$s = </strong>, %3$s = date.
esc_html__( 'They will be %1$sautomatically disabled on %3$s%2$s.', 'rocket' ),
'<strong>',
'</strong>',
esc_html( $data['disabled_date'] )
);
?>
</p>
<p><?php echo $data['message']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></p>
</div>
<div class="rocket-expired-cta-container">
<a href="<?php echo esc_url( $data['renewal_url'] ); ?>" class="rocket-renew-cta" target="_blank" rel="noopener noreferrer"><?php esc_html_e( 'Renew now', 'rocket' ); ?></a>
</div>
</div>
<button class="wpr-notice-close wpr-icon-close" id="rocket-dismiss-renewal"><span class="screen-reader-text"><?php esc_html_e( 'Dismiss this notice', 'rocket' ); ?></span></button>
</section>
@@ -0,0 +1,31 @@
<?php
/**
* Renewal expired banner.
*
* @since 3.7.5
*/
defined( 'ABSPATH' ) || exit;
?>
<section class="rocket-renewal-expired-banner" id="rocket-renewal-banner">
<h3 class="rocket-expired-title"><?php esc_html_e( 'Your WP Rocket license is expired!', 'rocket' ); ?></h3>
<div class="rocket-renewal-expired-banner-container">
<div class="rocket-expired-message">
<p>
<?php
printf(
// translators: %1$s = <strong>, %2$s = </strong>.
esc_html__( 'Your website could be much faster if it could take advantage of our %1$snew features and enhancements%2$s. 🚀', 'rocket' ),
'<strong>',
'</strong>'
);
?>
</p>
<p><?php echo $data['message']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></p>
</div>
<div class="rocket-expired-cta-container">
<a href="<?php echo esc_url( $data['renewal_url'] ); ?>" class="rocket-renew-cta" target="_blank" rel="noopener noreferrer"><?php esc_html_e( 'Renew now', 'rocket' ); ?></a>
</div>
</div>
<button class="wpr-notice-close wpr-icon-close" id="rocket-dismiss-renewal"><span class="screen-reader-text"><?php esc_html_e( 'Dismiss this notice', 'rocket' ); ?></span></button>
</section>
@@ -0,0 +1,33 @@
<?php
/**
* Renewal soon banner.
*
* @since 3.7.5
*/
defined( 'ABSPATH' ) || exit;
?>
<div class="rocket-renewal-banner">
<ul class="rocket-promo-countdown" id="rocket-renew-countdown">
<li class="rocket-countdown-item"><span class="rocket-countdown-value rocket-countdown-days"><?php echo esc_html( $data['countdown']['days'] ); ?></span> <?php esc_html_e( 'Days', 'rocket' ); ?></li>
<li class="rocket-countdown-item"><span class="rocket-countdown-value rocket-countdown-hours"><?php echo esc_html( $data['countdown']['hours'] ); ?></span> <?php esc_html_e( 'Hours', 'rocket' ); ?></li>
<li class="rocket-countdown-item"><span class="rocket-countdown-value rocket-countdown-minutes"><?php echo esc_html( $data['countdown']['minutes'] ); ?></span> <?php esc_html_e( 'Minutes', 'rocket' ); ?></li>
<li class="rocket-countdown-item"><span class="rocket-countdown-value rocket-countdown-seconds"><?php echo esc_html( $data['countdown']['seconds'] ); ?></span> <?php esc_html_e( 'Seconds', 'rocket' ); ?></li>
</ul>
<div class="rocket-renew-message">
<p>
<?php
printf(
// translators: %1$s = <strong>, %2$s = </strong>.
esc_html__( 'Your %1$sWP Rocket license is about to expire%2$s: you will soon lose access to product updates and support.', 'rocket' ),
'<strong>',
'</strong>'
);
?>
</p>
<p><?php echo $data['message']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></p>
</div>
<div class="rocket-renew-cta-container">
<a href="<?php echo esc_url( $data['renewal_url'] ); ?>" class="rocket-renew-cta" target="_blank" rel="noopener noreferrer"><?php esc_html_e( 'Renew now', 'rocket' ); ?></a>
</div>
</div>
@@ -0,0 +1,61 @@
<?php
/**
* Upgrade section template.
*
* @since 3.7.3
*/
defined( 'ABSPATH' ) || exit;
?>
<div class="wpr-Popin wpr-Popin-Upgrade">
<div class="wpr-Popin-header">
<h2 class="wpr-title1"><?php esc_html_e( 'Speed Up More Websites', 'rocket' ); ?></h2>
<button class="wpr-Popin-close wpr-Popin-Upgrade-close wpr-icon-close"></button>
</div>
<div class="wpr-Popin-content">
<p>
<?php
// translators: %1$s = opening strong tag, %2$s = closing strong tag.
printf( esc_html__( 'You can use WP Rocket on more websites by upgrading your license. To upgrade, simply pay the %1$sprice difference%2$s between your current and new licenses, as shown below.', 'rocket' ), '<strong>', '</strong>' );
?>
</p>
<p>
<?php
// translators: %1$s = opening strong tag, %2$s = closing strong tag.
printf( esc_html__( '%1$sN.B.%2$s: Upgrading your license does not change your expiration date', 'rocket' ), '<strong>', '</strong>' );
?>
</p>
<div class="wpr-Popin-flex">
<?php foreach ( $data['upgrades'] as $rocket_upgrade ) : ?>
<div class="wpr-Upgrade-<?php echo esc_attr( $rocket_upgrade['name'] ); ?>">
<?php if ( true === $data['is_promo_active'] ) : ?>
<div class="wpr-upgrade-saving">
<?php
// translators: %s = price.
printf( esc_html__( 'Save $%s', 'rocket' ), esc_html( $rocket_upgrade['saving'] ) );
?>
</div>
<?php endif; ?>
<h3 class="wpr-upgrade-title"><?php echo esc_html( $rocket_upgrade['name'] ); ?></h3>
<div class="wpr-upgrade-prices"><span class="wpr-upgrade-price-symbol">$</span> <?php echo esc_html( $rocket_upgrade['price'] ); ?>
<?php if ( true === $data['is_promo_active'] ) : ?>
<del class="wpr-upgrade-price-regular">$ <?php echo esc_html( $rocket_upgrade['regular_price'] ); ?></del>
<?php endif; ?>
</div>
<div class="wpr-upgrade-websites">
<?php
// translators: %s = number of websites.
printf( esc_html__( '%s websites', 'rocket' ), esc_html( $rocket_upgrade['websites'] ) );
?>
</div>
<a href="<?php echo esc_url( $rocket_upgrade['upgrade_url'] ); ?>" class="wpr-upgrade-link" target="_blank" rel="noopener noreferrer">
<?php
// translators: %s = license name.
printf( esc_html__( 'Upgrade to %s', 'rocket' ), esc_html( $rocket_upgrade['name'] ) );
?>
</a>
</div>
<?php endforeach; ?>
</div>
</div>
</div>
@@ -0,0 +1,12 @@
<?php
/**
* Upgrade section template.
*
* @since 3.7.3
*/
defined( 'ABSPATH' ) || exit;
?>
<p>
<?php esc_html_e( 'You can use WP Rocket on more websites by upgrading your license (you will only pay the price difference between your current and new licenses).', 'rocket' ); ?> <button class="wpr-license-upgrade-button wpr-popin-upgrade-toggle"><?php esc_html_e( 'Upgrade now', 'rocket' ); ?></button>
</p>