Skip to content

Commit cfe9a37

Browse files
chore: remove BF for monthly
1 parent 6642996 commit cfe9a37

2 files changed

Lines changed: 43 additions & 157 deletions

File tree

inc/admin.php

Lines changed: 17 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1556,9 +1556,8 @@ public function get_bf_notices( $user_plan ) {
15561556

15571557
$notices = [];
15581558
$has_free_plan = 'free' === $user_plan;
1559-
$has_monthly_plan = strpos( $user_plan, '-yearly' ) === false && ! $has_free_plan;
15601559

1561-
if ( ! $has_free_plan && ! $has_monthly_plan ) {
1560+
if ( ! $has_free_plan ) {
15621561
return $notices;
15631562
}
15641563

@@ -1592,23 +1591,21 @@ public function get_bf_notices( $user_plan ) {
15921591

15931592
$promo_code = 'BFCM2525';
15941593

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-
}
1594+
$notices['sidebar'] = [
1595+
'title' => sprintf(
1596+
'<span class="text-promo-orange">%1$s:</span> %2$s - %3$s',
1597+
__( 'Private Sale', 'optimole-wp' ),
1598+
wp_date( 'j M', $sale_start->getTimestamp() ),
1599+
wp_date( 'j M', $end->getTimestamp() )
1600+
),
1601+
'subtitle' => sprintf(
1602+
/* translators: %1$s is the promo code, %2$s is the discount amount ('25 off') */
1603+
__( 'Use code %1$s for an instant %2$s', 'optimole-wp' ),
1604+
'<span class="border-b border-0 border-white border-dashed text-promo-orange">' . $promo_code . '</span>',
1605+
'<span class="text-promo-orange uppercase">' . __( '25% discount', 'optimole-wp' ) . '</span>'
1606+
),
1607+
'cta_link' => esc_url_raw( tsdk_utmify( tsdk_translate_link( self::get_upgrade_base_link() ), 'bfcm25', 'sidebarnotice' ) ),
1608+
];
16121609

16131610
if ( get_option( self::BF_PROMO_DISMISS_KEY ) === 'yes' ) {
16141611
return $notices;
@@ -1618,23 +1615,11 @@ public function get_bf_notices( $user_plan ) {
16181615
// translators: $1$s is the promo code, $2$s is the discount amount ('25% off')
16191616
__( 'Use coupon code %1$s for an instant %2$s on your first billing cycle on Optimole plan.', 'optimole-wp' ),
16201617
'<span class="border-b border-0 border-white border-dashed text-promo-orange">' . $promo_code . '</span>',
1621-
'<span class="text-promo-orange uppercase">' . __( '25% off', 'optimole-wp' ) . '</span>'
1618+
'<span class="text-promo-orange uppercase">' . __( '25% discount', 'optimole-wp' ) . '</span>'
16221619
);
16231620
$cta_link = esc_url_raw( tsdk_utmify( self::get_upgrade_base_link(), 'bfcm25', 'notice' ) );
16241621
$cta_text = __( 'Claim now', 'optimole-wp' );
16251622

1626-
if ( $has_monthly_plan ) {
1627-
$message = sprintf(
1628-
// translators: %1$s is opening span tag, %2$s is closing span tag, %3$s is the discount amount ('15% off')
1629-
__( '%1$sSwitch to a yearly plan%2$s and get an instant %3$s on your payment. Contact us to redeem your deal', 'optimole-wp' ),
1630-
'<span class="text-promo-orange">',
1631-
'</span>',
1632-
'<span class="text-promo-orange uppercase">' . __( '15% off', 'optimole-wp' ) . '</span>'
1633-
);
1634-
$cta_link = $this->get_sale_url_for_monthly_plan();
1635-
$cta_text = __( 'Contact us', 'optimole-wp' );
1636-
}
1637-
16381623
$notices['banner'] = [
16391624
/* translators: number of days left */
16401625
'urgency' => sprintf( __( 'Hurry up! only %s left', 'optimole-wp' ), human_time_diff( $end->getTimestamp(), $now->getTimestamp() ) ),
@@ -1649,27 +1634,6 @@ public function get_bf_notices( $user_plan ) {
16491634
return $notices;
16501635
}
16511636

1652-
/**
1653-
* Get the sale url for yearly plan.
1654-
*
1655-
* @return string
1656-
*/
1657-
private function get_sale_url_for_monthly_plan() {
1658-
$sale_url = esc_url_raw( tsdk_utmify( self::get_contact_base_link(), 'bfcm25', 'global_notice' ) );
1659-
$sale_url = add_query_arg(
1660-
[
1661-
'contact_subject' => rawurlencode( 'Upgrade to yearly plan - Black Friday offer' ),
1662-
'contact_website' => rawurlencode( home_url() ),
1663-
'contact_description' => rawurlencode(
1664-
'Hi, I saw the Black Friday offer about getting 15% OFF when switching from a monthly to a yearly plan. I would like to redeem this deal. Could you please help to switch my plan?'
1665-
),
1666-
],
1667-
$sale_url
1668-
);
1669-
1670-
return $sale_url;
1671-
}
1672-
16731637
/**
16741638
* Get all dashboard strings.
16751639
*

tests/test-admin.php

Lines changed: 26 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -113,38 +113,23 @@ public function test_get_bf_notices_returns_empty_when_not_black_friday() {
113113
$this->assertEmpty( $result );
114114
}
115115

116-
/**
117-
* Test get_bf_notices returns empty array for yearly plans.
118-
*/
119-
public function test_get_bf_notices_returns_empty_for_yearly_plans() {
120-
// Mock Black Friday status as true
121-
add_filter( 'themeisle_sdk_is_black_friday_sale', '__return_true' );
122-
123-
// Test various yearly plans
124-
$yearly_plans = [ 'starter-yearly', 'growth-yearly', 'business-yearly', 'agency-yearly' ];
125-
126-
foreach ( $yearly_plans as $plan ) {
127-
$result = $this->admin->get_bf_notices( $plan );
128-
$this->assertIsArray( $result, "Failed for plan: $plan" );
129-
$this->assertEmpty( $result, "Expected empty array for yearly plan: $plan" );
130-
}
131-
}
116+
132117

133118
/**
134-
* Test get_bf_notices returns empty array for empty or invalid plans.
119+
* Test get_bf_notices returns empty array for non-free plans.
135120
*/
136-
public function test_get_bf_notices_returns_empty_for_invalid_plans() {
121+
public function test_get_bf_notices_returns_empty_for_non_free_plans() {
137122
$this->setup_black_friday_sale_period();
138123
$this->mock_date_to( clone $this->black_friday );
139124

140-
// Test invalid plan (yearly suffix makes it invalid for BF notices)
141-
$result = $this->admin->get_bf_notices( 'invalid-plan-yearly' );
142-
$this->assertIsArray( $result );
143-
$this->assertEmpty( $result );
125+
// Test various non-free plans - all should return empty
126+
$non_free_plans = [ 'starter', 'growth', 'business', 'agency', 'starter-yearly', 'invalid-plan' ];
144127

145-
// Verify the plan is actually being evaluated, not just returning empty by default
146-
$result_valid = $this->admin->get_bf_notices( 'starter' );
147-
$this->assertNotEmpty( $result_valid, 'Valid plan should return notices' );
128+
foreach ( $non_free_plans as $plan ) {
129+
$result = $this->admin->get_bf_notices( $plan );
130+
$this->assertIsArray( $result, "Failed for plan: $plan" );
131+
$this->assertEmpty( $result, "Expected empty array for non-free plan: $plan" );
132+
}
148133
}
149134

150135
/**
@@ -188,69 +173,28 @@ public function test_get_bf_notices_structure_for_free_plan() {
188173
$this->assertNotEmpty( $banner['cta_text'] );
189174
$this->assertStringContainsString( 'Use coupon code', $banner['subtitle'] );
190175
$this->assertStringContainsString( 'BFCM2525', $banner['subtitle'] );
176+
$this->assertStringContainsString( '25', $banner['subtitle'] );
191177
}
192178

193-
/**
194-
* Test get_bf_notices returns correct structure for monthly plan during Black Friday.
195-
*/
196-
public function test_get_bf_notices_structure_for_monthly_plan() {
197-
$this->setup_black_friday_sale_period();
198-
$this->mock_date_to( clone $this->black_friday );
199-
200-
// Test various monthly plans
201-
$monthly_plans = [ 'starter', 'growth', 'business', 'agency' ];
202-
203-
foreach ( $monthly_plans as $plan ) {
204-
$result = $this->admin->get_bf_notices( $plan );
205-
206-
$this->assertIsArray( $result, "Failed for plan: $plan" );
207-
// Monthly plans should NOT have sidebar, only banner
208-
$this->assertArrayNotHasKey( 'sidebar', $result, "Unexpected sidebar for monthly plan: $plan" );
209-
$this->assertArrayHasKey( 'banner', $result, "Missing banner for plan: $plan" );
210-
211-
$banner = $result['banner'];
212-
213-
// Check banner subtitle contains discount information for monthly users
214-
$this->assertStringContainsString( '15', $banner['subtitle'], "Missing 15% discount for plan: $plan" );
215-
$this->assertStringContainsString( 'yearly plan', $banner['subtitle'], "Missing yearly mention for plan: $plan" );
216-
217-
// Check CTA for monthly users
218-
$this->assertStringContainsString( 'Contact us', $banner['cta_text'], "Wrong CTA for plan: $plan" );
219-
$this->assertNotEmpty( $banner['cta_link'], "Empty link for plan: $plan" );
220-
}
221-
}
179+
222180

223181
/**
224-
* Test get_bf_notices banner is hidden when dismissed.
182+
* Test get_bf_notices banner visibility based on dismissal status.
225183
*/
226-
public function test_get_bf_notices_banner_hidden_when_dismissed() {
184+
public function test_get_bf_notices_banner_dismissal() {
227185
$this->setup_black_friday_sale_period();
228186
$this->mock_date_to( clone $this->black_friday );
229187

230-
// Set dismissal option
188+
// Test banner is hidden when dismissed
231189
update_option( Optml_Admin::BF_PROMO_DISMISS_KEY, 'yes' );
232-
233190
$result = $this->admin->get_bf_notices( 'free' );
234-
235-
// Should only have sidebar, not banner
236191
$this->assertIsArray( $result );
237192
$this->assertArrayHasKey( 'sidebar', $result );
238193
$this->assertArrayNotHasKey( 'banner', $result );
239-
}
240-
241-
/**
242-
* Test get_bf_notices banner appears when not dismissed.
243-
*/
244-
public function test_get_bf_notices_banner_appears_when_not_dismissed() {
245-
$this->setup_black_friday_sale_period();
246-
$this->mock_date_to( clone $this->black_friday );
247194

248-
// Ensure option is not set
195+
// Test banner appears when not dismissed
249196
delete_option( Optml_Admin::BF_PROMO_DISMISS_KEY );
250-
251197
$result = $this->admin->get_bf_notices( 'free' );
252-
253-
// Should have both sidebar and banner
254198
$this->assertIsArray( $result );
255199
$this->assertArrayHasKey( 'sidebar', $result );
256200
$this->assertArrayHasKey( 'banner', $result );
@@ -315,23 +259,7 @@ public function test_get_bf_notices_banner_has_correct_title() {
315259
$this->assertStringContainsString( 'private sale', $result['banner']['title'] );
316260
}
317261

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-
}
262+
335263

336264
/**
337265
* Test get_bf_notices with different date scenarios.
@@ -367,26 +295,20 @@ public function test_get_bf_notices_date_scenarios() {
367295
}
368296

369297
/**
370-
* Test get_bf_notices with non-'yes' dismissal values.
298+
* Test get_bf_notices banner appears with non-'yes' dismissal values.
371299
*/
372-
public function test_get_bf_notices_banner_appears_with_non_yes_dismissal() {
300+
public function test_get_bf_notices_banner_dismissal_values() {
373301
$this->setup_black_friday_sale_period();
374302
$this->mock_date_to( clone $this->black_friday );
375303

376-
// Test with 'no' value
377-
update_option( Optml_Admin::BF_PROMO_DISMISS_KEY, 'no' );
378-
$result = $this->admin->get_bf_notices( 'free' );
379-
$this->assertArrayHasKey( 'banner', $result, "Banner should appear when dismiss key is 'no'" );
380-
381-
// Test with '0' value
382-
update_option( Optml_Admin::BF_PROMO_DISMISS_KEY, '0' );
383-
$result = $this->admin->get_bf_notices( 'free' );
384-
$this->assertArrayHasKey( 'banner', $result, "Banner should appear when dismiss key is '0'" );
304+
// Banner only hides when dismissal key is exactly 'yes'
305+
$test_values = [ 'no', '0', '', 'dismissed' ];
385306

386-
// Test with empty string
387-
update_option( Optml_Admin::BF_PROMO_DISMISS_KEY, '' );
388-
$result = $this->admin->get_bf_notices( 'free' );
389-
$this->assertArrayHasKey( 'banner', $result, "Banner should appear when dismiss key is empty string" );
307+
foreach ( $test_values as $value ) {
308+
update_option( Optml_Admin::BF_PROMO_DISMISS_KEY, $value );
309+
$result = $this->admin->get_bf_notices( 'free' );
310+
$this->assertArrayHasKey( 'banner', $result, "Banner should appear when dismiss key is '$value'" );
311+
}
390312
}
391313

392314
/**

0 commit comments

Comments
 (0)