From 5f0a607d815e7f91fced80b6a097219ac0cfb8bf Mon Sep 17 00:00:00 2001 From: Mike Letellier Date: Wed, 2 Oct 2024 11:05:27 -0300 Subject: [PATCH 01/10] Pro issue 5404 / Black friday --- classes/controllers/FrmAppController.php | 65 ++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/classes/controllers/FrmAppController.php b/classes/controllers/FrmAppController.php index 4d5c5f40ac..de98d5b8d9 100644 --- a/classes/controllers/FrmAppController.php +++ b/classes/controllers/FrmAppController.php @@ -16,6 +16,8 @@ public static function menu() { $menu_name = FrmAppHelper::get_menu_name(); add_menu_page( 'Formidable', $menu_name, 'frm_view_forms', 'formidable', 'FrmFormsController::route', self::menu_icon(), self::get_menu_position() ); + + self::maybe_add_black_friday_submenu_item(); } /** @@ -40,6 +42,65 @@ private static function menu_icon() { return apply_filters( 'frm_icon', $icon ); } + /** + * @since x.x + * + * @return void + */ + private static function maybe_add_black_friday_submenu_item() { + $is_black_friday = self::is_black_friday(); + $is_cyber_monday = self::is_cyber_monday(); + + if ( ! $is_black_friday && ! $is_cyber_monday ) { + return; + } + + $black_friday_menu_label = $is_black_friday ? __( 'Black Friday!', 'formidable' ) : __( 'Cyber Monday!', 'formidable' ); + + add_action( + 'admin_menu', + function () use ( $black_friday_menu_label ) { + add_submenu_page( 'formidable', 'Formidable', $black_friday_menu_label, 'frm_change_settings', 'formidable-black-friday', 'FrmAppController::redirect_blackfriday' ); + }, + 1000 + ); + } + + /** + * Black Friday sale is from November 25 to 29. + * + * @since x.x + * + * @return bool + */ + private static function is_black_friday() { + return self::within_sale_date_range( '2024-11-25', '2024-11-29' ); + } + + /** + * Cyber Monday sale rules from November 30 to December 4. + * + * @since x.x + * + * @return bool + */ + private static function is_cyber_monday() { + return self::within_sale_date_range( '2024-11-30', '2024-12-04' ); + } + + /** + * Check if the current time is within a sale date range. + * + * @since x.x + * + * @return bool + */ + private static function within_sale_date_range( $from, $to ) { + // TODO This should not be in GMT but in a specific timezone. Is it EST, MST? + $today = gmdate( 'Y-m-d' ); + return $today >= $from && $today <= $to; + } + /** * @since 3.0 */ @@ -1390,4 +1451,8 @@ private static function is_our_callback_array( $callback ) { ! empty( $callback['function'][0] ) && self::is_our_callback_string( is_object( $callback['function'][0] ) ? get_class( $callback['function'][0] ) : $callback['function'][0] ); } + + public static function redirect_blackfriday() { + wp_redirect( 'https://formidableforms.com/black-friday' ); + } } From 076c5c8c5016a294f51d555c05f8b54de4edfbf7 Mon Sep 17 00:00:00 2001 From: Mike Letellier Date: Wed, 2 Oct 2024 11:12:53 -0300 Subject: [PATCH 02/10] Add utm parameters to the black friday URL --- classes/controllers/FrmAppController.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/classes/controllers/FrmAppController.php b/classes/controllers/FrmAppController.php index de98d5b8d9..1073dbd7a5 100644 --- a/classes/controllers/FrmAppController.php +++ b/classes/controllers/FrmAppController.php @@ -1453,6 +1453,16 @@ private static function is_our_callback_array( $callback ) { } public static function redirect_blackfriday() { - wp_redirect( 'https://formidableforms.com/black-friday' ); + wp_redirect( + add_query_arg( + array( + 'utm_source' => 'WordPress', + 'utm_medium' => 'black-friday', + 'utm_campaign' => 'liteplugin', + 'utm_content' => 'black-friday-submenu', + ), + 'https://formidableforms.com/black-friday' + ) + ); } } From d4a747fa454a2803a948f42ada06567f805d6375 Mon Sep 17 00:00:00 2001 From: Mike Letellier Date: Wed, 2 Oct 2024 11:18:31 -0300 Subject: [PATCH 03/10] Use FrmAppHelper::admin_upgrade_link for consistency --- classes/controllers/FrmAppController.php | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/classes/controllers/FrmAppController.php b/classes/controllers/FrmAppController.php index 1073dbd7a5..c3412092bb 100644 --- a/classes/controllers/FrmAppController.php +++ b/classes/controllers/FrmAppController.php @@ -1454,14 +1454,12 @@ private static function is_our_callback_array( $callback ) { public static function redirect_blackfriday() { wp_redirect( - add_query_arg( + FrmAppHelper::admin_upgrade_link( array( - 'utm_source' => 'WordPress', - 'utm_medium' => 'black-friday', - 'utm_campaign' => 'liteplugin', - 'utm_content' => 'black-friday-submenu', + 'medium' => 'black-friday', + 'content' => 'black-friday-submenu', ), - 'https://formidableforms.com/black-friday' + 'black-friday' ) ); } From 79ec73268d21b916775457ddab769bcbb1df973c Mon Sep 17 00:00:00 2001 From: Mike Letellier Date: Wed, 2 Oct 2024 11:19:47 -0300 Subject: [PATCH 04/10] Add comments --- classes/controllers/FrmAppController.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/classes/controllers/FrmAppController.php b/classes/controllers/FrmAppController.php index c3412092bb..158d51002f 100644 --- a/classes/controllers/FrmAppController.php +++ b/classes/controllers/FrmAppController.php @@ -1452,6 +1452,13 @@ private static function is_our_callback_array( $callback ) { self::is_our_callback_string( is_object( $callback['function'][0] ) ? get_class( $callback['function'][0] ) : $callback['function'][0] ); } + /** + * Redirect to Black Friday sales page when the menu item is clicked. + * + * @since x.x + * + * @return void + */ public static function redirect_blackfriday() { wp_redirect( FrmAppHelper::admin_upgrade_link( From cb46fa02bade23e059c47b6e44f83f1533c5497d Mon Sep 17 00:00:00 2001 From: Mike Letellier Date: Thu, 3 Oct 2024 14:07:14 -0300 Subject: [PATCH 05/10] Use EST --- classes/controllers/FrmAppController.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/classes/controllers/FrmAppController.php b/classes/controllers/FrmAppController.php index 158d51002f..c64362dac4 100644 --- a/classes/controllers/FrmAppController.php +++ b/classes/controllers/FrmAppController.php @@ -90,14 +90,16 @@ private static function is_cyber_monday() { /** * Check if the current time is within a sale date range. + * Our sales are based on Eastern Time, so we use New York's timezone. * * @since x.x * * @return bool */ private static function within_sale_date_range( $from, $to ) { - // TODO This should not be in GMT but in a specific timezone. Is it EST, MST? - $today = gmdate( 'Y-m-d' ); + $date = new DateTime( 'now', new DateTimeZone( 'America/New_York' ) ); + $today = $date->format( 'Y-m-d' ); + return $today >= $from && $today <= $to; } From 16135d9cfe753097bf7967b79b7a59b8ef103aa6 Mon Sep 17 00:00:00 2001 From: Mike Letellier Date: Thu, 3 Oct 2024 14:08:43 -0300 Subject: [PATCH 06/10] Add more param comments --- classes/controllers/FrmAppController.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/classes/controllers/FrmAppController.php b/classes/controllers/FrmAppController.php index c64362dac4..f2a1717119 100644 --- a/classes/controllers/FrmAppController.php +++ b/classes/controllers/FrmAppController.php @@ -94,12 +94,13 @@ private static function is_cyber_monday() { * * @since x.x * + * @param string $from The beginning of the date range. Y-m-d format is expected. + * @param string $to The end of the date range. Y-m-d format is expected. * @return bool */ private static function within_sale_date_range( $from, $to ) { $date = new DateTime( 'now', new DateTimeZone( 'America/New_York' ) ); $today = $date->format( 'Y-m-d' ); - return $today >= $from && $today <= $to; } From f6dde4052c0059289726b839e9d988bcab386bb3 Mon Sep 17 00:00:00 2001 From: Mike Letellier Date: Thu, 3 Oct 2024 14:15:45 -0300 Subject: [PATCH 07/10] Make the text orange, update the UTM so it is different for cyber monday --- classes/controllers/FrmAppController.php | 5 +++-- css/admin/frm_admin_global.css | 4 ++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/classes/controllers/FrmAppController.php b/classes/controllers/FrmAppController.php index f2a1717119..6c13bbf6b0 100644 --- a/classes/controllers/FrmAppController.php +++ b/classes/controllers/FrmAppController.php @@ -56,6 +56,7 @@ private static function maybe_add_black_friday_submenu_item() { } $black_friday_menu_label = $is_black_friday ? __( 'Black Friday!', 'formidable' ) : __( 'Cyber Monday!', 'formidable' ); + $black_friday_menu_label = '' . esc_html( $black_friday_menu_label ) . ''; add_action( 'admin_menu', @@ -1466,8 +1467,8 @@ public static function redirect_blackfriday() { wp_redirect( FrmAppHelper::admin_upgrade_link( array( - 'medium' => 'black-friday', - 'content' => 'black-friday-submenu', + 'medium' => 'black-friday-submenu', + 'content' => self::is_cyber_monday() ? 'cyber-monday' : 'black-friday', ), 'black-friday' ) diff --git a/css/admin/frm_admin_global.css b/css/admin/frm_admin_global.css index c894c9f4b1..b0377e898b 100644 --- a/css/admin/frm_admin_global.css +++ b/css/admin/frm_admin_global.css @@ -17,3 +17,7 @@ vertical-align: unset; padding: 0; } + +#adminmenu .frm-orange-text { + color: #F47449; +} \ No newline at end of file From 9b248e54f0f355b524f0cde31e5ffc478736ecfd Mon Sep 17 00:00:00 2001 From: Mike Letellier Date: Thu, 3 Oct 2024 14:18:14 -0300 Subject: [PATCH 08/10] Exit after black friday redirect --- classes/controllers/FrmAppController.php | 1 + 1 file changed, 1 insertion(+) diff --git a/classes/controllers/FrmAppController.php b/classes/controllers/FrmAppController.php index 6c13bbf6b0..9a3dd614ca 100644 --- a/classes/controllers/FrmAppController.php +++ b/classes/controllers/FrmAppController.php @@ -1473,5 +1473,6 @@ public static function redirect_blackfriday() { 'black-friday' ) ); + exit; } } From 2e426a07316564ed3da15e48c6df400d9be9208e Mon Sep 17 00:00:00 2001 From: Mike Letellier Date: Thu, 3 Oct 2024 14:18:39 -0300 Subject: [PATCH 09/10] Die instead to be consistent --- classes/controllers/FrmAppController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/classes/controllers/FrmAppController.php b/classes/controllers/FrmAppController.php index 9a3dd614ca..a8a1184a9e 100644 --- a/classes/controllers/FrmAppController.php +++ b/classes/controllers/FrmAppController.php @@ -1473,6 +1473,6 @@ public static function redirect_blackfriday() { 'black-friday' ) ); - exit; + die(); } } From 45af60d35a4d6c00a4add3af3f7cd76940bfa739 Mon Sep 17 00:00:00 2001 From: Mike Letellier Date: Thu, 3 Oct 2024 14:31:22 -0300 Subject: [PATCH 10/10] Add a permission check earlier before checking date ranges, add -submenu to the utm content to be specific --- classes/controllers/FrmAppController.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/classes/controllers/FrmAppController.php b/classes/controllers/FrmAppController.php index a8a1184a9e..a89109ce69 100644 --- a/classes/controllers/FrmAppController.php +++ b/classes/controllers/FrmAppController.php @@ -48,6 +48,10 @@ private static function menu_icon() { * @return void */ private static function maybe_add_black_friday_submenu_item() { + if ( ! current_user_can( 'frm_change_settings' ) ) { + return; + } + $is_black_friday = self::is_black_friday(); $is_cyber_monday = self::is_cyber_monday(); @@ -1468,7 +1472,7 @@ public static function redirect_blackfriday() { FrmAppHelper::admin_upgrade_link( array( 'medium' => 'black-friday-submenu', - 'content' => self::is_cyber_monday() ? 'cyber-monday' : 'black-friday', + 'content' => self::is_cyber_monday() ? 'cyber-monday-submenu' : 'black-friday-submenu', ), 'black-friday' )