Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion assets/src/dashboard/parts/connected/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ const ConnectedLayout = ({
}
}, [ canSave ]);

const showBFBanner = 'free' === plan && optimoleDashboardApp?.bf_notices?.banner;
const showBFBanner = Boolean( optimoleDashboardApp?.bf_notices?.banner );

return (
<div className="optml-connected 2xl:max-w-screen-xl max-w-screen px-4 mx-auto">
Expand Down
116 changes: 81 additions & 35 deletions inc/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Optml_Admin {

const IMAGE_DATA_COLLECTED_BATCH = 100;

const BF_PROMO_DISMISS_KEY = 'optml_bf24_notice_dismiss';
const BF_PROMO_DISMISS_KEY = 'optml_bf25_notice_dismiss';

const SPC_BANNER_DISMISS_KEY = 'optml_spc_banner_dismiss';

Expand Down Expand Up @@ -711,6 +711,7 @@ public function should_show_upgrade() {
*/
public static function get_upgrade_base_link() {
$base_url = 'https://optimole.com/upgrade';
$base_url = tsdk_translate_link( $base_url );
$email = self::get_account_email();

if ( ! empty( $email ) ) {
Expand All @@ -720,6 +721,15 @@ public static function get_upgrade_base_link() {
return $base_url;
}

/**
* Get contact URL.
*
* @return string Contact URL.
*/
public static function get_contact_base_link() {
return tsdk_translate_link( 'https://optimole.com/contact' );
}

/**
* Retrieve Optimole account email.
*
Expand Down Expand Up @@ -1396,6 +1406,9 @@ private function localize_dashboard_app() {
$service_data['renews_on_formatted'] = date_i18n( get_option( 'date_format' ), $service_data['renews_on'] );

}

$user_plan = isset( $service_data['plan'] ) ? $service_data['plan'] : 'free';

return [
'strings' => $this->get_dashboard_strings(),
'assets_url' => OPTML_URL . 'assets/',
Expand Down Expand Up @@ -1432,7 +1445,7 @@ private function localize_dashboard_app() {
'hash' => '#settings',
],
],
'bf_notices' => $this->get_bf_notices(),
'bf_notices' => $this->get_bf_notices( $user_plan ),
'spc_banner' => $this->get_spc_banner(),
'show_exceed_plan_quota_notice' => $this->should_show_exceed_quota_warning(),
'show_free_user_with_offload_notice' => get_option( 'optml_has_offloading_enabled_on_upgrade', 'no' ),
Expand All @@ -1443,7 +1456,7 @@ private function localize_dashboard_app() {
'utm_campaign' => 'report_issue',
'contact_website' => home_url(),
],
tsdk_translate_link( 'https://optimole.com/contact/' )
self::get_contact_base_link()
),
];
}
Expand Down Expand Up @@ -1535,53 +1548,86 @@ private function get_spc_status() {
/**
* Get the black friday notices.
*
* @return array
* @param non-empty-string $user_plan User plan.
*
* @return array<string, mixed> Notice data.
*/
public function get_bf_notices() {
$date = new DateTime();
public function get_bf_notices( $user_plan ) {

$now = time();
$start = strtotime( '2024-11-25 00:00:00' );
$end = strtotime( '2024-12-03 23:59:59' );
$notices = [];
$has_free_plan = 'free' === $user_plan;

if ( $now < $start || $now > $end ) {
return [];
if ( ! $has_free_plan ) {
return $notices;
}

$notices = [
'sidebar' => [
'title' => sprintf(
'<span class="text-promo-orange">%1$s:</span> %2$s',
__( 'Private Sale', 'optimole-wp' ),
__( '25 Nov - 03 Dec', 'optimole-wp' )
),
'subtitle' => sprintf(
/* translators: 1 is the promo code, 2 is the discount amount ('25 off') */
__( 'Use code %1$s for %2$s on yearly plans.', 'optimole-wp' ),
'<span class="border-b border-0 border-white border-dashed text-promo-orange">BFCM2425</span>',
'<span class="text-promo-orange uppercase">' . __( '25% off', 'optimole-wp' ) . '</span>'
),
'cta_link' => esc_url_raw( tsdk_utmify( tsdk_translate_link( self::get_upgrade_base_link() ), 'bfcm24', 'sidebarnotice' ) ),
],
/**
* The black friday sale period flag.
*
* @var bool $is_black_friday Whether is black friday sale period or not.
*/
$is_black_friday = apply_filters( 'themeisle_sdk_is_black_friday_sale', false );

if ( ! $is_black_friday ) {
return $notices;
}

/**
* The current date.
*
* @var DateTime $now Current date.
*/
$now = apply_filters( 'themeisle_sdk_current_date', new \DateTime( 'now' ) );
$current_year = $now->format( 'Y' );

$black_friday_day = new DateTime( "last Friday of November $current_year" );
Comment thread
Soare-Robert-Daniel marked this conversation as resolved.
Outdated
$sale_start = clone $black_friday_day;
$sale_start->modify( 'monday this week' );
$sale_start->setTime( 0, 0 );

$end = clone $sale_start;
$end->modify( '+7 days' );
$end->setTime( 23, 59, 59 );

$promo_code = 'BFCM2525';

$notices['sidebar'] = [
'title' => sprintf(
'<span class="text-promo-orange">%1$s:</span> %2$s - %3$s',
__( 'Private Sale', 'optimole-wp' ),
wp_date( 'j M', $sale_start->getTimestamp() ),
wp_date( 'j M', $end->getTimestamp() )
),
'subtitle' => sprintf(
/* translators: %1$s is the promo code, %2$s is the discount amount ('25 off') */
__( 'Use code %1$s for an instant %2$s', 'optimole-wp' ),
'<span class="border-b border-0 border-white border-dashed text-promo-orange">' . $promo_code . '</span>',
'<span class="text-promo-orange uppercase">' . __( '25% discount', 'optimole-wp' ) . '</span>'
),
'cta_link' => esc_url_raw( tsdk_utmify( tsdk_translate_link( self::get_upgrade_base_link() ), 'bfcm25', 'sidebarnotice' ) ),
];

if ( get_option( self::BF_PROMO_DISMISS_KEY ) === 'yes' ) {
return $notices;
}

$message = sprintf(
// translators: $1$s is the promo code, $2$s is the discount amount ('25% off')
Comment thread
Soare-Robert-Daniel marked this conversation as resolved.
Outdated
__( 'Use coupon code %1$s for an instant %2$s on your first billing cycle on Optimole plan.', 'optimole-wp' ),
'<span class="border-b border-0 border-white border-dashed text-promo-orange">' . $promo_code . '</span>',
'<span class="text-promo-orange uppercase">' . __( '25% discount', 'optimole-wp' ) . '</span>'
);
$cta_link = esc_url_raw( tsdk_utmify( self::get_upgrade_base_link(), 'bfcm25', 'notice' ) );
$cta_text = __( 'Claim now', 'optimole-wp' );

$notices['banner'] = [
/* translators: number of days left */
'urgency' => sprintf( __( 'Hurry up! only %s left', 'optimole-wp' ), human_time_diff( $end, $now ) ),
'urgency' => sprintf( __( 'Hurry up! only %s left', 'optimole-wp' ), human_time_diff( $end->getTimestamp(), $now->getTimestamp() ) ),
/* translators: private sale */
'title' => sprintf( __( 'Black Friday %s', 'optimole-wp' ), '<span class="text-promo-orange">' . __( 'private sale', 'optimole-wp' ) . '</span>' ),
'subtitle' => sprintf(
/* translators: 1 is the promo code, 2 is the discount amount ('25 off') */
__( 'Use coupon code %1$s for an instant %2$s on Optimole yearly plans', 'optimole-wp' ),
'<span class="border-b border-0 border-white border-dashed text-promo-orange">BFCM2425</span>',
'<span class="text-promo-orange">' . __( '25% discount', 'optimole-wp' ) . '</span>'
),
'cta_text' => __( 'Claim now', 'optimole-wp' ),
'cta_link' => esc_url_raw( tsdk_utmify( tsdk_translate_link( self::get_upgrade_base_link() ), 'bfcm24', 'dismissiblenotice' ) ),
'subtitle' => $message,
'cta_text' => $cta_text,
'cta_link' => $cta_link,
'dismiss_key' => self::BF_PROMO_DISMISS_KEY,
];

Expand Down
6 changes: 0 additions & 6 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -168,12 +168,6 @@ parameters:
count: 1
path: inc/admin.php

-
message: '#^Method Optml_Admin\:\:get_bf_notices\(\) return type has no value type specified in iterable type array\.$#'
identifier: missingType.iterableValue
count: 1
path: inc/admin.php

-
message: '#^Method Optml_Admin\:\:get_dashboard_strings\(\) return type has no value type specified in iterable type array\.$#'
identifier: missingType.iterableValue
Expand Down
Loading
Loading