Skip to content

Commit 5f67881

Browse files
Copilotswissspidy
andcommitted
Add support for listing mu-plugins from subfolders
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
1 parent 0a68837 commit 5f67881

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

features/plugin.feature

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -751,6 +751,31 @@ Feature: Manage WordPress plugins
751751
| name | title | description |
752752
| test-mu | Test mu-plugin | Test mu-plugin description |
753753

754+
Scenario: Listing mu-plugins should include plugins from subfolders
755+
Given a WP install
756+
And a wp-content/mu-plugins/test-mu-root.php file:
757+
"""
758+
<?php
759+
// Plugin Name: Test MU Root
760+
// Description: Test mu-plugin in root
761+
// Version: 1.0.0
762+
"""
763+
And a wp-content/mu-plugins/subfolder-plugin/subfolder-plugin.php file:
764+
"""
765+
<?php
766+
/**
767+
* Plugin Name: Subfolder MU Plugin
768+
* Description: Test mu-plugin in subfolder
769+
* Version: 2.0.0
770+
*/
771+
"""
772+
773+
When I run `wp plugin list --status=must-use --fields=name,title,version`
774+
Then STDOUT should be a table containing rows:
775+
| name | title | version |
776+
| test-mu-root | Test MU Root | 1.0.0 |
777+
| subfolder-plugin | Subfolder MU Plugin | 2.0.0 |
778+
754779
@require-wp-5.5
755780
Scenario: Listing plugins should include name and auto_update
756781
Given a WP install

src/Plugin_Command.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,20 @@ protected function status_single( $args ) {
239239
protected function get_all_items() {
240240
$items = $this->get_item_list();
241241

242-
foreach ( get_mu_plugins() as $file => $mu_plugin ) {
242+
// Get all mu-plugins including those in subfolders.
243+
$mu_plugins = get_mu_plugins();
244+
if ( defined( 'WPMU_PLUGIN_DIR' ) ) {
245+
$mu_plugins_subfolder = get_plugins( '/../' . basename( WPMU_PLUGIN_DIR ) );
246+
// Merge subfolder plugins with the main mu-plugins list.
247+
foreach ( $mu_plugins_subfolder as $file => $plugin_data ) {
248+
// Only add if not already in the list (avoid duplicates from root-level plugins).
249+
if ( ! isset( $mu_plugins[ $file ] ) ) {
250+
$mu_plugins[ $file ] = $plugin_data;
251+
}
252+
}
253+
}
254+
255+
foreach ( $mu_plugins as $file => $mu_plugin ) {
243256
$mu_version = '';
244257
if ( ! empty( $mu_plugin['Version'] ) ) {
245258
$mu_version = $mu_plugin['Version'];

0 commit comments

Comments
 (0)