Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
bf19f2e
New sales API (first commit_
Crabcyborg Jan 7, 2025
295abc4
Add a new helper function to reduce code
Crabcyborg Jan 7, 2025
60996bf
Add a new helper function to reduce code
Crabcyborg Jan 7, 2025
0f2fd41
Optimize, update function
Crabcyborg Jan 7, 2025
faebd90
Add footer CTA to API
Crabcyborg Jan 7, 2025
aa766ed
Replace the menu link/text
Crabcyborg Jan 7, 2025
3bde007
Also update the dashboard license box
Crabcyborg Jan 7, 2025
5985f4b
Update strings in the license box
Crabcyborg Jan 7, 2025
07efda9
Update another URL
Crabcyborg Jan 7, 2025
8b965d3
Use best discount if higher than 50
Crabcyborg Jan 7, 2025
ce22f7f
Change case
Crabcyborg Jan 7, 2025
f91a23a
Check for A/B test groups
Crabcyborg Jan 7, 2025
218d8e5
Remove die copde
Crabcyborg Jan 7, 2025
0eff751
Run php cs fixer
Crabcyborg Jan 7, 2025
e000ed9
phpcs fixes
Crabcyborg Jan 7, 2025
28f684f
Check starts timestamp as well and compare against New York time
Crabcyborg Jan 7, 2025
93914e1
Remove more code that is not required
Crabcyborg Jan 7, 2025
14c163b
Do not autoload the option
Crabcyborg Jan 7, 2025
212146e
Re-use code in inbox code
Crabcyborg Jan 7, 2025
4111ec1
phpcs fixes
Crabcyborg Jan 7, 2025
05b3cb3
Add line break
Crabcyborg Jan 7, 2025
a127f8c
Fix broken php
Crabcyborg Jan 7, 2025
0c9821e
Add a comment
Crabcyborg Jan 7, 2025
50eb65b
Add missing var
Crabcyborg Jan 8, 2025
8ab852a
Remove unused $for_parent constructor param
Crabcyborg Jan 10, 2025
d22d88e
Remove phpstan exception
Crabcyborg Jan 10, 2025
9bb7318
Merge branch 'lite-to-pro-improvement' into new_sales_api
Crabcyborg Jan 10, 2025
8df2e3e
Merge branch 'master' into new_sales_api
Crabcyborg Jan 13, 2025
1fac935
Clear sales API when clearing caches, stop using hard coded test data
Crabcyborg Jan 13, 2025
41da4cd
Merge branch 'master' into new_sales_api
Crabcyborg Jan 13, 2025
616826c
Add a check for Psalm
Crabcyborg Jan 13, 2025
8bb347a
Update sales API URL (use cloudflare worker)
Crabcyborg Jan 13, 2025
fd6524c
Add day in seconds to expires check to include the expires date
Crabcyborg Jan 13, 2025
8c3a688
Also update the link in the plugins page
Crabcyborg Jan 14, 2025
4c0189e
Merge branch 'master' into new_sales_api
Crabcyborg Jan 14, 2025
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
11 changes: 8 additions & 3 deletions classes/controllers/FrmAddonsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,18 +97,23 @@ public static function menu() {
}

$label = __( 'Add-Ons', 'formidable' );
$label = '<span style="color:#3FCA89">' . $label . '</span>';
$label = '<span style="color:#3FCA89">' . esc_html( $label ) . '</span>';

add_submenu_page( 'formidable', 'Formidable | ' . __( 'Add-Ons', 'formidable' ), $label, 'frm_view_forms', 'formidable-addons', 'FrmAddonsController::list_addons' );

// remove default created subpage, make the page with highest priority as default.
remove_submenu_page( 'formidable', 'formidable' );

if ( ! FrmAppHelper::pro_is_installed() ) {
$cta_text = FrmSalesApi::get_best_sale_value( 'menu_cta_text' );
if ( ! $cta_text ) {
$cta_text = __( 'Upgrade', 'formidable' );
}

add_submenu_page(
'formidable',
'Formidable | ' . __( 'Upgrade', 'formidable' ),
'<span class="frm-upgrade-submenu">' . __( 'Upgrade', 'formidable' ) . '</span>',
'<span class="frm-upgrade-submenu">' . esc_html( $cta_text ) . '</span>',
'frm_view_forms',
'formidable-pro-upgrade',
function () {
Expand All @@ -119,7 +124,7 @@ function () {
} elseif ( 'formidable-pro-upgrade' === FrmAppHelper::get_param( 'page' ) ) {
wp_safe_redirect( admin_url( 'admin.php?page=formidable' ) );
exit;
}
}//end if
}

/**
Expand Down
32 changes: 25 additions & 7 deletions classes/controllers/FrmAppController.php
Original file line number Diff line number Diff line change
Expand Up @@ -337,16 +337,31 @@ private static function get_form_nav_items( $form ) {
return (array) apply_filters( 'frm_form_nav_list', $nav_items, $nav_args );
}

// Adds a settings link to the plugins page
/**
* Adds a settings link to the plugins page
*
* @param array $links
* @return array
*/
public static function settings_link( $links ) {
$settings = array();

if ( ! FrmAppHelper::pro_is_installed() ) {
$label = FrmAddonsController::is_license_expired() ? __( 'Renew', 'formidable' ) : __( 'Upgrade to Pro', 'formidable' );
$settings[] = '<a href="' . esc_url( FrmAppHelper::admin_upgrade_link( 'plugin-row' ) ) . '" target="_blank" rel="noopener"><b style="color:#1da867;font-weight:700;">' . esc_html( $label ) . '</b></a>';
if ( FrmAddonsController::is_license_expired() ) {
$label = __( 'Renew', 'formidable' );
} else {
$label = FrmSalesApi::get_best_sale_value( 'plugin_page_cta_text' );
if ( ! $label ) {
$label = __( 'Upgrade to Pro', 'formidable' );
}
}

$upgrade_link = FrmSalesApi::get_best_sale_value( 'plugin_page_cta_link' );
if ( ! $upgrade_link ) {
$upgrade_link = FrmAppHelper::admin_upgrade_link( 'plugin-row' );
}

$settings[] = '<a href="' . esc_url( $upgrade_link ) . '" target="_blank" rel="noopener"><b style="color:#1da867;font-weight:700;">' . esc_html( $label ) . '</b></a>';
}

$settings[] = '<a href="' . esc_url( admin_url( 'admin.php?page=formidable' ) ) . '">' . __( 'Build a Form', 'formidable' ) . '</a>';
Expand Down Expand Up @@ -557,14 +572,17 @@ public static function admin_init() {
}

if ( 'formidable-pro-upgrade' === FrmAppHelper::get_param( 'page' ) && ! FrmAppHelper::pro_is_installed() && current_user_can( 'frm_view_forms' ) ) {
wp_redirect(
FrmAppHelper::admin_upgrade_link(
$redirect = FrmSalesApi::get_best_sale_value( 'menu_cta_link' );
if ( ! $redirect ) {
$redirct = FrmAppHelper::admin_upgrade_link(
array(
'medium' => 'upgrade',
'content' => 'submenu-upgrade',
)
)
);
);
}

wp_redirect( $redirect );
Comment thread
Crabcyborg marked this conversation as resolved.
die();
}

Expand Down
119 changes: 119 additions & 0 deletions classes/helpers/FrmApiHelper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
die( 'You are not allowed to call this page directly.' );
}

/**
* @since x.x
*/
class FrmApiHelper {

/**
* Check if an API item matches the current site license target.
*
* @since x.x
*
* @param array $item Inbox or Sale item.
* @return bool
*/
public static function is_for_user( $item ) {
if ( ! isset( $item['who'] ) || $item['who'] === 'all' ) {
return true;
}
$who = (array) $item['who'];
if ( self::is_for_everyone( $who ) ) {
return true;
}
if ( self::is_user_type( $who ) ) {
return true;
}
if ( in_array( 'free_first_30', $who, true ) && self::is_free_first_30() ) {
return true;
}
if ( in_array( 'free_not_first_30', $who, true ) && self::is_free_not_first_30() ) {
return true;
}
return false;
}
Comment thread
Crabcyborg marked this conversation as resolved.

/**
* @since x.x
*
* @param array $who
* @return bool
*/
private static function is_for_everyone( $who ) {
return in_array( 'all', $who, true );
}

/**
* @since x.x
*
* @param array $who
* @return bool
*/
private static function is_user_type( $who ) {
return in_array( self::get_user_type(), $who, true );
}

/**
* @since x.x
*
* @return string
*/
private static function get_user_type() {
if ( ! FrmAppHelper::pro_is_installed() ) {
return 'free';
}

return FrmAddonsController::license_type();
}

/**
* Check if user is still using the Lite version only, and within
* the first 30 days of activation.
*
* @since x.x
*
* @return bool
*/
private static function is_free_first_30() {
return self::is_free() && self::is_first_30();
}

/**
* @since x.x
*
* @return bool
*/
private static function is_first_30() {
$activation_timestamp = get_option( 'frm_first_activation' );
if ( false === $activation_timestamp ) {
// If the option does not exist, assume that it is
// because the user was active before this option was introduced.
return false;
}
Comment thread
Crabcyborg marked this conversation as resolved.
$cutoff = strtotime( '-30 days' );
return $activation_timestamp > $cutoff;
}

/**
* @since x.x
*
* @return bool
*/
private static function is_free_not_first_30() {
return self::is_free() && ! self::is_first_30();
}

/**
* Check if the Pro plugin is active. If not, consider the user to be on the free version.
*
* @since x.x
*
* @return bool
*/
private static function is_free() {
return ! FrmAppHelper::pro_is_included();
}
}
26 changes: 18 additions & 8 deletions classes/helpers/FrmAppHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -1370,16 +1370,26 @@ public static function print_admin_banner( $should_show_lite_upgrade ) {
?>
<div class="frm-upgrade-bar">
<?php
$upgrade_link = self::admin_upgrade_link(
array(
'medium' => 'settings-license',
'content' => 'lite-banner',
)
);
$cta_text = FrmSalesApi::get_best_sale_value( 'lite_banner_cta_text' );
if ( ! $cta_text ) {
$cta_text = __( 'upgrading to PRO', 'formidable' );
}

$upgrade_link = FrmSalesApi::get_best_sale_value( 'lite_banner_cta_link' );
if ( ! $upgrade_link ) {
$upgrade_link = self::admin_upgrade_link(
array(
'medium' => 'settings-license',
'content' => 'lite-banner',
)
);
}

printf(
/* translators: %1$s: Start link HTML, %2$s: End link HTML */
esc_html__( 'You\'re using Formidable Forms Lite. To unlock more features consider %1$supgrading to PRO%2$s.', 'formidable' ),
/* translators: %1$s: Start link HTML, %2$s: CTA text ("upgrading to PRO" by default), %3$s: End link HTML */
esc_html__( 'You\'re using Formidable Forms Lite. To unlock more features consider %1$s%2$s%3$s.', 'formidable' ),
'<a href="' . esc_url( $upgrade_link ) . '">',
esc_html( $cta_text ),
'</a>'
);
?>
Expand Down
22 changes: 15 additions & 7 deletions classes/helpers/FrmDashboardHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,12 +196,20 @@ class="<?php echo esc_attr( $button_classes . $add_classes ); ?>"
* @return array
*/
public static function get_license_buttons() {
$upgrade_link = FrmAppHelper::admin_upgrade_link(
array(
'medium' => 'settings-license',
'content' => 'dashboard-license-box',
)
);
$cta_text = FrmSalesApi::get_best_sale_value( 'dashboard_license_cta_text' );
if ( ! $cta_text ) {
$cta_text = __( 'Get Formidable PRO', 'formidable' );
}

$upgrade_link = FrmSalesApi::get_best_sale_value( 'dashboard_license_cta_link' );
if ( ! $upgrade_link ) {
$upgrade_link = FrmAppHelper::admin_upgrade_link(
array(
'medium' => 'settings-license',
'content' => 'dashboard-license-box',
)
);
}

return array(
array(
Expand All @@ -210,7 +218,7 @@ public static function get_license_buttons() {
'classes' => 'frm-button-primary frm-show-unauthorized',
),
array(
'label' => __( 'Get Formidable PRO', 'formidable' ),
'label' => $cta_text,
'link' => $upgrade_link,
'classes' => 'frm-button-secondary frm-show-unauthorized',
),
Expand Down
3 changes: 3 additions & 0 deletions classes/models/FrmAddon.php
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,9 @@ protected function delete_cache() {

$api = new FrmApplicationApi( $this->license );
$api->reset_cached();

$api = new FrmSalesApi();
$api->reset_cached();
}

/**
Expand Down
Loading