Skip to content

Commit

Permalink
Allow the flexibility of client-mu-plugins to be used where it exists
Browse files Browse the repository at this point in the history
  • Loading branch information
srtfisher committed Jul 24, 2023
1 parent 1d6d3b2 commit 63856a8
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions src/class-wp-plugin-loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,24 @@ protected function load_plugins(): void {
WP_CONTENT_DIR . '/plugins',
];

// Use the client mu-plugins directory if it exists and the constant
// from VIP's mu-plugins is defined.
$client_mu_plugins_dir = defined( 'WPCOM_VIP_CLIENT_MU_PLUGIN_DIR' )
? WPCOM_VIP_CLIENT_MU_PLUGIN_DIR
: ( is_dir( WP_CONTENT_DIR . '/client-mu-plugins' ) ? WP_CONTENT_DIR . '/client-mu-plugins' : null );

/**
* The client-mu-plugins directory should always be used if the
* directory exists. If the WPCOM_VIP_CLIENT_MU_PLUGIN_DIR constant is
* defined, then we won't add the mu-plugins directory to the list of
* folders. Otherwise, we will add the mu-plugins directory to the list
* of folders.
*/
if ( defined( 'WPCOM_VIP_CLIENT_MU_PLUGIN_DIR' ) ) {
$folders[] = WPCOM_VIP_CLIENT_MU_PLUGIN_DIR;
} else {
// Add the mu-plugins directory if the client mu-plugins directory
// does not exist. We wouldn't want to attempt to load from VIP's
// mu-plugins directory if the client mu-plugins directory exists.
if ( $client_mu_plugins_dir ) {
$folders[] = WP_CONTENT_DIR . '/client-mu-plugins';
}

$folders[] = WP_CONTENT_DIR . '/mu-plugins';
}

Expand Down Expand Up @@ -153,10 +163,10 @@ protected function load_plugins(): void {
];

// Include the client mu-plugins directory if it exists.
if ( defined( 'WPCOM_VIP_CLIENT_MU_PLUGIN_DIR' ) ) {
$paths[] = WPCOM_VIP_CLIENT_MU_PLUGIN_DIR . "/$sanitized_plugin/$sanitized_plugin.php";
$paths[] = WPCOM_VIP_CLIENT_MU_PLUGIN_DIR . "/$sanitized_plugin/plugin.php";
$paths[] = WPCOM_VIP_CLIENT_MU_PLUGIN_DIR . "/$sanitized_plugin.php";
if ( $client_mu_plugins_dir ) {
$paths[] = "$client_mu_plugins_dir/$sanitized_plugin/$sanitized_plugin.php";
$paths[] = "$client_mu_plugins_dir/$sanitized_plugin/plugin.php";
$paths[] = "$client_mu_plugins_dir/$sanitized_plugin.php";
}

foreach ( $paths as $path ) {
Expand Down

0 comments on commit 63856a8

Please sign in to comment.