admin管理员组

文章数量:1124751

How can I (easily) determine which of my wordpress sites are using a given plugin, on a Wordpress Multisite install?

Let's say I have 1,000 wordpress sites on a Wordpress Multisite install. I have 100 plugins.

For each plugin, I want to list all of the sites that are using that plugin.

In the GUI, I can only see how this can be done in about 1 million clicks. Is there a query I can run against the DB (and maybe cleanup with bash/awk/etc) that will automatically

  1. Get all of the plugins installed
  2. For each plugin, list all of the sites that use that plugin (by site-id is fine)

What's a fast way to determine all of the sites that use each of my installed plugins on Wordpress Multisite?

How can I (easily) determine which of my wordpress sites are using a given plugin, on a Wordpress Multisite install?

Let's say I have 1,000 wordpress sites on a Wordpress Multisite install. I have 100 plugins.

For each plugin, I want to list all of the sites that are using that plugin.

In the GUI, I can only see how this can be done in about 1 million clicks. Is there a query I can run against the DB (and maybe cleanup with bash/awk/etc) that will automatically

  1. Get all of the plugins installed
  2. For each plugin, list all of the sites that use that plugin (by site-id is fine)

What's a fast way to determine all of the sites that use each of my installed plugins on Wordpress Multisite?

Share Improve this question asked May 17, 2022 at 16:42 Michael AltfieldMichael Altfield 18015 bronze badges 3
  • 2 are you comfortable using WP CLI? If so there may be CLI based solutions here that don't require additional PHP/SQL – Tom J Nowell Commented May 17, 2022 at 17:13
  • wp-cli is definitely a valid answer to this question. However, for this server, I can only use software that can be installed from a secure package manager with cryptographically signed manifests (which apt provides but composer, curl, git, brew, etc do not provide) – Michael Altfield Commented May 18, 2022 at 7:30
  • So uploading or downloading wp-cli.phar as the wp cli homepage says in that environment is not an option? Even then nothing prevents you downloading the data and running WP CLI locally, and WP CLI may be a hard requirement as you mentioned 1k+ sites ( and ignoring that files and commits in git are all managed using a cryptographic hash chain ) – Tom J Nowell Commented May 18, 2022 at 13:23
Add a comment  | 

3 Answers 3

Reset to default 2

You can list the sites a plugin has been activated on in the shell using WP CLI:

sites=$(wp site list --field=url)
for url in $sites; do
    if wp plugin is-active "YOURPLUGINNAME" --url="${url}" --network; then
        echo "${url}"
    fi
done

It will print out the URL of each site on its own line that has that plugin activated.

I just stumbled upon an extension to WP-CLI that organizes the urls for each plugin queried, on Github.

So I modified the solution by @michael-altfield to get better results:

plugins=$(wp --quiet plugin list --field=name 2> /dev/null)
# List all plugins first
printf "${plugins}\n\n"
for plugin in $plugins; do
   wp plugin active-on-sites "${plugin}"
done

The following code uses wp-cli and will iterate through all plugins and it will print all sites that use each of those plugins.

sites=$(wp --quiet site list --field=url 2> /dev/null)
plugins=$(wp --quiet plugin list --field=name 2> /dev/null)
for plugin in $plugins; do
   echo $plugin;

   for url in $sites; do
      wp --quiet plugin is-active "${plugin}" --url="${url}" --network 2> /dev/null
      if [[ $? -eq 0 ]]; then

         echo -e "\t${url}"

      fi
   done
    
done

Credit to @tom-j-nowell as the above code is a modified version of his answer, but this also loops through plugins.

本文标签: How to see which sites use my installed plugins (wordpress multisite)