Skip to content

Commit

Permalink
Fix strpos index and use get_stylesheet() instead of private property…
Browse files Browse the repository at this point in the history
… stylesheet
  • Loading branch information
DanieleFreemius committed Nov 28, 2024
1 parent 620feeb commit 980cb5e
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions start.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,15 @@ function_exists( 'wp_is_json_request' ) &&
$themes_directory = get_theme_root( get_stylesheet() );
$themes_directory_name = basename( $themes_directory );

// This change ensures that the condition works even if the SDK is located in a subdirectory (e.g., vendor)
/**
* We updated the logic to support SDK loading from a subfolder of a theme as well as from a parent theme
* If the SDK is found in the active theme, it sets the relative path accordingly.
* If not, it checks the parent theme and sets the relative path if found there.
* This allows the SDK to be loaded from composer dependencies or from a custom `vendor/freemius` folder.
*
* @author Daniele Alessandra (@DanieleAlessandra)
* @since 2.9.0.5
*/
$theme_candidate_sdk_basename = str_replace( $themes_directory . '/' . get_stylesheet() . '/', '', $fs_root_path );

// Check if the current file is part of the active theme.
Expand Down Expand Up @@ -253,8 +261,12 @@ function_exists( 'wp_is_json_request' ) &&
} 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,
'/' . $themes_directory_name . '/' . $current_theme->stylesheet . '/' ) !== false );
$is_newest_sdk_module_active = (
strpos(
$fs_newest_sdk->plugin_path,
'../' . $themes_directory_name . '/' . $current_theme->get_stylesheet() . '/'
) === 0
);

$current_theme_parent = $current_theme->parent();

Expand All @@ -264,8 +276,12 @@ function_exists( 'wp_is_json_request' ) &&
*/
if ( ! $is_newest_sdk_module_active && $current_theme_parent instanceof WP_Theme ) {
// 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 );
$is_newest_sdk_module_active = (
strpos(
$fs_newest_sdk->plugin_path,
'../' . $themes_directory_name . '/' . $current_theme_parent->get_stylesheet() . '/'
) === 0
);
}
}

Expand Down

0 comments on commit 980cb5e

Please sign in to comment.