Skip to content

Commit b661c43

Browse files
PSMEL-353 - Updated SDK
1 parent 55349cb commit b661c43

17 files changed

+386
-211
lines changed

freemius/includes/class-freemius.php

Lines changed: 48 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1546,7 +1546,7 @@ private function register_constructor_hooks() {
15461546
fs_request_is_action( 'reset_anonymous_mode' ) ||
15471547
fs_request_is_action( 'reset_pending_activation_mode' )
15481548
) &&
1549-
$this->get_unique_affix() === fs_request_get( 'fs_unique_affix' )
1549+
$this->get_unique_affix() === fs_request_get_raw( 'fs_unique_affix' )
15501550
) {
15511551
add_action( 'admin_init', array( &$this, 'connect_again' ) );
15521552
}
@@ -3759,7 +3759,7 @@ static function _set_db_option() {
37593759
self::shoot_ajax_failure();
37603760
}
37613761

3762-
$option_value = fs_request_get( 'option_value' );
3762+
$option_value = fs_request_get_raw( 'option_value' );
37633763

37643764
if ( ! empty( $option_value ) ) {
37653765
update_option( $option_name, $option_value );
@@ -10298,7 +10298,20 @@ function get_parent_id() {
1029810298
function get_usage_tracking_terms_url() {
1029910299
return $this->apply_filters(
1030010300
'usage_tracking_terms_url',
10301-
"https://freemius.com/wordpress/usage-tracking/{$this->_plugin->id}/{$this->_slug}/"
10301+
"https://freemius.com/product/opt-in/{$this->_plugin->id}/{$this->_slug}/"
10302+
);
10303+
}
10304+
10305+
/**
10306+
* @todo (For LiteSDK) We can refactor this and other related functions giving links to several landing pages on freemius.com to come from a separate class like `FS_Terms_Pages`. This would get a `FS_WP_Hook` (hypothetical) instance as a dependency and use it to hook into the `license_activation_terms_url` or related filters. The entry level instance from `ms_fs()` would hold a public read-only variable `my_fs()->terms_pages` which would be an instance of `FS_Terms_Pages` and would hold all the links to the terms pages.
10307+
* @since 2.5.8
10308+
*
10309+
* @return string
10310+
*/
10311+
function get_license_activation_terms_url() {
10312+
return $this->apply_filters(
10313+
'license_activation_terms_url',
10314+
"https://freemius.com/product/license-activation/{$this->_plugin->id}/{$this->_slug}/"
1030210315
);
1030310316
}
1030410317

@@ -13661,7 +13674,7 @@ function _activate_license_ajax_action() {
1366113674

1366213675
$this->check_ajax_referer( 'activate_license' );
1366313676

13664-
$license_key = trim( fs_request_get( 'license_key' ) );
13677+
$license_key = trim( fs_request_get_raw( 'license_key' ) );
1366513678

1366613679
if ( empty( $license_key ) ) {
1366713680
exit;
@@ -16676,64 +16689,6 @@ private static function decrypt_entity( FS_Entity $entity ) {
1667616689
return $clone;
1667716690
}
1667816691

16679-
/**
16680-
* Tries to activate account based on POST params.
16681-
*
16682-
* @author Vova Feldman (@svovaf)
16683-
* @since 1.0.2
16684-
*
16685-
* @deprecated Not in use, outdated.
16686-
*/
16687-
function _activate_account() {
16688-
if ( $this->is_registered() ) {
16689-
// Already activated.
16690-
return;
16691-
}
16692-
16693-
self::_clean_admin_content_section();
16694-
16695-
if ( fs_request_is_action( 'activate' ) && fs_request_is_post() ) {
16696-
// check_admin_referer( 'activate_' . $this->_plugin->public_key );
16697-
16698-
// Verify matching plugin details.
16699-
if ( $this->_plugin->id != fs_request_get( 'plugin_id' ) || $this->_slug != fs_request_get( 'plugin_slug' ) ) {
16700-
return;
16701-
}
16702-
16703-
$user = new FS_User();
16704-
$user->id = fs_request_get( 'user_id' );
16705-
$user->public_key = fs_request_get( 'user_public_key' );
16706-
$user->secret_key = fs_request_get( 'user_secret_key' );
16707-
$user->email = fs_request_get( 'user_email' );
16708-
$user->first = fs_request_get( 'user_first' );
16709-
$user->last = fs_request_get( 'user_last' );
16710-
$user->is_verified = fs_request_get_bool( 'user_is_verified' );
16711-
16712-
$site = new FS_Site();
16713-
$site->id = fs_request_get( 'install_id' );
16714-
$site->public_key = fs_request_get( 'install_public_key' );
16715-
$site->secret_key = fs_request_get( 'install_secret_key' );
16716-
$site->plan_id = fs_request_get( 'plan_id' );
16717-
16718-
$plans = array();
16719-
$plans_data = json_decode( urldecode( fs_request_get( 'plans' ) ) );
16720-
foreach ( $plans_data as $p ) {
16721-
$plan = new FS_Plugin_Plan( $p );
16722-
if ( $site->plan_id == $plan->id ) {
16723-
$plan->title = fs_request_get( 'plan_title' );
16724-
$plan->name = fs_request_get( 'plan_name' );
16725-
}
16726-
16727-
$plans[] = $plan;
16728-
}
16729-
16730-
$this->_set_account( $user, $site, $plans );
16731-
16732-
// Reload the page with the keys.
16733-
fs_redirect( $this->_get_admin_page_url() );
16734-
}
16735-
}
16736-
1673716692
/**
1673816693
* @author Vova Feldman (@svovaf)
1673916694
* @since 1.0.7
@@ -17748,8 +17703,8 @@ function _install_with_new_user() {
1774817703

1774917704
$this->install_many_pending_with_user(
1775017705
fs_request_get( 'user_id' ),
17751-
fs_request_get( 'user_public_key' ),
17752-
fs_request_get( 'user_secret_key' ),
17706+
fs_request_get_raw( 'user_public_key' ),
17707+
fs_request_get_raw( 'user_secret_key' ),
1775317708
fs_request_get_bool( 'is_marketing_allowed', null ),
1775417709
fs_request_get_bool( 'is_extensions_tracking_allowed', null ),
1775517710
fs_request_get_bool( 'is_diagnostic_tracking_allowed', null ),
@@ -17760,14 +17715,14 @@ function _install_with_new_user() {
1776017715
} else {
1776117716
$this->install_with_new_user(
1776217717
fs_request_get( 'user_id' ),
17763-
fs_request_get( 'user_public_key' ),
17764-
fs_request_get( 'user_secret_key' ),
17718+
fs_request_get_raw( 'user_public_key' ),
17719+
fs_request_get_raw( 'user_secret_key' ),
1776517720
fs_request_get_bool( 'is_marketing_allowed', null ),
1776617721
fs_request_get_bool( 'is_extensions_tracking_allowed', null ),
1776717722
fs_request_get_bool( 'is_diagnostic_tracking_allowed', null ),
1776817723
fs_request_get( 'install_id' ),
17769-
fs_request_get( 'install_public_key' ),
17770-
fs_request_get( 'install_secret_key' ),
17724+
fs_request_get_raw( 'install_public_key' ),
17725+
fs_request_get_raw( 'install_secret_key' ),
1777117726
true,
1777217727
fs_request_get_bool( 'auto_install' )
1777317728
);
@@ -18106,13 +18061,13 @@ function _install_with_current_user() {
1810618061
}
1810718062

1810818063
if ( fs_request_is_action( $this->get_unique_affix() . '_activate_existing' ) && fs_request_is_post() ) {
18109-
// check_admin_referer( 'activate_existing_' . $this->_plugin->public_key );
18064+
check_admin_referer( $this->get_unique_affix() . '_activate_existing' );
1811018065

1811118066
/**
1811218067
* @author Vova Feldman (@svovaf)
1811318068
* @since 1.1.9 Add license key if given.
1811418069
*/
18115-
$license_key = fs_request_get( 'license_secret_key' );
18070+
$license_key = fs_request_get_raw( 'license_secret_key' );
1811618071

1811718072
FS_Permission_Manager::instance( $this )->update_permissions_tracking_flag( array(
1811818073
FS_Permission_Manager::PERMISSION_DIAGNOSTIC => fs_request_get_bool( 'is_diagnostic_tracking_allowed', null ),
@@ -20847,7 +20802,7 @@ function _set_data_debug_mode() {
2084720802
return;
2084820803
}
2084920804

20850-
$license_or_user_key = fs_request_get( 'license_or_user_key' );
20805+
$license_or_user_key = fs_request_get_raw( 'license_or_user_key' );
2085120806

2085220807
$transient_value = ( ! empty( $license_or_user_key ) ) ?
2085320808
'true' :
@@ -22685,8 +22640,8 @@ private function complete_change_owner() {
2268522640

2268622641
$user = new FS_User();
2268722642
$user->id = fs_request_get( 'user_id' );
22688-
$user->public_key = fs_request_get( 'user_public_key' );
22689-
$user->secret_key = fs_request_get( 'user_secret_key' );
22643+
$user->public_key = fs_request_get_raw( 'user_public_key' );
22644+
$user->secret_key = fs_request_get_raw( 'user_secret_key' );
2269022645

2269122646
$prev_user = $this->_user;
2269222647
$this->_user = $user;
@@ -23182,6 +23137,9 @@ private function _handle_account_edits() {
2318223137
$state = fs_request_get( 'state', 'init' );
2318323138
switch ( $state ) {
2318423139
case 'init':
23140+
// The nonce is injected by the error handler in `_email_address_update_ajax_handler` function.
23141+
check_admin_referer( 'change_owner' );
23142+
2318523143
$candidate_email = fs_request_get( 'candidate_email' );
2318623144
$transfer_type = fs_request_get( 'transfer_type' );
2318723145

@@ -23194,11 +23152,17 @@ private function _handle_account_edits() {
2319423152
}
2319523153
break;
2319623154
case 'owner_confirmed':
23155+
// We cannot (or need not to) check the nonce and referer here, because the link comes from the email sent by our API.
2319723156
$candidate_email = fs_request_get( 'candidate_email', '' );
2319823157

23158+
if ( ! is_email($candidate_email ) ) {
23159+
return;
23160+
}
23161+
2319923162
$this->_admin_notices->add( sprintf( $this->get_text_inline( 'Thanks for confirming the ownership change. An email was just sent to %s for final approval.', 'change-owner-request_owner-confirmed' ), '<b>' . $candidate_email . '</b>' ) );
2320023163
break;
2320123164
case 'candidate_confirmed':
23165+
// We do not need to validate the authenticity of this request here, because the `complete_change_owner` does that for us through API calls.
2320223166
if ( $this->complete_change_owner() ) {
2320323167
$this->_admin_notices->add_sticky(
2320423168
sprintf( $this->get_text_inline( '%s is the new owner of the account.', 'change-owner-request_candidate-confirmed' ), '<b>' . $this->_user->email . '</b>' ),
@@ -23232,6 +23196,10 @@ private function _handle_account_edits() {
2323223196

2323323197
#region Actions that might be called from external links (e.g. email)
2323423198

23199+
/**
23200+
* !!IMPORTANT!!: We cannot check for a valid nonce in this region, because the links could be coming from emails.
23201+
*/
23202+
2323523203
case 'cancel_trial':
2323623204
$result = $this->cancel_subscription_or_trial( $plugin_id );
2323723205
if ( $this->is_api_error( $result ) ) {
@@ -23538,11 +23506,11 @@ function _fs_pricing_ajax_action_handler() {
2353823506
$params = array(
2353923507
'is_enriched' => true,
2354023508
'trial' => fs_request_get_bool( 'trial' ),
23541-
'sandbox' => fs_request_get( 'sandbox' ),
23542-
's_ctx_type' => fs_request_get( 's_ctx_type' ),
23543-
's_ctx_id' => fs_request_get( 's_ctx_id' ),
23544-
's_ctx_ts' => fs_request_get( 's_ctx_ts' ),
23545-
's_ctx_secure' => fs_request_get( 's_ctx_secure' ),
23509+
'sandbox' => fs_request_get_raw( 'sandbox' ),
23510+
's_ctx_type' => fs_request_get_raw( 's_ctx_type' ),
23511+
's_ctx_id' => fs_request_get_raw( 's_ctx_id' ),
23512+
's_ctx_ts' => fs_request_get_raw( 's_ctx_ts' ),
23513+
's_ctx_secure' => fs_request_get_raw( 's_ctx_secure' ),
2354623514
);
2354723515

2354823516
$bundle_id = $this->get_bundle_id();
@@ -25872,7 +25840,7 @@ private function get_gdpr_admin_notice_string( $user_plugins ) {
2587225840
'%s %s %s',
2587325841
$thank_you,
2587425842
$already_opted_in,
25875-
sprintf( $this->get_text_inline( 'Due to the new %sEU General Data Protection Regulation (GDPR)%s compliance requirements it is required that you provide your explicit consent, again, confirming that you are onboard :-)', 'due-to-gdpr-compliance-requirements' ), '<a href="https://eugdpr.org/" target="_blank" rel="noopener noreferrer">', '</a>' ) .
25843+
sprintf( $this->get_text_inline( 'Due to the new %sEU General Data Protection Regulation (GDPR)%s compliance requirements it is required that you provide your explicit consent, again, confirming that you are onboard :-)', 'due-to-gdpr-compliance-requirements' ), '<a href="https://ec.europa.eu/info/law/law-topic/data-protection_en/" target="_blank" rel="noopener noreferrer">', '</a>' ) .
2587625844
'<br><br>' .
2587725845
'<b>' . $this->get_text_inline( "Please let us know if you'd like us to contact you for security & feature updates, educational content, and occasional offers:", 'contact-for-updates' ) . '</b>' .
2587825846
$actions .
@@ -26161,7 +26129,7 @@ function _fetch_is_marketing_required_flag_value_ajax_action() {
2616126129

2616226130
$this->check_ajax_referer( 'fetch_is_marketing_required_flag_value' );
2616326131

26164-
$license_key = fs_request_get( 'license_key' );
26132+
$license_key = fs_request_get_raw( 'license_key' );
2616526133

2616626134
if ( empty($license_key) ) {
2616726135
self::shoot_ajax_failure( $this->get_text_inline( 'License key is empty.', 'empty-license-key' ) );

freemius/includes/class-fs-plugin-updater.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ private function filters() {
134134
function catch_plugin_information_dialog_contents() {
135135
if (
136136
'plugin-information' !== fs_request_get( 'tab', false ) ||
137-
$this->_fs->get_slug() !== fs_request_get( 'plugin', false )
137+
$this->_fs->get_slug() !== fs_request_get_raw( 'plugin', false )
138138
) {
139139
return;
140140
}
@@ -153,7 +153,7 @@ function catch_plugin_information_dialog_contents() {
153153
function edit_and_echo_plugin_information_dialog_contents( $hook_suffix ) {
154154
if (
155155
'plugin-information' !== fs_request_get( 'tab', false ) ||
156-
$this->_fs->get_slug() !== fs_request_get( 'plugin', false )
156+
$this->_fs->get_slug() !== fs_request_get_raw( 'plugin', false )
157157
) {
158158
return;
159159
}

0 commit comments

Comments
 (0)