Skip to content

Commit 680d9cf

Browse files
* Added checkout customization parameters
Feature/daniele/checkout custom parameters (#819) # Conflicts: # start.php * Flat checkout properties * feat(checkout): allow customizing checkout query params via filter Introduce a namespaced filter to let developers add/modify query params sent to Freemius Checkout. • Add fs_apply_filter( $fs->get_unique_affix(), 'checkout_query_params', ... ) * Add allowlist for checkout query parameters in FS_Checkout_Manager Introduced the private $_allowed_custom_params property to define all supported custom query parameters for the checkout. After applying `fs_apply_filter()`, the function now filters `$filtered_params` using `array_intersect_key()` to remove any unsupported keys before merging. This prevents external filters from injecting unexpected parameters into the checkout query. * Changed filter name to checkout/parameters, code clean and small fixes --------- Co-authored-by: Daniele Alessandra <[email protected]>
1 parent 0be8867 commit 680d9cf

File tree

2 files changed

+39
-4
lines changed

2 files changed

+39
-4
lines changed

includes/managers/class-fs-checkout-manager.php

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,36 @@
1212

1313
class FS_Checkout_Manager {
1414

15-
# region Singleton
15+
/**
16+
* Allowlist of query parameters for checkout.
17+
*/
18+
private $_allowed_custom_params = array(
19+
// currency
20+
'currency' => true,
21+
'default_currency' => true,
22+
// cart
23+
'always_show_renewals_amount' => true,
24+
'annual_discount' => true,
25+
'billing_cycle' => true,
26+
'billing_cycle_selector' => true,
27+
'bundle_discount' => true,
28+
'maximize_discounts' => true,
29+
'multisite_discount' => true,
30+
'show_inline_currency_selector' => true,
31+
'show_monthly' => true,
32+
// appearance
33+
'form_position' => true,
34+
'is_bundle_collapsed' => true,
35+
'layout' => true,
36+
'refund_policy_position' => true,
37+
'show_refund_badge' => true,
38+
'show_reviews' => true,
39+
'show_upsells' => true,
40+
'title' => true,
41+
);
42+
43+
44+
# region Singleton
1645

1746
/**
1847
* @var FS_Checkout_Manager
@@ -153,7 +182,12 @@ public function get_query_params( Freemius $fs, $plugin_id, $plan_id, $licenses
153182
( $fs->is_theme() && current_user_can( 'install_themes' ) )
154183
);
155184

156-
return array_merge( $context_params, $_GET, array(
185+
$filtered_params = $fs->apply_filters('checkout/parameters', $context_params);
186+
187+
// Allowlist only allowed query params.
188+
$filtered_params = array_intersect_key($filtered_params, $this->_allowed_custom_params);
189+
190+
return array_merge( $context_params, $filtered_params, $_GET, array(
157191
// Current plugin version.
158192
'plugin_version' => $fs->get_plugin_version(),
159193
'sdk_version' => WP_FS__SDK_VERSION,
@@ -239,4 +273,4 @@ public function get_pending_activation_url( Freemius $fs, $plugin_id ) {
239273
private function get_checkout_redirect_nonce_action( Freemius $fs ) {
240274
return $fs->get_unique_affix() . '_checkout_redirect';
241275
}
242-
}
276+
}

start.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*
1616
* @var string
1717
*/
18-
$this_sdk_version = '2.12.2.3';
18+
$this_sdk_version = '2.12.2.4';
1919

2020
#region SDK Selection Logic --------------------------------------------------------------------
2121

@@ -446,6 +446,7 @@ function_exists( 'wp_is_json_request' ) &&
446446
* fs_plugin_icon_{plugin_slug}
447447
* fs_show_trial_{plugin_slug}
448448
* fs_is_pricing_page_visible_{plugin_slug}
449+
* fs_checkout/parameters_{plugin_slug}
449450
*
450451
* --------------------------------------------------------
451452
*

0 commit comments

Comments
 (0)