How I Would Solve Plugin Dependencies

lol, I wouldn’t1.


1. If I absolutely had to, I wouldn’t do it the same as Ryan.

WordPress isn’t (and will never be) Linux

ZYpp is the dependency solver used by OpenSUSE (and its PHP port in Composer), it was born of the need to solve complex dependency trees. The good news is, WordPress doesn’t have the same problem, and we shouldn’t create that problem for ourselves.

One of the most common-yet-complex issues is determining how to handle different version requirements by different packages. If My Amazing Plugin requires WP-API 1.9, but Your Wonderful Plugin requires WP-API 2.0, we have a problem. There are two ways to solve it – Windows solves it by installing multiple versions of the dependency, and loading the correct version for each package. This isn’t a particularly viable option in PHP, because trying to load two different versions of the same code in the same process is not my idea of a fun time.

The second option, which ZYpp solves, is to try and find a mutually compatible version of the dependency that each plugin can use. The biggest problem with this method is that it can’t always find a solution. If there’s no compatible way of installing the libraries, it has to throw back to the user to make the decision. This isn’t a viable option, as 99.999*% worth of users wouldn’t be able to tell the difference between WP-API versions 1.9 and 2.0, and nor should they.

But there’s a third option.

Technical Debt as a Service

Code libraries are, by their nature, developer facing. A user never really needs to know that they exist, in the same way that they don’t need to know about WP_Query. In WordPress Core, we strive for (and often achieve) 100% backwards compatibility between major versions. If we were going to implement plugin dependencies, I would make it a requirement that the code libraries shoulder the same burden: don’t make a user choose between upgrades, just always keep the code backwards compatible. If you need to make architectural changes, include a backwards compatible shim to keep things working nicely.

This intentionally moves the burden of upgrading to the developer, rather than the end user.

What Version?

If we’re going to require library developers to maintain backwards compatibility, we can do away with version requirements (and thus, removing the need for a dependency solver). If a plugin needs a library, it can just specify the library slug.

Better Living Through Auto Updates

If we were to implement plugin dependencies, I think it’d be a great place to introduce auto updates being enable by default. There’s no existing architecture for us to take into account, so we can have this use the current WordPress best practices. On top of that, it’s a step towards enabling auto updates for all Core releases, and it encourages developers to create backwards compatible libraries, because their library will almost certainly be updated before a plugin using it is.

Let’s Wrap This Up

I’m still not convinced plugin dependencies is a good thing to put in Core – it introduces significant complexities to plugin updates, as well as adding another dependency on WordPress.org to Core. But it’s definitely a conversation worth having.

4 Replies to “How I Would Solve Plugin Dependencies”

  1. Sorry to be posting it on your website. How do I know you are an expert in database’m doing this query.
    In the ten websites that I manage I’m finding problems in the database with the new version 4.2.2. (upgrade) .
    I can not access the administrative area (wp-admin) because I have no access to the database.
    In several tests I did, I notice that access the cpanel occurs normally.
    In some of the websites, I can access the posts but not the pages.
    In this latest update of whm mysql has been updated to version 5.5.42-cll.

  2. the debug results:

    [05-Jun-2015 20:19:43 UTC] PHP Warning: mysql_connect(): Headers and client library minor version mismatch. Headers:50542 Library:50623 in /home/website/public_html/wp-includes/wp-db.php on line 1461
    [05-Jun-2015 20:19:43 UTC] PHP Notice: mysql_connect(): SQL safe mode in effect – ignoring host/user/password information in /home/website/public_html/wp-includes/wp-db.php on line 1461
    [05-Jun-2015 20:19:43 UTC] PHP Warning: mysql_connect(): Access denied for user ‘website’@’localhost’ (using password: NO) in /home/website/public_html/wp-includes/wp-db.php on line 1461

Comments are closed.