How would you require and automatically download dependent plugins?

I would encourage against this, but I understand what you’re trying to do and do something similar myself.

How I do it

I build themes that depend on plugins, plugins that depend on plugins, and plugins that depend on plugins that depend on other plugins. If I’m controlling both sides of the development, I do things in two pieces …

In the plugin that will be required by something else:

add_filter( 'my-cool-plugin-name-installed', '__return_true' );

In the plugin/theme that will require the other plugin:

if ( ! apply_filters( 'my-cool-plugin-name-installed', false ) )
    add_action( 'admin_notices', 'my-cool-plugin-name_not_installed' );

Then I add a bright “Please install my super-cool plugin” notice to the top of the admin screen with a link to the download page.

This gives me a surefire way to check that my dependencies exist and are installed. If the plugin is installed but not activated, the warning still shows up.

Another way

Another option has already been recommended by @tollmanz. I won’t copy-paste his solution, but checking for the existence of a core function of your dependent plugin is a great way to make sure it’s there.

Once again, if the plugin is installed but inactive, this route will only detect if it’s active.

Why I do things this way

First of all, I don’t like other people’s tools downloading extra stuff to my site. So I don’t force that paradigm on other users. Instead, I prompt them to download the extra code and point them in the right direction. A cleaner way would be to tie in with the automated installer so they could pull down the plugin with a single click.

Also, several users of my code are on servers where they can’t use the one-click installer (or automated downloads at all). They have to FTP plugins to install them, so a silent download-and-activate-a-dependency system wouldn’t work at all.

Finally, if you’re working with someone else’s code, you have 0 control over when they ship new releases, if they introduce bugs, or if they’re hacked. So don’t automatically install code for which you can’t claim responsibility.

Leave a Comment