Skip to content

Commit 93b5f91

Browse files
fix: tweaks
1 parent 67b3028 commit 93b5f91

2 files changed

Lines changed: 67 additions & 32 deletions

File tree

inc/admin.php

Lines changed: 41 additions & 28 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 ) ) {
@@ -1553,11 +1554,12 @@ private function get_spc_status() {
15531554
*/
15541555
public function get_bf_notices( $user_plan ) {
15551556

1557+
$notices = [];
15561558
$has_free_plan = 'free' === $user_plan;
15571559
$has_monthly_plan = strpos( $user_plan, '-yearly' ) === false && ! $has_free_plan;
15581560

15591561
if ( ! $has_free_plan && ! $has_monthly_plan ) {
1560-
return [];
1562+
return $notices;
15611563
}
15621564

15631565
/**
@@ -1568,7 +1570,7 @@ public function get_bf_notices( $user_plan ) {
15681570
$is_black_friday = apply_filters( 'themeisle_sdk_is_black_friday_sale', false );
15691571

15701572
if ( ! $is_black_friday ) {
1571-
return [];
1573+
return $notices;
15721574
}
15731575

15741576
/**
@@ -1588,47 +1590,58 @@ public function get_bf_notices( $user_plan ) {
15881590
$end->modify( '+7 days' );
15891591
$end->setTime( 23, 59, 59 );
15901592

1593+
$promo_code = 'BFCM2525';
1594+
1595+
if ( $has_free_plan ) {
1596+
$notices['sidebar'] = [
1597+
'title' => sprintf(
1598+
'<span class="text-promo-orange">%1$s:</span> %2$s - %3$s',
1599+
__( 'Private Sale', 'optimole-wp' ),
1600+
$sale_start->format( 'j M' ),
1601+
$end->format( 'j M' )
1602+
),
1603+
'subtitle' => sprintf(
1604+
/* translators: %1$s is the promo code, %2$s is the discount amount ('25 off') */
1605+
__( 'Use code %1$s for an instant %2$s', 'optimole-wp' ),
1606+
'<span class="border-b border-0 border-white border-dashed text-promo-orange">' . $promo_code .'</span>',
1607+
'<span class="text-promo-orange uppercase">' . __( '25% off', 'optimole-wp' ) . '</span>'
1608+
),
1609+
'cta_link' => esc_url_raw( tsdk_utmify( tsdk_translate_link( self::get_upgrade_base_link() ), 'bfcm25', 'sidebarnotice' ) ),
1610+
];
1611+
}
1612+
1613+
if ( get_option( self::BF_PROMO_DISMISS_KEY ) === 'yes' ) {
1614+
return $notices;
1615+
}
1616+
15911617
$message = sprintf(
1592-
/* translators: 1 is the promo code, 2 is the discount amount ('25 off') */
1618+
// translators: $1$s is the promo code, $2$s is the discount amount ('25% off')
15931619
__( 'Use coupon code %1$s for an instant %2$s on your first billing cycle on Optimole plan.', 'optimole-wp' ),
1594-
'<span class="border-b border-0 border-white border-dashed text-promo-orange">BFCM2525</span>',
1620+
'<span class="border-b border-0 border-white border-dashed text-promo-orange">' . $promo_code . '</span>',
15951621
'<span class="text-promo-orange uppercase">' . __( '25% off', 'optimole-wp' ) . '</span>'
15961622
);
1597-
$cta_link = esc_url_raw( tsdk_utmify( tsdk_translate_link( self::get_upgrade_base_link() ), 'bfcm25', 'notice' ) );
1623+
$cta_link = esc_url_raw( tsdk_utmify( self::get_upgrade_base_link(), 'bfcm25', 'notice' ) );
15981624
$cta_text = __( 'Claim now', 'optimole-wp' );
15991625

16001626
if ( $has_monthly_plan ) {
16011627
$message = sprintf(
1602-
/* translators: 1 is the promo code, 2 is the discount amount ('25 off') */
1628+
// translators: %1$s is opening span tag, %2$s is closing span tag, %3$s is the discount amount ('15% off')
16031629
__( '%1$sSwitch to a yearly plan%2$s and get an instant %3$s on your payment. Contact us to reedem your deal', 'optimole-wp' ),
16041630
'<span class=" text-promo-orange">',
16051631
'</span>',
16061632
'<span class="text-promo-orange uppercase">' . __( '15% off', 'optimole-wp' ) . '</span>'
16071633
);
1608-
$cta_link = esc_url_raw( tsdk_utmify( tsdk_translate_link( self::get_contact_base_link() ), 'bfcm25', 'notice' ) );
1634+
$cta_link = esc_url_raw( tsdk_utmify( self::get_contact_base_link(), 'bfcm25', 'notice' ) );
1635+
$cta_link = add_query_arg(
1636+
[
1637+
'contact_subject' => rawurlencode( 'Upgrade to yearly plan - Black Friday offer' ),
1638+
'contact_website' => rawurlencode( home_url() ),
1639+
],
1640+
$cta_link
1641+
);
16091642
$cta_text = __( 'Contact us', 'optimole-wp' );
16101643
}
16111644

1612-
$notices = [
1613-
'sidebar' => [
1614-
'title' => sprintf(
1615-
'<span class="text-promo-orange">%1$s:</span>',
1616-
__( 'Private Sale', 'optimole-wp' ),
1617-
),
1618-
'subtitle' => sprintf(
1619-
/* translators: 1 is the promo code, 2 is the discount amount ('25 off') */
1620-
__( 'Use code %1$s for %2$s on yearly plans.', 'optimole-wp' ),
1621-
'<span class="border-b border-0 border-white border-dashed text-promo-orange">BFCM2425</span>',
1622-
'<span class="text-promo-orange uppercase">' . __( '25% off', 'optimole-wp' ) . '</span>'
1623-
),
1624-
'cta_link' => esc_url_raw( tsdk_utmify( tsdk_translate_link( self::get_upgrade_base_link() ), 'bfcm24', 'sidebarnotice' ) ),
1625-
],
1626-
];
1627-
1628-
if ( get_option( self::BF_PROMO_DISMISS_KEY ) === 'yes' ) {
1629-
return $notices;
1630-
}
1631-
16321645
$notices['banner'] = [
16331646
/* translators: number of days left */
16341647
'urgency' => sprintf( __( 'Hurry up! only %s left', 'optimole-wp' ), human_time_diff( $end->getTimestamp(), $now->getTimestamp() ) ),

tests/test-admin.php

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -178,13 +178,16 @@ public function test_get_bf_notices_structure_for_free_plan() {
178178

179179
// Check subtitle contains discount information for free users
180180
$this->assertStringContainsString( '25', $sidebar['subtitle'] );
181-
$this->assertStringContainsString( 'BFCM2425', $sidebar['subtitle'] );
181+
$this->assertStringContainsString( 'BFCM2525', $sidebar['subtitle'] );
182+
$this->assertStringContainsString( 'Use code', $sidebar['subtitle'] );
182183

183184
// Check CTA link is not empty
184185
$this->assertNotEmpty( $sidebar['cta_link'] );
185186

186-
// Check banner CTA text
187+
// Check banner CTA text and message
187188
$this->assertNotEmpty( $banner['cta_text'] );
189+
$this->assertStringContainsString( 'Use coupon code', $banner['subtitle'] );
190+
$this->assertStringContainsString( 'BFCM2525', $banner['subtitle'] );
188191
}
189192

190193
/**
@@ -201,14 +204,15 @@ public function test_get_bf_notices_structure_for_monthly_plan() {
201204
$result = $this->admin->get_bf_notices( $plan );
202205

203206
$this->assertIsArray( $result, "Failed for plan: $plan" );
204-
$this->assertArrayHasKey( 'sidebar', $result, "Missing sidebar for plan: $plan" );
207+
// Monthly plans should NOT have sidebar, only banner
208+
$this->assertArrayNotHasKey( 'sidebar', $result, "Unexpected sidebar for monthly plan: $plan" );
205209
$this->assertArrayHasKey( 'banner', $result, "Missing banner for plan: $plan" );
206210

207211
$banner = $result['banner'];
208212

209213
// Check banner subtitle contains discount information for monthly users
210214
$this->assertStringContainsString( '15', $banner['subtitle'], "Missing 15% discount for plan: $plan" );
211-
$this->assertStringContainsString( 'yearly', $banner['subtitle'], "Missing yearly mention for plan: $plan" );
215+
$this->assertStringContainsString( 'yearly plan', $banner['subtitle'], "Missing yearly mention for plan: $plan" );
212216

213217
// Check CTA for monthly users
214218
$this->assertStringContainsString( 'Contact us', $banner['cta_text'], "Wrong CTA for plan: $plan" );
@@ -311,6 +315,24 @@ public function test_get_bf_notices_banner_has_correct_title() {
311315
$this->assertStringContainsString( 'private sale', $result['banner']['title'] );
312316
}
313317

318+
/**
319+
* Test get_bf_notices with different date scenarios.
320+
*/
321+
public function test_get_bf_notices_monthly_plan_contact_link() {
322+
$this->setup_black_friday_sale_period();
323+
$this->mock_date_to( clone $this->black_friday );
324+
325+
$result = $this->admin->get_bf_notices( 'starter' );
326+
327+
$this->assertArrayHasKey( 'banner', $result );
328+
$banner = $result['banner'];
329+
330+
// Verify monthly plan contact link includes query parameters
331+
$this->assertStringContainsString( 'contact_subject', $banner['cta_link'] );
332+
$this->assertStringContainsString( 'contact_website', $banner['cta_link'] );
333+
$this->assertStringContainsString( 'Upgrade', $banner['cta_link'] );
334+
}
335+
314336
/**
315337
* Test get_bf_notices with different date scenarios.
316338
*/

0 commit comments

Comments
 (0)