Skip to content
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

Merged
merged 8 commits into from
Nov 28, 2024

Conversation

DanieleAlessandra
Copy link
Collaborator

No description provided.

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 );
Copy link
Contributor

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

  1. Rename this variable to something like $theme_candidate_sdk_basename
  2. 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);
Copy link
Contributor

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

  1. $is_current_active_theme --> $is_current_sdk_from_active_theme
  2. $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;
Copy link
Contributor

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 );
Copy link
Contributor

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 );
Copy link
Contributor

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) {
Copy link
Contributor

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?

@DanieleAlessandra DanieleAlessandra force-pushed the feature/autoload-start-file branch 2 times, most recently from a87f124 to ec88565 Compare November 27, 2024 12:37
@DanieleAlessandra DanieleAlessandra force-pushed the feature/autoload-start-file branch 2 times, most recently from 79c7a9d to fb64c61 Compare November 28, 2024 08:39
Copy link
Contributor

@swashata swashata left a 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,
Copy link
Contributor

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,
Copy link
Contributor

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 ) {
Copy link
Contributor

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';
Copy link
Contributor

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

CleanShot 2024-11-28 at 17 51 01@2x

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)

Copy link
Contributor

@swashata swashata left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nicely done

@swashata swashata merged commit 84bbdb1 into develop Nov 28, 2024
5 checks passed
@swashata swashata deleted the feature/autoload-start-file branch November 28, 2024 15:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants