Skip to content

Commit

Permalink
Version 2.10.0
Browse files Browse the repository at this point in the history
Merge pull request #764 from Freemius/develop

* [staging-sites] Updated the staging site URL pattern for Kinsta.

* [anonymous-mode] Support anonymous mode by default on sandbox sites.

* [license-dialog] Fixed the retrieving of the selected license's ID from the license update dialog.

* [pricing] [filter] Respect the plugin_icon filter and add new filter to configure single package mode of the pricing app.

* [pricing] [filter] Add new filter to enqueue a CSS to the pricing page.

* [pricing] [update] Update version 1.1.0 of the pricing app.

* [cron] Improved the scheduling of the install sync cron job.

* [parallel-activation] Improved the support for plugins with free and premium versions that can be activated in parallel.

* [composer] [autoload] Added start.php to autoload.files in composer.json supporting both plugins and themes (#756)

* [composer] [autoload] Added start.php to autoload.files in composer.json

* [composer] [vendor] [themes] Changed logic related to theme to make it work also when SDK is stored in a subfolder (e.g. vendor folder)

* [themes] [child theme] [load priority] Correctly determine SDK file to load, even with themes and child themes

* Code style, renamed variables, removed unused $is_theme check.

* Code Style (wordpress)

* Code styling (spaces instead of tabs)

* Revert indent spacing

* Fix strpos index and use get_stylesheet() instead of private property stylesheet

---------

Co-authored-by: Daniele Alessandra <[email protected]>

* [version] Version 2.10.0

---------

Co-authored-by: Leo Fajardo <[email protected]>
Co-authored-by: Daniele Alessandra <[email protected]>
Co-authored-by: Daniele Alessandra <[email protected]>
  • Loading branch information
4 people authored Dec 3, 2024
2 parents 5669671 + 517391b commit d3c35b9
Show file tree
Hide file tree
Showing 7 changed files with 212 additions and 50 deletions.
2 changes: 1 addition & 1 deletion assets/js/pricing/freemius-pricing.js

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
"require": {
"php": ">=5.6"
},
"autoload": {
"files": [
"start.php"
]
},
"require-dev": {
"wp-coding-standards/wpcs": "^2.3",
"dealerdirect/phpcodesniffer-composer-installer": "^1.0",
Expand Down
121 changes: 97 additions & 24 deletions includes/class-freemius.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,12 @@ class Freemius extends Freemius_Abstract {
*/
private $_enable_anonymous = true;

/**
* @since 2.9.1
* @var string|null Hints the SDK whether the plugin supports parallel activation mode, preventing the auto-deactivation of the free version when the premium version is activated, and vice versa.
*/
private $_premium_plugin_basename_from_parallel_activation;

/**
* @since 1.1.7.5
* @var bool Hints the SDK if plugin should run in anonymous mode (only adds feedback form).
Expand Down Expand Up @@ -1651,6 +1657,31 @@ private function register_after_settings_parse_hooks() {
);
}
}

if (
$this->is_user_in_admin() &&
$this->is_parallel_activation() &&
$this->_premium_plugin_basename !== $this->premium_plugin_basename_from_parallel_activation
) {
$this->_premium_plugin_basename = $this->premium_plugin_basename_from_parallel_activation;

register_activation_hook(
dirname( $this->_plugin_dir_path ) . '/' . $this->_premium_plugin_basename,
array( &$this, '_activate_plugin_event_hook' )
);
}
}

/**
* Determines if a plugin is running in parallel activation mode.
*
* @author Leo Fajardo (@leorw)
* @since 2.9.1
*
* @return bool
*/
private function is_parallel_activation() {
return ! empty( $this->premium_plugin_basename_from_parallel_activation );
}

/**
Expand Down Expand Up @@ -5155,19 +5186,43 @@ private function parse_settings( &$plugin_info ) {
$this->_plugin :
new FS_Plugin();

$is_premium = $this->get_bool_option( $plugin_info, 'is_premium', true );
$premium_suffix = $this->get_option( $plugin_info, 'premium_suffix', '(Premium)' );

$module_type = $this->get_option( $plugin_info, 'type', $this->_module_type );

$parallel_activation = $this->get_option( $plugin_info, 'parallel_activation' );

if (
! $is_premium &&
is_array( $parallel_activation ) &&
( WP_FS__MODULE_TYPE_PLUGIN === $module_type ) &&
$this->get_bool_option( $parallel_activation, 'enabled' )
) {
$premium_basename = $this->get_option( $parallel_activation, 'premium_version_basename' );

if ( empty( $premium_basename ) ) {
throw new Exception('You need to specify the premium version basename to enable parallel version activation.');
}

$this->premium_plugin_basename_from_parallel_activation = $premium_basename;

if ( is_plugin_active( $premium_basename ) ) {
$is_premium = true;
}
}

$plugin->update( array(
'id' => $id,
'type' => $this->get_option( $plugin_info, 'type', $this->_module_type ),
'type' => $module_type,
'public_key' => $public_key,
'slug' => $this->_slug,
'premium_slug' => $this->get_option( $plugin_info, 'premium_slug', "{$this->_slug}-premium" ),
'parent_plugin_id' => $parent_id,
'version' => $this->get_plugin_version(),
'title' => $this->get_plugin_name( $premium_suffix ),
'file' => $this->_plugin_basename,
'is_premium' => $this->get_bool_option( $plugin_info, 'is_premium', true ),
'is_premium' => $is_premium,
'premium_suffix' => $premium_suffix,
'is_live' => $this->get_bool_option( $plugin_info, 'is_live', true ),
'affiliate_moderation' => $this->get_option( $plugin_info, 'has_affiliation' ),
Expand Down Expand Up @@ -5236,7 +5291,14 @@ private function parse_settings( &$plugin_info ) {
$this->_anonymous_mode = false;
} else {
$this->_enable_anonymous = $this->get_bool_option( $plugin_info, 'enable_anonymous', true );
$this->_anonymous_mode = $this->get_bool_option( $plugin_info, 'anonymous_mode', false );
$this->_anonymous_mode = (
$this->get_bool_option( $plugin_info, 'anonymous_mode', false ) ||
(
$this->apply_filters( 'playground_anonymous_mode', true ) &&
! empty( $_SERVER['HTTP_HOST'] ) &&
FS_Site::is_playground_wp_environment_by_host( $_SERVER['HTTP_HOST'] )
)
);
}
$this->_permissions = $this->get_option( $plugin_info, 'permissions', array() );
$this->_is_bundle_license_auto_activation_enabled = $this->get_option( $plugin_info, 'bundle_license_auto_activation', false );
Expand Down Expand Up @@ -5444,7 +5506,7 @@ function _plugin_code_type_changed() {

if ( $this->is_registered() ) {
// Schedule code type changes event.
$this->schedule_install_sync();
$this->maybe_schedule_install_sync_cron();
}

/**
Expand Down Expand Up @@ -6507,6 +6569,33 @@ private function maybe_schedule_sync_cron() {
$this->schedule_sync_cron();
}

/**
* Instead of running blocking install sync event, execute non blocking scheduled cron job.
*
* @param int $except_blog_id Since 2.0.0 when running in a multisite network environment, the cron execution is consolidated. This param allows excluding specified blog ID from being the cron job executor.
*
* @author Leo Fajardo (@leorw)
* @since 2.9.1
*/
private function maybe_schedule_install_sync_cron( $except_blog_id = 0 ) {
if ( ! $this->is_user_in_admin() ) {
return;
}

if ( $this->is_clone() ) {
return;
}

if (
// The event has been properly scheduled, so no need to reschedule it.
is_numeric( $this->next_install_sync() )
) {
return;
}

$this->schedule_cron( 'install_sync', 'install_sync', 'single', WP_FS__SCRIPT_START_TIME, false, $except_blog_id );
}

/**
* @author Vova Feldman (@svovaf)
* @since 1.1.7.3
Expand Down Expand Up @@ -6604,22 +6693,6 @@ private function get_install_sync_cron_blog_id() {
return $this->get_cron_blog_id( 'install_sync' );
}

/**
* Instead of running blocking install sync event, execute non blocking scheduled wp-cron.
*
* @author Vova Feldman (@svovaf)
* @since 1.1.7.3
*
* @param int $except_blog_id Since 2.0.0 when running in a multisite network environment, the cron execution is consolidated. This param allows excluding excluded specified blog ID from being the cron executor.
*/
private function schedule_install_sync( $except_blog_id = 0 ) {
if ( $this->is_clone() ) {
return;
}

$this->schedule_cron( 'install_sync', 'install_sync', 'single', WP_FS__SCRIPT_START_TIME, false, $except_blog_id );
}

/**
* Unix timestamp for previous install sync cron execution or false if never executed.
*
Expand Down Expand Up @@ -7411,7 +7484,7 @@ function _activate_plugin_event_hook() {
*/
if (
is_plugin_active( $other_version_basename ) &&
$this->apply_filters( 'deactivate_on_activation', true )
$this->apply_filters( 'deactivate_on_activation', ! $this->is_parallel_activation() )
) {
deactivate_plugins( $other_version_basename );
}
Expand All @@ -7425,7 +7498,7 @@ function _activate_plugin_event_hook() {

// Schedule re-activation event and sync.
// $this->sync_install( array(), true );
$this->schedule_install_sync();
$this->maybe_schedule_install_sync_cron();

// If activating the premium module version, add an admin notice to congratulate for an upgrade completion.
if ( $is_premium_version_activation ) {
Expand Down Expand Up @@ -8616,7 +8689,7 @@ private function update_plugin_version_event() {
return;
}

$this->schedule_install_sync();
$this->maybe_schedule_install_sync_cron();
// $this->sync_install( array(), true );
}

Expand Down Expand Up @@ -15974,7 +16047,7 @@ private function update_multisite_data_after_site_deactivation( $context_blog_id
if ( $this->is_install_sync_scheduled() &&
$context_blog_id == $this->get_install_sync_cron_blog_id()
) {
$this->schedule_install_sync( $context_blog_id );
$this->maybe_schedule_install_sync_cron( $context_blog_id );
}
}

Expand Down
35 changes: 34 additions & 1 deletion includes/entities/class-fs-site.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ static function is_localhost_by_address( $url ) {
fs_ends_with( $subdomain, '.cloudwaysapps.com' ) ||
// Kinsta
(
( fs_starts_with( $subdomain, 'staging-' ) || fs_starts_with( $subdomain, 'env-' ) ) &&
( fs_starts_with( $subdomain, 'stg-' ) || fs_starts_with( $subdomain, 'staging-' ) || fs_starts_with( $subdomain, 'env-' ) ) &&
( fs_ends_with( $subdomain, '.kinsta.com' ) || fs_ends_with( $subdomain, '.kinsta.cloud' ) )
) ||
// DesktopServer
Expand All @@ -208,6 +208,39 @@ static function is_localhost_by_address( $url ) {
);
}

/**
* @author Leo Fajardo (@leorw)
* @since 2.9.1
*
* @param string $host
*
* @return bool
*/
static function is_playground_wp_environment_by_host( $host ) {
// Services aimed at providing a WordPress sandbox environment.
$sandbox_wp_environment_domains = array(
// InstaWP
'instawp.xyz',

// TasteWP
'tastewp.com',

// WordPress Playground
'playground.wordpress.net',
);

foreach ( $sandbox_wp_environment_domains as $domain) {
if (
fs_ends_with( $host, '.' . $domain ) ||
fs_ends_with( $host, '-' . $domain )
) {
return true;
}
}

return false;
}

function is_localhost() {
return ( WP_FS__IS_LOCALHOST_FOR_SERVER || self::is_localhost_by_address( $this->url ) );
}
Expand Down
Loading

0 comments on commit d3c35b9

Please sign in to comment.