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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ js/*.js.LICENSE.txt

# Ignore map files
**/*.css.map
**/*.js.map

# Node
node_modules
Expand Down
2 changes: 2 additions & 0 deletions classes/controllers/FrmHooksController.php
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,8 @@ public static function load_ajax_hooks() {
add_action( 'wp_ajax_frm_dismiss_review', 'FrmAppController::dismiss_review' );

add_action( 'wp_ajax_frm_small_screen_proceed', 'FrmAppController::small_screen_proceed' );

add_action( 'wp_ajax_frm_sale_banner_dismiss', 'FrmSalesApi::dismiss_banner' );
}

/**
Expand Down
2 changes: 1 addition & 1 deletion classes/helpers/FrmAppHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -1417,7 +1417,7 @@ public static function print_admin_banner( $should_show_lite_upgrade ) {
return;
}

if ( self::maybe_show_license_warning() || FrmInbox::maybe_show_banner() || ! $should_show_lite_upgrade || self::pro_is_installed() ) {
if ( FrmSalesApi::maybe_show_banner() || self::maybe_show_license_warning() || FrmInbox::maybe_show_banner() || ! $should_show_lite_upgrade || self::pro_is_installed() ) {
// Print license warning or inbox banner and exit if either prints.
// And exit before printing the upgrade bar if it shouldn't be shown.
return;
Expand Down
153 changes: 153 additions & 0 deletions classes/models/FrmSalesApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,15 @@ private function fill_sale( $sale ) {
'global_settings_upgrade_cta_link' => '',
'builder_sidebar_cta_link' => '',
'builder_sidebar_cta_text' => '',
'banner_title' => '',
'banner_body' => '',
'banner_icon' => '',
'banner_text_color' => '',
'banner_bg_color' => '',
'banner_cta_link' => '',
'banner_cta_text' => '',
'banner_cta_text_color' => '',
'banner_cta_bg_color' => '',
);

return array_merge( $defaults, $sale );
Expand Down Expand Up @@ -226,4 +235,148 @@ private function get_ab_group_for_current_site() {
}
return (int) $option;
}

/**
* Maybe show banner for the best sale.
*
* @since x.x
*
* @return bool
*/
public static function maybe_show_banner() {
if ( ! isset( self::$instance ) ) {
self::$instance = new FrmSalesApi();
}

$sale = self::$instance->get_best_sale();
if ( ! $sale || ! is_array( $sale ) ) {
return false;
}

$banner_title = ! empty( $sale['banner_title'] ) ? $sale['banner_title'] : false;
$banner_body = ! empty( $sale['banner_body'] ) ? $sale['banner_body'] : false;

if ( false === $banner_title || false === $banner_body ) {
return false;
}

if ( self::is_banner_dismissed( $sale['key'] ) ) {
return false;
}

$banner_icon = ! empty( $sale['banner_icon'] ) ? $sale['banner_icon'] : 'generic';
$banner_bg_color = ! empty( $sale['banner_bg_color'] ) ? $sale['banner_bg_color'] : false;
$banner_text_color = ! empty( $sale['banner_text_color'] ) ? $sale['banner_text_color'] : false;
$banner_cta_link = ! empty( $sale['banner_cta_link'] ) ? $sale['banner_cta_link'] : false;

// translators: %s is the discount percentage.
$banner_cta_text = ! empty( $sale['banner_cta_text'] ) ? $sale['banner_cta_text'] : sprintf( __( 'GET %s OFF NOW', 'formidable' ), $sale['discount_percent'] . '%' );
$banner_cta_text_color = ! empty( $sale['banner_cta_text_color'] ) ? $sale['banner_cta_text_color'] : false;
$banner_cta_bg_color = ! empty( $sale['banner_cta_bg_color'] ) ? $sale['banner_cta_bg_color'] : false;

if ( false === $banner_cta_link ) {
$banner_cta_link = FrmAppHelper::admin_upgrade_link(
array(
'medium' => 'sales-api-banner',
'content' => $sale['key'],
)
);
}

$banner_attrs = array(
'id' => 'frm_sale_banner',
'data-url' => $banner_cta_link,
);

if ( false === $banner_bg_color || 'gradient' === $banner_bg_color ) {
$banner_attrs['class'] = 'frm-gradient';
} else {
$banner_attrs['style'] = 'background-color: ' . esc_attr( $banner_bg_color ) . ';';
}

$cta_attrs = array(
'href' => '#',
'style' => '',
);
if ( false !== $banner_cta_text_color ) {
$cta_attrs['style'] .= 'color: ' . esc_attr( $banner_cta_text_color ) . ';';
}
if ( false !== $banner_cta_bg_color ) {
$cta_attrs['style'] .= 'background-color: ' . esc_attr( $banner_cta_bg_color ) . ';';
}

$dismiss_attrs = array(
'href' => '#',
'class' => 'dismiss',
);

$content_attrs = array();

if ( false !== $banner_text_color ) {
$content_attrs['style'] = 'color: ' . esc_attr( $banner_text_color ) . ';';
$dismiss_attrs['style'] = 'color: ' . esc_attr( $banner_text_color ) . ';';
}

?>
<div <?php FrmAppHelper::array_to_html_params( $banner_attrs, true ); ?>>
<div>
<img src="<?php echo esc_url( FrmAppHelper::plugin_url() . '/images/sales/' . $banner_icon . '.svg' ); ?>" alt="<?php echo esc_attr( $banner_title ); ?>" />
</div>
<div <?php FrmAppHelper::array_to_html_params( $content_attrs, true ); ?>>
<div>
<?php echo esc_html( $banner_title ); ?>
</div>
<div>
<?php echo esc_html( $banner_body ); ?>
</div>
</div>
<div>
<a <?php FrmAppHelper::array_to_html_params( $cta_attrs, true ); ?>>
<?php echo esc_html( $banner_cta_text ); ?>
</a>
</div>
<a <?php FrmAppHelper::array_to_html_params( $dismiss_attrs, true ); ?>><?php FrmAppHelper::icon_by_class( 'frm_icon_font frm_close_icon' ); ?></a>
</div>
<?php

return true;
}
Comment thread
Crabcyborg marked this conversation as resolved.

/**
* Dismiss a banner via AJAX hook.
*
* @since x.x
*/
public static function dismiss_banner() {
FrmAppHelper::permission_check( 'frm_view_forms' );
check_ajax_referer( 'frm_ajax', 'nonce' );

if ( ! isset( self::$instance ) ) {
self::$instance = new FrmSalesApi();
}

$sale = self::$instance->get_best_sale();
if ( ! $sale || ! is_array( $sale ) ) {
wp_send_json_error();
}

$dismissed_sales = get_user_option( 'frm_dismissed_sales', get_current_user_id() );
if ( ! is_array( $dismissed_sales ) ) {
$dismissed_sales = array();
}

$dismissed_sales[] = $sale['key'];
update_user_option( get_current_user_id(), 'frm_dismissed_sales', $dismissed_sales );

wp_send_json_success();
}

/**
* @param string $key
* @return bool
*/
private static function is_banner_dismissed( $key ) {
$dismissed_sales = get_user_option( 'frm_dismissed_sales', get_current_user_id() );
return is_array( $dismissed_sales ) && in_array( $key, $dismissed_sales, true );
}
}
2 changes: 1 addition & 1 deletion css/frm_admin.css

Large diffs are not rendered by default.

61 changes: 61 additions & 0 deletions images/sales/anniversary.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions images/sales/back-to-school.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions images/sales/black-friday.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions images/sales/fall.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions images/sales/geek-week.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading