From e1c06f573cf2498cd28dc149341a9f3a96e06c19 Mon Sep 17 00:00:00 2001 From: Daniele Alessandra Date: Thu, 5 Dec 2024 15:34:33 +0100 Subject: [PATCH 1/5] Use Theme name as 'plugin_path' and builds $this_sdk_relative_path using the lins of installed plugin, without using plugin_basename. This solves an infinite loop error while activating a plugin with a newer SDK version from a symlink --- start.php | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/start.php b/start.php index b4ba17d4..128fcbaa 100644 --- a/start.php +++ b/start.php @@ -15,7 +15,7 @@ * * @var string */ - $this_sdk_version = '2.10.0'; + $this_sdk_version = '2.10.1'; #region SDK Selection Logic -------------------------------------------------------------------- @@ -108,14 +108,36 @@ function_exists( 'wp_is_json_request' ) && $is_current_sdk_from_parent_theme = $file_path == $themes_directory . '/' . get_template() . '/' . $theme_candidate_sdk_basename . '/' . basename( $file_path ); } + $theme_name = null; if ( $is_current_sdk_from_active_theme ) { - $this_sdk_relative_path = '../' . $themes_directory_name . '/' . get_stylesheet() . '/' . $theme_candidate_sdk_basename; + $theme_name = get_stylesheet(); + $this_sdk_relative_path = '../' . $themes_directory_name . '/' . $theme_name . '/' . $theme_candidate_sdk_basename; $is_theme = true; } else if ( $is_current_sdk_from_parent_theme ) { - $this_sdk_relative_path = '../' . $themes_directory_name . '/' . get_template() . '/' . $theme_candidate_sdk_basename; + $theme_name = get_template(); + $this_sdk_relative_path = '../' . $themes_directory_name . '/' . $theme_name . '/' . $theme_candidate_sdk_basename; $is_theme = true; } else { - $this_sdk_relative_path = plugin_basename( $fs_root_path ); + /** + * If the plugin is not active we cannot use plugin_basename() to get the plugin directory name. + * This snippet retrieves the plugin directory name by comparing the path of the current file with the path of installed plugins. + */ + if (!function_exists('get_plugins')) { + require_once ABSPATH . 'wp-admin/includes/plugin.php'; + } + $all_plugins = get_plugins(); + + foreach ( $all_plugins as $plugin_path => $plugin_info ) { + $plugin_directory_path = dirname( realpath( WP_PLUGIN_DIR . '/' . $plugin_path ) ); + // If $fs_root_path starts with $plugin_directory_name, then we found the plugin that included this file. + if ( 0 === strpos( $fs_root_path, $plugin_directory_path . '/' ) ) { + $plugin_directory_name = basename( $plugin_directory_path ); + // Take the final part of $fs_root_path starting from $plugin_directory_name + $this_sdk_relative_path = $plugin_directory_name . '/' . substr( $fs_root_path, strlen( $plugin_directory_path ) + 1 ); + break; + } + } + $is_theme = false; } @@ -202,7 +224,7 @@ function_exists( 'wp_is_json_request' ) && ) { if ( $is_theme ) { // Saving relative path and not only directory name as it could be a subfolder - $plugin_path = $this_sdk_relative_path; + $plugin_path = $theme_name; } else { $plugin_path = plugin_basename( fs_find_direct_caller_plugin_file( $file_path ) ); } From 93d83ba6045a391b81055376ffb1662a05c17616 Mon Sep 17 00:00:00 2001 From: Swashata Ghosh Date: Mon, 9 Dec 2024 18:19:58 +0530 Subject: [PATCH 2/5] [symlink] [fix] Try alternative solution for the symlink plugin not working with direct require. --- start.php | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/start.php b/start.php index 128fcbaa..b470083e 100644 --- a/start.php +++ b/start.php @@ -118,27 +118,23 @@ function_exists( 'wp_is_json_request' ) && $this_sdk_relative_path = '../' . $themes_directory_name . '/' . $theme_name . '/' . $theme_candidate_sdk_basename; $is_theme = true; } else { + $this_sdk_relative_path = plugin_basename( $fs_root_path ); + $is_theme = false; + /** - * If the plugin is not active we cannot use plugin_basename() to get the plugin directory name. - * This snippet retrieves the plugin directory name by comparing the path of the current file with the path of installed plugins. + * If this file was included from another plugin with lower SDK version, and if this plugin is symlinked, then we need to get the actual plugin path, + * as the value right now will be wrong, it will only remove the directory separator from the file_path. + * + * The check of `fs_find_direct_caller_plugin_file` determines that this file was indeed included by a different plugin than the main plugin. */ - if (!function_exists('get_plugins')) { - require_once ABSPATH . 'wp-admin/includes/plugin.php'; - } - $all_plugins = get_plugins(); - - foreach ( $all_plugins as $plugin_path => $plugin_info ) { - $plugin_directory_path = dirname( realpath( WP_PLUGIN_DIR . '/' . $plugin_path ) ); - // If $fs_root_path starts with $plugin_directory_name, then we found the plugin that included this file. - if ( 0 === strpos( $fs_root_path, $plugin_directory_path . '/' ) ) { - $plugin_directory_name = basename( $plugin_directory_path ); - // Take the final part of $fs_root_path starting from $plugin_directory_name - $this_sdk_relative_path = $plugin_directory_name . '/' . substr( $fs_root_path, strlen( $plugin_directory_path ) + 1 ); - break; - } - } + if ( DIRECTORY_SEPARATOR . $this_sdk_relative_path === $fs_root_path && function_exists( 'fs_find_direct_caller_plugin_file' ) ) { + $original_plugin_dir_name = dirname( fs_find_direct_caller_plugin_file( $file_path ) ); - $is_theme = false; + // Remove everything before the original plugin directory name. + $this_sdk_relative_path = substr( $this_sdk_relative_path, strpos( $this_sdk_relative_path, $original_plugin_dir_name ) ); + + unset( $original_plugin_dir_name ); + } } if ( ! isset( $fs_active_plugins ) ) { From c8b547b4a82c9b3b9db6bc5b3ec519bf0d27525f Mon Sep 17 00:00:00 2001 From: Daniele Alessandra Date: Tue, 10 Dec 2024 01:58:35 +0100 Subject: [PATCH 3/5] [php-compat] [warning] [fix] Fix warning with PHP 8.2 --- start.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/start.php b/start.php index b470083e..c70a028b 100644 --- a/start.php +++ b/start.php @@ -375,7 +375,7 @@ function_exists( 'wp_is_json_request' ) && return; } - if ( version_compare( $this_sdk_version, $fs_active_plugins->newest->version, '<' ) ) { + if ( isset( $fs_active_plugins->newest ) && version_compare( $this_sdk_version, $fs_active_plugins->newest->version, '<' ) ) { $newest_sdk = $fs_active_plugins->plugins[ $fs_active_plugins->newest->sdk_path ]; $plugins_or_theme_dir_path = ( ! isset( $newest_sdk->type ) || 'theme' !== $newest_sdk->type ) ? From 505e985ac81df5ef4555338560a019208d64a975 Mon Sep 17 00:00:00 2001 From: Leo Fajardo Date: Thu, 5 Dec 2024 23:26:05 +0800 Subject: [PATCH 4/5] [playground] [anonymous-mode] Fixed the WP Playground anonymous mode support. --- includes/entities/class-fs-site.php | 1 + 1 file changed, 1 insertion(+) diff --git a/includes/entities/class-fs-site.php b/includes/entities/class-fs-site.php index e0c1fab4..abcf1034 100755 --- a/includes/entities/class-fs-site.php +++ b/includes/entities/class-fs-site.php @@ -231,6 +231,7 @@ static function is_playground_wp_environment_by_host( $host ) { foreach ( $sandbox_wp_environment_domains as $domain) { if ( + ( $host === $domain ) || fs_ends_with( $host, '.' . $domain ) || fs_ends_with( $host, '-' . $domain ) ) { From dc387f8ed4266ee7c935e0d626b2a932daee73d9 Mon Sep 17 00:00:00 2001 From: Leo Fajardo Date: Wed, 11 Dec 2024 15:52:05 +0800 Subject: [PATCH 5/5] [parallel-activation] Fixed variable usages. --- includes/class-freemius.php | 8 ++++---- start.php | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/includes/class-freemius.php b/includes/class-freemius.php index 018d7ad0..aa0fb804 100755 --- a/includes/class-freemius.php +++ b/includes/class-freemius.php @@ -1661,9 +1661,9 @@ 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 ) { - $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, @@ -1681,7 +1681,7 @@ private function register_after_settings_parse_hooks() { * @return bool */ private function is_parallel_activation() { - return ! empty( $this->premium_plugin_basename_from_parallel_activation ); + return ! empty( $this->_premium_plugin_basename_from_parallel_activation ); } /** @@ -5205,7 +5205,7 @@ private function parse_settings( &$plugin_info ) { 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; + $this->_premium_plugin_basename_from_parallel_activation = $premium_basename; if ( is_plugin_active( $premium_basename ) ) { $is_premium = true; diff --git a/start.php b/start.php index c70a028b..df0f3584 100644 --- a/start.php +++ b/start.php @@ -134,7 +134,7 @@ function_exists( 'wp_is_json_request' ) && $this_sdk_relative_path = substr( $this_sdk_relative_path, strpos( $this_sdk_relative_path, $original_plugin_dir_name ) ); unset( $original_plugin_dir_name ); - } + } } if ( ! isset( $fs_active_plugins ) ) { @@ -375,7 +375,7 @@ function_exists( 'wp_is_json_request' ) && return; } - if ( isset( $fs_active_plugins->newest ) && version_compare( $this_sdk_version, $fs_active_plugins->newest->version, '<' ) ) { + if ( isset( $fs_active_plugins->newest ) && version_compare( $this_sdk_version, $fs_active_plugins->newest->version, '<' ) ) { $newest_sdk = $fs_active_plugins->plugins[ $fs_active_plugins->newest->sdk_path ]; $plugins_or_theme_dir_path = ( ! isset( $newest_sdk->type ) || 'theme' !== $newest_sdk->type ) ?