If you are running WordPress Multisite, this code will list the plugins active on each of the blogs.
I use WordPress Multisite for my development environment. It is hosted by my chosen hosting company. Unlike a local environment, clients can access this installation. Creating a new site is trivial.
Every now and again I find a very useful piece of code for Multisite. When searching about how to list the plugins in use on the sub sites I found that someone had asked that exact question on StackExchange. Furthermore, it had an answer with some code that was ready to go.
I copied it into a text file, with the required plugin header info and network activated it. Now, on the root site Dashboard it presents a list of the active sites and the active plugins on each site.
As my development site runs with WP_DEBUG set to true I saw a warning message when I looked at debug.log:
“PHP Warning: Missing argument 2 for wpdb::prepare().”
The original code uses ‘$wpdb->prepare()‘ but it did not have any arguments, making prepare() unnecessary. So, after reading about the warning message, I removed the function call. In my opinion, the two dynamic portions of the call ($wpdb->blogs and $wpdb->siteid) are coming from WordPress core and can be trusted.
I also enhanced the code to display the plugin name instead of its directory. It does require that each plugin file must be parsed by WordPress but, as the code is only accessed from the root site Dashboard, which is only accessible by the Super Admin, this overhead is acceptable.