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

[plugin-main-file-location] [enhancement] Enriched the main plugin fi… #593

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 25 additions & 10 deletions includes/class-freemius.php
Original file line number Diff line number Diff line change
Expand Up @@ -2203,20 +2203,35 @@ private function get_caller_main_file_and_type( $module_id ) {
) {
if ( 'activate_plugin' === $bt[ $i ]['function'] ) {
/**
* Store the directory of the activator plugin so that any other file that starts with it
* cannot be mistakenly chosen as a candidate caller file.
* If a plugin is programmatically activated with the following call stack: "PluginX -> ThemeX -> activate_plugin(PluginY)", then the `for` below makes sure that `$plugin_dir_to_skip` will be set to the plugin's dir. Otherwise, the SDK will pick up PluginX's main file as the main file of PluginY. This is relevant for companion theme plugins that can install plugins (that use Freemius) when importing starter sites.
*
* @author Leo Fajardo
*
* @since 2.3.0
* @since 2.5.3
*/
$caller_file_path = fs_normalize_path( $bt[ $i ]['file'] );
for ( $j = $i; $j < $len; $j ++ ) {
if ( empty( $bt[ $j ]['file'] ) ) {
continue;
}

/**
* Store the directory of the activator plugin so that any other file that starts with it
* cannot be mistakenly chosen as a candidate caller file.
*
* @author Leo Fajardo
*
* @since 2.3.0
*/
$caller_file_path = fs_normalize_path( $bt[ $j ]['file'] );

foreach ( $all_plugins_paths as $plugin_path ) {
$plugin_dir = fs_normalize_path( dirname( $plugin_path ) . '/' );
if ( false !== strpos( $caller_file_path, $plugin_dir ) ) {
$plugin_dir_to_skip = $plugin_dir;

foreach ( $all_plugins_paths as $plugin_path ) {
$plugin_dir = fs_normalize_path( dirname( $plugin_path ) . '/' );
if ( false !== strpos( $caller_file_path, $plugin_dir ) ) {
$plugin_dir_to_skip = $plugin_dir;
break;
}
}

if ( ! empty( $plugin_dir_to_skip ) ) {
break;
}
}
Expand Down