How to Enable Plugin Dependencies for Your WordPress Plugins

A timeglass and some dominos.

Plugin authors have long wished for a way to make a WordPress.org plugin depend on another. WordPress 6.5 introduced plugin dependencies, which made this possible for .org plugins.

In this tutorial, I’ll explain how to set plugin dependencies and how it will look to the end user.

Setting a dependency

To set a dependency, just use the Requires Plugins header in your main plugin file.

<?php
/**
 * Plugin Name: Reorder Terms
 * Plugin URI: https://wordpress.org/plugins/reorder-terms/
 * Description: Reorder Terms
 * Version: 1.1.1
 * Author: Ronald Huereca
 * Author URI:
 * License: GPL2
 * Text Domain: reorder-terms
 * Domain Path: /languages
 * Requires Plugins: metronet-reorder-posts
 */
Code language: PHP (php)

You can also specify multiple WordPress.org plugin slugs.

* Requires Plugins: metronet-reorder-posts, plugin-slug-2, plugin-slug-3Code language: PHP (php)

If the required plugin isn’t installed, the plugin will display a warning when it is viewed in the plugin’s list.

Plugin Activation Warning for a Parent Plugin Needed
Plugin Row Requiring a Plugin for Activation

In the event that a dependent plugin is active before its parent can be installed, you’ll see an error like the one below:

A Red Requires Banner When a Plugin is Activated Without its Parent Plugin
A Red Banner When a Plugin is Activated Without its Parent Plugin

You’ll also see a warning at the top of the plugins page.

Banner at the Top of the Plugins Screen With a Warning About Missing Plugins
Banner at the Top of the Plugins Screen With a Warning About Missing Plugins

When a parent plugin and a dependent plugin are both active, you’ll find that you can’t deactivate the parent plugin. This is designed so that nothing breaks should the parent plugin accidentally be activated.

Warning Saying A Parent Plugin Can't Be Deactivated
Warning Saying A Parent Plugin Can’t Be Deactivated

Here’s how the plugin would look in the plugin search screen if a parent plugin isn’t installed.

A Warning in the Plugin Search Screen of a Missing Plugin
A Warning in the Plugin Search Screen of a Missing Plugin

Conclusion

Dependencies are a neat way for a child to reference its parent plugin. For more on dependencies, please read the developer notes, as they cover many “what-if” scenarios.

If you have any questions, please comment below or @me on X.

Like this tutorial? There's more like it. Subscribe today!

Name(Required)

Ronald Huereca
By: Ronald Huereca
Published On: on June 13, 2024

Ronald Huereca founded DLX Plugins in 2022 with the goal of providing deluxe plugins available for download. Find out more about DLX Plugins, check out some tutorials, and check out our plugins.

Leave Your Valuable Feedback

Your email address will not be published. Required fields are marked *

Shopping Cart
  • Your cart is empty.
Scroll to Top