Skip to content
Open
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
67 changes: 64 additions & 3 deletions includes/managers/class-fs-checkout-manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,35 @@

class FS_Checkout_Manager {

# region Singleton
/**
* Allowlist of query parameters for checkout.
*/
private $_allowed_custom_params = array(
// currency
'currency' => 'string',
'default_currency' => 'string',
// cart
'always_show_renewals_amount' => 'bool',
'annual_discount' => 'bool',
'billing_cycle' => ['string', 'int'],
'bundle_discount' => 'float',
'maximize_discounts' => 'bool',
'multisite_discount' => ['bool', 'string'], // string expected to be "auto"
'show_inline_currency_selector' => 'bool',
'show_monthly' => 'bool',
// appearance
'form_position' => 'string',
'is_bundle_collapsed' => 'bool',
'layout' => 'string',
'refund_policy_position' => 'string',
'show_refund_badge' => 'bool',
'show_reviews' => 'bool',
'show_upsells' => 'bool',
'title' => 'string',
);


# region Singleton

/**
* @var FS_Checkout_Manager
Expand Down Expand Up @@ -153,7 +181,40 @@ public function get_query_params( Freemius $fs, $plugin_id, $plan_id, $licenses
( $fs->is_theme() && current_user_can( 'install_themes' ) )
);

return array_merge( $context_params, $_GET, array(
/**
* Allow developers to customize the checkout query params before final validation,
* so custom keys can be included and known keys can be overridden.
* We then validate the merged params and re-attach any unknown custom keys that
* validation intentionally ignores, preserving developer-provided extras while
* keeping core keys safe.
*
* Usage example (in a plugin/theme):
*
* add_filter( 'fs_checkout_query_params_' . fs()->get_unique_affix(), function( $params ) {
* // Add or modify query params passed to the Freemius Checkout.
* $params['coupon'] = 'WELCOME10';
* $params['utm_source'] = 'my-plugin';
* return $params;
* }, 10, 5 );
*
* @since 2.12.2.4
*
* @param array $context_params The params prepared by the SDK before validation.
* @param Freemius $fs The Freemius instance of the calling module.
* @param int|mixed $plugin_id The target plugin/add-on ID for the checkout context.
* @param int|mixed $plan_id The selected plan ID (if any).
* @param int|mixed $licenses The requested number of licenses (if provided).
*/
$filtered_params = fs_apply_filter(
$fs->get_unique_affix(),
'checkout_query_params',
$context_params
);

// Allowlist only allowed query params.
$filtered_params = array_intersect_key($filtered_params, $this->_allowed_custom_params);

return array_merge( $context_params, $filtered_params, $_GET, array(
// Current plugin version.
'plugin_version' => $fs->get_plugin_version(),
'sdk_version' => WP_FS__SDK_VERSION,
Expand Down Expand Up @@ -239,4 +300,4 @@ public function get_pending_activation_url( Freemius $fs, $plugin_id ) {
private function get_checkout_redirect_nonce_action( Freemius $fs ) {
return $fs->get_unique_affix() . '_checkout_redirect';
}
}
}
2 changes: 1 addition & 1 deletion start.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*
* @var string
*/
$this_sdk_version = '2.12.2.3';
$this_sdk_version = '2.12.2.4';

#region SDK Selection Logic --------------------------------------------------------------------

Expand Down