Skip to content

Commit 81943ba

Browse files
Copilotswissspidy
andcommitted
Add detailed comments explaining active_plugins structure
Co-authored-by: swissspidy <[email protected]>
1 parent b892b03 commit 81943ba

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/Plugin_Command.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1376,22 +1376,25 @@ public function is_active( $args, $assoc_args ) {
13761376
if ( ! $plugin ) {
13771377
// Plugin not found via fetcher, but it might still be in active_plugins option
13781378
// Check if it's in the active_plugins list
1379-
$input_name = $args[0];
1379+
$input_name = $args[0];
1380+
// For network plugins: active_sitewide_plugins is an array where keys are plugin files and values are timestamps
1381+
// For regular plugins: active_plugins is an array of plugin file paths
13801382
$active_plugins = $network_wide ? get_site_option( 'active_sitewide_plugins', [] ) : get_option( 'active_plugins', [] );
13811383

13821384
// Ensure we have an array to work with
13831385
if ( ! is_array( $active_plugins ) ) {
13841386
$active_plugins = [];
13851387
}
13861388

1387-
// For network-wide plugins, the array is keyed differently
1389+
// For network-wide plugins, extract the plugin files from the keys
13881390
if ( $network_wide ) {
13891391
$active_plugin_files = array_keys( $active_plugins );
13901392
} else {
13911393
$active_plugin_files = $active_plugins;
13921394
}
13931395

1394-
// Try to find a matching plugin file in active_plugins
1396+
// Try to find a matching plugin file in active_plugins using the same logic as the fetcher
1397+
// This matches: exact file name, "name.php", or directory name
13951398
$found_in_active = '';
13961399
foreach ( $active_plugin_files as $plugin_file ) {
13971400
// Ensure plugin_file is a string
@@ -1400,6 +1403,7 @@ public function is_active( $args, $assoc_args ) {
14001403
}
14011404

14021405
// Check if the input matches the plugin file in various ways
1406+
// This mirrors the logic in WP_CLI\Fetchers\Plugin::get()
14031407
if ( "$input_name.php" === $plugin_file ||
14041408
$plugin_file === $input_name ||
14051409
( dirname( $plugin_file ) === $input_name && '.' !== $input_name ) ) {

0 commit comments

Comments
 (0)