Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 89 additions & 0 deletions classes/controllers/FrmAppController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

/**
Expand All @@ -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 = '<span class="frm-orange-text">' . esc_html( $black_friday_menu_label ) . '</span>';

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;
}

Comment thread
Crabcyborg marked this conversation as resolved.
/**
* @since 3.0
*/
Expand Down Expand Up @@ -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();
}
}
4 changes: 4 additions & 0 deletions css/admin/frm_admin_global.css
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,7 @@
vertical-align: unset;
padding: 0;
}

#adminmenu .frm-orange-text {
color: #F47449;
}