Yet Another Plugin Dependencies Discussion, Two Proposals This Time – WP Tavern


It has been over 9 years because the late Alex Mills opened a ticket on WordPress Trac titled Plugin Dependencies (Yet Another Plugin Dependencies Ticket). It isn’t the oldest of comparable characteristic requests, however it’s nonetheless open. Most predecessors have been closed with the “wontfix” label, which is often the ultimate nail within the coffin of fine and dangerous concepts alike.

The objective of the ticket is to create a system that permits one plugin to require a number of others to function. Dependencies are nothing new within the programming world. Composer, the usual PHP bundle supervisor, is 2 weeks shy of turning 10 years previous. On the JavaScript finish, npm has been round for 12 years, and WordPress has closely embraced it for core code.

Nonetheless, these are developer instruments. WordPress was constructed for customers, and resolving plugin dependencies would wish to occur from inside the person interface.

Mills wrote within the ticket:

It’s been a couple of years since we checked out plugin dependencies, and this nonetheless appears to be a characteristic folks actually, actually need, particularly for shared performance that isn’t a plugin in itself. For instance, a PHP library that isn’t widespread sufficient to be in core however is widespread sufficient to be bundled in a number of plugins.

That assertion is maybe much more related right this moment. Prior to now decade, many plugins have grown their very own ecosystems of add-on plugins. The accountability of creating positive dependencies are put in has usually fallen on the shoulders of end-users. Builders have provide you with in-house options to ease that burden, and the TGM Plugin Activation script has turn into the de facto normal.

Counting on dependencies is sort of a given in any plugin challenge, at the very least enjoying a component within the common construct instruments setup. It’s most likely secure to say that extra WordPress plugin builders are snug coding in an surroundings that requires third-party code right this moment than they might have been in WordPress’s childhood.

For a platform that has been working onerous to modernize itself, resolving plugin dependencies is like touring in a rocket ship to the Wild West.

The concept shouldn’t be with out precedent within the WordPress world. Whereas it’s a much less advanced case, WordPress robotically downloads and installs the guardian when putting in a toddler theme from the listing.

Many arguments for a plugin dependency system fall below the add-on state of affairs. The obvious use case is WooCommerce and the handfuls upon dozens of extensions written for it.

Nonetheless, the opposite state of affairs that may attain deeper into how builders construct on prime of WordPress is the inclusion of frameworks and libraries. Proper now, plugin authors should bundle third-party code inside their tasks and ensure it doesn’t get loaded if already bundled inside a completely separate plugin.

Code reuse is among the cornerstones of programming. At the moment, there isn’t a normal for bundling code libraries or scripts. And, the WordPress plugin directory disallows new frameworks and related libraries.

For transparency, I’ve at the very least a dozen tasks that match below this class, packages sitting round that others might use. So, I at the very least have some pores and skin within the recreation, and I’m positive many others are in the identical boat.

There are two pull requests on the WordPress GitHub repository for a plugin dependency system. There’s additionally a Google Docs file that outlines both proposals in detail.

Every asks builders to outline dependencies through a plugin header. The next is an instance that might require WooCommerce and Gutenberg:

<?php
/**
 * Plugin Identify: Pattern
 * Requires Plugins: woocommerce, gutenberg
 */

Each of the approaches are related. From the person viewpoint, they might:

  • Present an admin discover that there are dependencies to put in.
  • Disallow deletion or deactivation of plugins with out deleting or deactivating their required plugins.
  • Output a message within the plugin card on the handle plugins display screen.

The first implementation is by Ari Stathopoulos. It creates an “activation queue” that might solely activate a plugin as soon as customers have activated the required plugins. It additionally permits customers to cancel activation requests.

Manage plugins screen in WordPress that shows admin notices to install dependent plugins and similar messaging in the plugin card.
Notices to activate dependencies.

Andy Fragen’s solution creates a brand new “Dependencies” tab on the plugin administration display screen. This strategy would robotically deactivate any plugin with unmet dependencies and inform the person through an admin discover.

He has additionally launched the Plugin Dependencies Tab challenge individually on GitHub.

Plugin dependencies screen in WordPress for activating and installing required plugins.
Plugin dependencies tab.

There are nonetheless some sensible issues with each. Particularly, what occurs when there’s a battle between supported variations? The present proposals go away it as much as the plugins to not break something on the person’s finish.

Which may be the least confidence-inspiring piece of all of this. Nonetheless, it’s seemingly probably the most sensible route. Plus, WordPress doesn’t remedy model conflicts in its present Wild West system.

A dependency resolution is also a possibility for extra code modernization. Seeing extra builders embracing options like interfaces (contracts) can be welcome. Coding with dependents in thoughts means pondering by architectural issues in a different way than when any given challenge was a standalone plugin.


Leave a Reply

Your email address will not be published.