Skip to content

Commit 063d888

Browse files
fix: Black Friday for 2025 (#997)
- Modified the Black Friday logic to use the SDK flag for detection. - Modified the messages. - Added monthly to yearly update path vis support contact. - Added unit tests.
1 parent 970e9f8 commit 063d888

File tree

5 files changed

+420
-43
lines changed

5 files changed

+420
-43
lines changed

assets/src/dashboard/parts/connected/Sidebar.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ const Sidebar = ({ settings, setSettings, setCanSave, setTab }) => {
103103
<Button
104104
variant="link"
105105
className="optml__button flex w-full justify-center font-bold min-h-40 !no-underline !text-white !bg-opaque-black !rounded"
106-
href={ optimoleDashboardApp.optimoleHome + 'pricing' }
106+
href={ optimoleDashboardApp?.bf_notices?.sidebar?.cta_link ?? optimoleDashboardApp.upgrade_url }
107107
target="_blank"
108108
>
109109
{ optimoleDashboardApp.strings.upgrade.cta }

assets/src/dashboard/parts/connected/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ const ConnectedLayout = ({
9393
}
9494
}, [ canSave ]);
9595

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

9898
return (
9999
<div className="optml-connected 2xl:max-w-screen-xl max-w-screen px-4 mx-auto">

inc/admin.php

Lines changed: 82 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class Optml_Admin {
2323

2424
const IMAGE_DATA_COLLECTED_BATCH = 100;
2525

26-
const BF_PROMO_DISMISS_KEY = 'optml_bf24_notice_dismiss';
26+
const BF_PROMO_DISMISS_KEY = 'optml_bf25_notice_dismiss';
2727

2828
const SPC_BANNER_DISMISS_KEY = 'optml_spc_banner_dismiss';
2929

@@ -711,6 +711,7 @@ public function should_show_upgrade() {
711711
*/
712712
public static function get_upgrade_base_link() {
713713
$base_url = 'https://optimole.com/upgrade';
714+
$base_url = tsdk_translate_link( $base_url );
714715
$email = self::get_account_email();
715716

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

724+
/**
725+
* Get contact URL.
726+
*
727+
* @return string Contact URL.
728+
*/
729+
public static function get_contact_base_link() {
730+
return tsdk_translate_link( 'https://optimole.com/contact' );
731+
}
732+
723733
/**
724734
* Retrieve Optimole account email.
725735
*
@@ -1396,6 +1406,9 @@ private function localize_dashboard_app() {
13961406
$service_data['renews_on_formatted'] = date_i18n( get_option( 'date_format' ), $service_data['renews_on'] );
13971407

13981408
}
1409+
1410+
$user_plan = isset( $service_data['plan'] ) ? $service_data['plan'] : 'free';
1411+
13991412
return [
14001413
'strings' => $this->get_dashboard_strings(),
14011414
'assets_url' => OPTML_URL . 'assets/',
@@ -1432,7 +1445,7 @@ private function localize_dashboard_app() {
14321445
'hash' => '#settings',
14331446
],
14341447
],
1435-
'bf_notices' => $this->get_bf_notices(),
1448+
'bf_notices' => $this->get_bf_notices( $user_plan ),
14361449
'spc_banner' => $this->get_spc_banner(),
14371450
'show_exceed_plan_quota_notice' => $this->should_show_exceed_quota_warning(),
14381451
'show_free_user_with_offload_notice' => get_option( 'optml_has_offloading_enabled_on_upgrade', 'no' ),
@@ -1443,8 +1456,9 @@ private function localize_dashboard_app() {
14431456
'utm_campaign' => 'report_issue',
14441457
'contact_website' => home_url(),
14451458
],
1446-
tsdk_translate_link( 'https://optimole.com/contact/' )
1459+
self::get_contact_base_link()
14471460
),
1461+
'upgrade_url' => esc_url( self::get_upgrade_base_link() ),
14481462
];
14491463
}
14501464

@@ -1535,53 +1549,86 @@ private function get_spc_status() {
15351549
/**
15361550
* Get the black friday notices.
15371551
*
1538-
* @return array
1552+
* @param non-empty-string $user_plan User plan.
1553+
*
1554+
* @return array<string, mixed> Notice data.
15391555
*/
1540-
public function get_bf_notices() {
1541-
$date = new DateTime();
1556+
public function get_bf_notices( $user_plan ) {
15421557

1543-
$now = time();
1544-
$start = strtotime( '2024-11-25 00:00:00' );
1545-
$end = strtotime( '2024-12-03 23:59:59' );
1558+
$notices = [];
1559+
$has_free_plan = 'free' === $user_plan;
15461560

1547-
if ( $now < $start || $now > $end ) {
1548-
return [];
1561+
if ( ! $has_free_plan ) {
1562+
return $notices;
15491563
}
15501564

1551-
$notices = [
1552-
'sidebar' => [
1553-
'title' => sprintf(
1554-
'<span class="text-promo-orange">%1$s:</span> %2$s',
1555-
__( 'Private Sale', 'optimole-wp' ),
1556-
__( '25 Nov - 03 Dec', 'optimole-wp' )
1557-
),
1558-
'subtitle' => sprintf(
1559-
/* translators: 1 is the promo code, 2 is the discount amount ('25 off') */
1560-
__( 'Use code %1$s for %2$s on yearly plans.', 'optimole-wp' ),
1561-
'<span class="border-b border-0 border-white border-dashed text-promo-orange">BFCM2425</span>',
1562-
'<span class="text-promo-orange uppercase">' . __( '25% off', 'optimole-wp' ) . '</span>'
1563-
),
1564-
'cta_link' => esc_url_raw( tsdk_utmify( tsdk_translate_link( self::get_upgrade_base_link() ), 'bfcm24', 'sidebarnotice' ) ),
1565-
],
1565+
/**
1566+
* The black friday sale period flag.
1567+
*
1568+
* @var bool $is_black_friday Whether is black friday sale period or not.
1569+
*/
1570+
$is_black_friday = apply_filters( 'themeisle_sdk_is_black_friday_sale', false );
1571+
1572+
if ( ! $is_black_friday ) {
1573+
return $notices;
1574+
}
1575+
1576+
/**
1577+
* The current date.
1578+
*
1579+
* @var DateTime $now Current date.
1580+
*/
1581+
$now = apply_filters( 'themeisle_sdk_current_date', new \DateTime( 'now' ) );
1582+
$current_year = $now->format( 'Y' );
1583+
1584+
$black_friday_day = new \DateTime( "last Friday of November $current_year" );
1585+
$sale_start = clone $black_friday_day;
1586+
$sale_start->modify( 'monday this week' );
1587+
$sale_start->setTime( 0, 0 );
1588+
1589+
$end = clone $sale_start;
1590+
$end->modify( '+7 days' );
1591+
$end->setTime( 23, 59, 59 );
1592+
1593+
$promo_code = 'BFCM2525';
1594+
1595+
$notices['sidebar'] = [
1596+
'title' => sprintf(
1597+
'<span class="text-promo-orange">%1$s:</span> %2$s - %3$s',
1598+
__( 'Private Sale', 'optimole-wp' ),
1599+
wp_date( 'j M', $sale_start->getTimestamp() ),
1600+
wp_date( 'j M', $end->getTimestamp() )
1601+
),
1602+
'subtitle' => sprintf(
1603+
/* translators: %1$s is the promo code, %2$s is the discount amount ('25 off') */
1604+
__( 'Use code %1$s for %2$s on yearly plans.', 'optimole-wp' ),
1605+
'<span class="border-b border-0 border-white border-dashed text-promo-orange">' . $promo_code . '</span>',
1606+
'<span class="text-promo-orange uppercase">' . __( '25% discount', 'optimole-wp' ) . '</span>'
1607+
),
1608+
'cta_link' => esc_url_raw( tsdk_utmify( tsdk_translate_link( self::get_upgrade_base_link() ), 'bfcm25', 'sidebarnotice' ) ),
15661609
];
15671610

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

1615+
$message = sprintf(
1616+
// translators: %1$s is the promo code, %2$s is the discount amount ('25% off')
1617+
__( 'Use coupon code %1$s for an instant %2$s on Optimole yearly plans', 'optimole-wp' ),
1618+
'<span class="border-b border-0 border-white border-dashed text-promo-orange">' . $promo_code . '</span>',
1619+
'<span class="text-promo-orange uppercase">' . __( '25% discount', 'optimole-wp' ) . '</span>'
1620+
);
1621+
$cta_link = esc_url_raw( tsdk_utmify( self::get_upgrade_base_link(), 'bfcm25', 'notice' ) );
1622+
$cta_text = __( 'Claim now', 'optimole-wp' );
1623+
15721624
$notices['banner'] = [
15731625
/* translators: number of days left */
1574-
'urgency' => sprintf( __( 'Hurry up! only %s left', 'optimole-wp' ), human_time_diff( $end, $now ) ),
1626+
'urgency' => sprintf( __( 'Hurry up! only %s left', 'optimole-wp' ), human_time_diff( $end->getTimestamp(), $now->getTimestamp() ) ),
15751627
/* translators: private sale */
15761628
'title' => sprintf( __( 'Black Friday %s', 'optimole-wp' ), '<span class="text-promo-orange">' . __( 'private sale', 'optimole-wp' ) . '</span>' ),
1577-
'subtitle' => sprintf(
1578-
/* translators: 1 is the promo code, 2 is the discount amount ('25 off') */
1579-
__( 'Use coupon code %1$s for an instant %2$s on Optimole yearly plans', 'optimole-wp' ),
1580-
'<span class="border-b border-0 border-white border-dashed text-promo-orange">BFCM2425</span>',
1581-
'<span class="text-promo-orange">' . __( '25% discount', 'optimole-wp' ) . '</span>'
1582-
),
1583-
'cta_text' => __( 'Claim now', 'optimole-wp' ),
1584-
'cta_link' => esc_url_raw( tsdk_utmify( tsdk_translate_link( self::get_upgrade_base_link() ), 'bfcm24', 'dismissiblenotice' ) ),
1629+
'subtitle' => $message,
1630+
'cta_text' => $cta_text,
1631+
'cta_link' => $cta_link,
15851632
'dismiss_key' => self::BF_PROMO_DISMISS_KEY,
15861633
];
15871634

phpstan-baseline.neon

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -168,12 +168,6 @@ parameters:
168168
count: 1
169169
path: inc/admin.php
170170

171-
-
172-
message: '#^Method Optml_Admin\:\:get_bf_notices\(\) return type has no value type specified in iterable type array\.$#'
173-
identifier: missingType.iterableValue
174-
count: 1
175-
path: inc/admin.php
176-
177171
-
178172
message: '#^Method Optml_Admin\:\:get_dashboard_strings\(\) return type has no value type specified in iterable type array\.$#'
179173
identifier: missingType.iterableValue

0 commit comments

Comments
 (0)