[wp-trac] [WordPress Trac] #57278: Add filter to allow filtering of the must-use plugins list in the admin
WordPress Trac
noreply at wordpress.org
Fri Mar 24 16:58:02 UTC 2023
#57278: Add filter to allow filtering of the must-use plugins list in the admin
-------------------------------------------------+-------------------------
Reporter: nateallen | Owner: (none)
Type: enhancement | Status: new
Priority: normal | Milestone: Future
| Release
Component: Plugins | Version: 3.0
Severity: normal | Resolution:
Keywords: has-patch has-unit-tests needs- | Focuses:
testing has-testing-info | administration
-------------------------------------------------+-------------------------
Changes (by nateallen):
* keywords: has-patch has-unit-tests needs-testing => has-patch has-unit-
tests needs-testing has-testing-info
Comment:
The failures with the PR were caused by `null` being passed to `strlen` in
`class-wp-plugins-list-table.php`, which results in a TypeError in PHP 8.
I added an `isset` check before calling `strlen` which fixes that issue.
Here are testing instructions for the new `plugins_list` filter:
**To reproduce the issue:**
1. Add a normal plugin to the `mu-plugins` directory (like Jetpack)
2. Add the `mu-loader.php` file to the `mu-plugins` directory. See code at
the bottom of this comment
3. In the admin, go to Plugins > Installed Plugins and click on the "Must-
Use" link
4. Observe that the `mu-loader.php` is listed, but the plugin is not
**To test the fix:**
1. Apply the patch attached to this ticket.
2. Ensure a plugin and `mu-loader.php` are in `mu-plugins` as before
3. Use the new `plugins_list` filter to add the plugin to the list. See
example code at the bottom of this comment.
4. In the admin, go to Plugins > Installed Plugins and click on the "Must-
Use" link
5. Observe that the plugin is now listed and `mu-loader.php` is removed
----
**Code used for testing:**
**The must-use autoloader example**
Save this code to an `mu-loader.php` file in your `mu-plugins` directory
{{{#!php
<?php
require_once ABSPATH . 'wp-admin/includes/plugin.php';
foreach ( glob( WPMU_PLUGIN_DIR . '/*/*.php' ) as $file ) {
$plugin_data = get_plugin_data( $file, false, false );
if ( empty( $plugin_data['Name'] ) ) {
continue;
}
include_once $file;
}
}}}
**Using the new `plugins_list` filter**
Place this code in your theme's `functions.php` file
{{{#!php
<?php
function custom_mu_plugin_filter( $mu_plugins ) {
unset( $mu_plugins['mustuse']['mu-loader.php'] );
foreach ( glob( WPMU_PLUGIN_DIR . '/*/*.php' ) as $file ) {
$plugin_data = get_plugin_data( $file, false, false );
if ( empty( $plugin_data['Name'] ) ) {
continue;
}
$mu_plugins['mustuse'][ basename( $file ) ] =
$plugin_data;
}
return $mu_plugins;
}
add_filter( 'plugins_list', 'custom_mu_plugin_filter' );
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/57278#comment:14>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list