Skip to content

Commit

Permalink
[opt-in] [skip] [add-ons] When activating a parent account, also upda…
Browse files Browse the repository at this point in the history
…te the license required permissions if anonymous.
  • Loading branch information
fajardoleo authored and vovafeldman committed Jan 8, 2023
1 parent 6cc1481 commit a552c72
Showing 1 changed file with 24 additions and 14 deletions.
38 changes: 24 additions & 14 deletions includes/class-freemius.php
Original file line number Diff line number Diff line change
Expand Up @@ -9119,6 +9119,26 @@ private function reset_anonymous_mode( $network_or_blog_ids = false ) {
}
}

/**
* @author Leo Fajardo (@leorw)
* @since 2.5.3
*/
private function update_license_required_permissions_if_anonymous() {
if ( ! $this->is_anonymous() ) {
return;
}

$this->reset_anonymous_mode( fs_is_network_admin() );

FS_Permission_Manager::instance( $this )->update_permissions_tracking_flag( array(
'essentials' => true,
'events' => true,
'diagnostic' => false,
'extensions' => false,
'site' => false,
) );
}

/**
* This is used to ensure that before redirecting to the opt-in page after resetting the anonymous mode or
* deleting the account in the network level, the URL of the page to redirect to is correct.
Expand Down Expand Up @@ -18076,19 +18096,7 @@ function _install_with_new_user() {

$has_pending_activation_confirmation_param = fs_request_has( 'pending_activation' );

$fs_is_network_admin = fs_is_network_admin();

if ( $this->is_anonymous() ) {
$this->reset_anonymous_mode( $fs_is_network_admin );

FS_Permission_Manager::instance( $this )->update_permissions_tracking_flag( array(
'essentials' => true,
'events' => true,
'diagnostic' => false,
'extensions' => false,
'site' => false,
) );
}
$this->update_license_required_permissions_if_anonymous();

if ( ( $this->is_plugin() && fs_request_is_action( $this->get_unique_affix() . '_activate_new' ) ) ||
// @todo This logic should be improved because it's executed on every load of a theme.
Expand All @@ -18097,7 +18105,7 @@ function _install_with_new_user() {
// check_admin_referer( $this->_slug . '_activate_new' );

if ( fs_request_has( 'user_secret_key' ) ) {
if ( $fs_is_network_admin && isset( $this->_storage->pending_sites_info ) ) {
if ( fs_is_network_admin() && isset( $this->_storage->pending_sites_info ) ) {
$pending_sites_info = $this->_storage->pending_sites_info;

$this->install_many_pending_with_user(
Expand Down Expand Up @@ -18955,6 +18963,8 @@ private function activate_parent_account( Freemius $parent_fs ) {
// Sync add-on plans.
$parent_fs->_sync_plans();

$parent_fs->update_license_required_permissions_if_anonymous();

$parent_fs->_set_account( $user, $parent_fs->_site );
}

Expand Down

0 comments on commit a552c72

Please sign in to comment.