-
Notifications
You must be signed in to change notification settings - Fork 77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[composer] [autoload] Added start.php to autoload.files in composer.json #756
Conversation
start.php
Outdated
) { | ||
$this_sdk_relative_path = '../' . $themes_directory_name . '/' . $theme_candidate_basename; | ||
// This change ensures that the condition works even if the SDK is located in a subdirectory (e.g., vendor) | ||
$theme_candidate_basename = str_replace($themes_directory . '/' . get_stylesheet() . '/', '', $fs_root_path ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@DanieleAlessandra While I understand your logic, I think the placement of it can be made better.
The variable $theme_candidate_basename
means the "basename" of the theme itself, it doesn't need to be the basename of the SDK directory inside the theme.
So either
- Rename this variable to something like
$theme_candidate_sdk_basename
- Or change the logic of
$is_current_active_theme
start.php
Outdated
$theme_candidate_basename = str_replace($themes_directory . '/' . get_stylesheet() . '/', '', $fs_root_path ); | ||
|
||
// Check if the current file is part of the active theme. | ||
$is_current_active_theme = $file_path == $themes_directory . '/' . get_stylesheet() . '/' . $theme_candidate_basename . '/' . basename($file_path); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would name the variable like
$is_current_active_theme
-->$is_current_sdk_from_active_theme
$is_current_parent_theme
-->$is_current_sdk_from_parent_theme
.
start.php
Outdated
@@ -176,7 +190,8 @@ function_exists( 'wp_is_json_request' ) && | |||
$this_sdk_version != $fs_active_plugins->plugins[ $this_sdk_relative_path ]->version | |||
) { | |||
if ( $is_theme ) { | |||
$plugin_path = basename( dirname( $this_sdk_relative_path ) ); | |||
// Saving relative path and not only directory name as it could be a subfolder | |||
$plugin_path = $this_sdk_relative_path; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is creating an anomaly in logic. For plugins, we are saving the basename of the plugin, but for theme, we are saving the SDK's relative path! Can't we do better here? That is for both plugin and theme, save the basename?
start.php
Outdated
@@ -229,7 +244,8 @@ function_exists( 'wp_is_json_request' ) && | |||
$is_newest_sdk_plugin_active = is_plugin_active( $fs_newest_sdk->plugin_path ); | |||
} else { | |||
$current_theme = wp_get_theme(); | |||
$is_newest_sdk_plugin_active = ( $current_theme->stylesheet === $fs_newest_sdk->plugin_path ); | |||
// Detect if current theme is the one registered as newer SDK | |||
$is_newest_sdk_plugin_active = ( strpos( $fs_newest_sdk->plugin_path, '/' . $themes_directory_name . '/' . $current_theme->stylesheet . '/' ) !== false ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please see my suggestion above, perhaps we can skip this change!
start.php
Outdated
@@ -238,7 +254,8 @@ function_exists( 'wp_is_json_request' ) && | |||
* from happening by keeping the SDK info stored in the `fs_active_plugins` option. | |||
*/ | |||
if ( ! $is_newest_sdk_plugin_active && $current_theme_parent instanceof WP_Theme ) { | |||
$is_newest_sdk_plugin_active = ( $fs_newest_sdk->plugin_path === $current_theme_parent->stylesheet ); | |||
// Detect if current theme parent is the one registered as newer SDK | |||
$is_newest_sdk_plugin_active = ( strpos( $fs_newest_sdk->plugin_path, '../' . $themes_directory_name . '/' . $current_theme_parent->stylesheet . '/' ) === 0 ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please see my suggestion
start.php
Outdated
@@ -309,6 +326,9 @@ function_exists( 'wp_is_json_request' ) && | |||
} | |||
|
|||
if ( class_exists( 'Freemius' ) ) { | |||
if ($is_theme && $is_current_sdk_newest) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like you forgot to remove this part?
…t work also when SDK is stored in a subfolder (e.g. vendor folder)
…o load, even with themes and child themes
a87f124
to
ec88565
Compare
79c7a9d
to
fb64c61
Compare
fb64c61
to
d3ac8fa
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please take a look at my minor changes here, thanks.
start.php
Outdated
} else { | ||
$current_theme = wp_get_theme(); | ||
// Detect if current theme is the one registered as newer SDK | ||
$is_newest_sdk_module_active = ( strpos( $fs_newest_sdk->plugin_path, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$is_newest_sdk_module_active = (
strpos(
$fs_newest_sdk->plugin_path,
'/' . $themes_directory_name . '/' . $current_theme->stylesheet . '/'
) !== false
);
start.php
Outdated
} else { | ||
$current_theme = wp_get_theme(); | ||
// Detect if current theme is the one registered as newer SDK | ||
$is_newest_sdk_module_active = ( strpos( $fs_newest_sdk->plugin_path, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also do you think a === 0
would be a more appropriate check here, like the one for the parent theme? (line 268)
|
||
$current_theme_parent = $current_theme->parent(); | ||
|
||
/** | ||
* If the current theme is a child of the theme that has the newest SDK, this prevents a redirects loop | ||
* from happening by keeping the SDK info stored in the `fs_active_plugins` option. | ||
*/ | ||
if ( ! $is_newest_sdk_plugin_active && $current_theme_parent instanceof WP_Theme ) { | ||
$is_newest_sdk_plugin_active = ( $fs_newest_sdk->plugin_path === $current_theme_parent->stylesheet ); | ||
if ( ! $is_newest_sdk_module_active && $current_theme_parent instanceof WP_Theme ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// Detect if current theme parent is the one registered as newer SDK
$is_newest_sdk_module_active = (
strpos(
$fs_newest_sdk->plugin_path,
'../' . $themes_directory_name . '/' . $current_theme_parent->stylesheet . '/'
) === 0
);
@@ -15,7 +15,7 @@ | |||
* | |||
* @var string | |||
*/ | |||
$this_sdk_version = '2.9.0.4'; | |||
$this_sdk_version = '2.9.0.5'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@DanieleAlessandra You will find in line 40 a note about theme. Let's add something for your changes too
Something like this:
* We updated the logic to support SDK loading from a subfolder of a theme as well as from a parent theme.
* This allows the SDK to be loaded from composer dependencies or from a custom `vendor/freemius` folder.
*
* @since 2.9.0.5
* @author Daniele Alessandra (@DanielleAlessandra)
980cb5e
to
e3c1b84
Compare
e3c1b84
to
577f8d7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nicely done
No description provided.