diff --git a/classes/controllers/FrmAppController.php b/classes/controllers/FrmAppController.php index 4d5c5f40ac..a89109ce69 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,73 @@ 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() { + if ( ! current_user_can( 'frm_change_settings' ) ) { + return; + } + + $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' ); + $black_friday_menu_label = '' . esc_html( $black_friday_menu_label ) . ''; + + 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. + * Our sales are based on Eastern Time, so we use New York's timezone. + * + * @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; + } + /** * @since 3.0 */ @@ -1390,4 +1459,24 @@ 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] ); } + + /** + * 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( + array( + 'medium' => 'black-friday-submenu', + 'content' => self::is_cyber_monday() ? 'cyber-monday-submenu' : 'black-friday-submenu', + ), + 'black-friday' + ) + ); + die(); + } } 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