One of the benefits of using WordPress to run your website is that it comes with a rich ecosystem of plugins, making it a rich ecosystem for all kinds of purposes. However, WordPress library conflicts can happen when using more than one plugin on any given site.
One common example is when multiple plugins try to load different versions of the same code library. If that library is required by more than one plugin, you can’t reliably know that the loaded library is the one that is needed for your site’s functionality.
Detecting and resolving a library conflict on your WordPress site is important for lots of reasons. Most importantly, membership sites should be aware of library conflicts that can block the initial payment at checkout or affect incoming recurring transactions.
In this post, we’ll walk you through how to fix a library conflict in WordPress.
What is a Library Conflict?
A code library is a pre-written collection of code that helps to streamline the development of new products and features. For example, payment gateways like Stripe help plugin developers to quickly integrate with their platform by providing a free code library.
As a best practice, plugin authors add a library to their plugin by copying all of the code that makes up the library and inserting it directly into the plugin files. But not every plugin developer follows best practices.
Code Library Updates
Just as we update websites and plugins over time, libraries also use updates to fix issues and add new features. To take advantage of these changes, plugin developers need to overwrite the old library files (that they have already added to their plugin) with the newly updated plugin files.
In cases where the plugin is already working as intended with the old version of the library, however, plugin developers may decide not to update to newer library versions. As they say, “if it ain’t broke, don’t fix it.”
Most of the time, having a plugin that uses an old version of a library is not a problem, but issues can arise when multiple plugins on the same website are trying to use the same library. We call this a WordPress library conflict.
Because libraries can only be declared once, the first plugin to load the library wins. Instead of being able to load their own library, this requirement forces all other plugins on the website to share that single library.
Allowing a single plugin to load its version of a library may not always be a problem, especially if the plugin has an up-to-date version of the library.
However, if the plugin has an outdated version of the library and other plugins rely on newer versions of the library, a plugin conflict can occur.
For example, we recently updated PMPro’s Stripe gateway to collect payment via Apple Pay. Older versions of the Stripe library do not support Apple Pay. To add Apple Pay support, PMPro needed to update its version of the Stripe library to the latest version.
Although this new feature usually worked as expected, checkouts on some websites would fail if another plugin on the website had loaded an old version of the Stripe library. If that older version did not include Apple Pay support, PMPro could not load an up-to-date version. So Apple Pay couldn’t work.
Want to learn more about Stripe checkout issues? Check out our troubleshooting guide.
Detecting a WordPress Library Conflict
In the most recent version of PMPro, the “Paid Memberships Pro” section of Site Health has been updated to list all plugins that have loaded a library before PMPro was able to load its version of the library—as well as the library version that was loaded by each plugin.
This change allows site owners to easily identify which plugin is loading an outdated version of a library. Today, you can check your Site Health in order to address conflicts as quickly as possible.
Resolving a Library Conflict as a Site Owner
- If your site is running into issues as a result of another plugin loading an outdated version of a library, the first step is to update the conflicting plugin. If the plugin developer has updated the library code in a recent version of their plugin, then updating the plugin may resolve the library conflict.
- If updating does not resolve the issue or there is not an update available for the conflicting plugin, then the best long-term solution is to reach out to the plugin author to notify them of the conflict.
This not only may resolve the conflict on your website; It could also resolve issues on any other website using the conflicting plugin. At the end of this post, we added a few suggestions for plugin authors to resolve library conflicts caused by their plugin.
Bu what do you do when the plugin author does not respond? Or what if you need an immediate fix for the plugin conflict? Here’s a code recipe that forces the PMPro version of a library to load before any other plugin has a chance to load their versions:
While this code is written to load the Stripe library, it can be modified to load any other library used by PMPro. To use the recipe, make sure you add it to a new file in the
wp-content/mu-plugins/ folder of your website to ensure that it runs before all other plugins.
Resolving a Library Conflict as a WordPress Plugin Developer
Are you are a plugin developer that has conflicts with PMPro on a customer’s site? If so, we have two suggestions for updating your plugin so that it doesn’t conflict with PMPro. Bonus: these updates also fix conflicts with any other plugin that shares the library that you are loading.
- Update the library included in your plugin. The main benefit to this approach is that it is quick to implement. However, this may only be a temporary fix, as conflicts can reappear if the library is not kept up to date over time.
- Only load a library when it’s needed. This is a more permanent solution. In the specific case of PMPro, the checkout page is where most library conflicts tend to occur—and it typically happens with plugins that blindly load their outdated libraries on every page. With this in mind, if your plugin does not actively use a library on the PMPro checkout page, we kindly ask that it does not load that library in order to avoid these unnecessary library conflicts.
Check out the WordPress plugin developer best practices resource for more advice on how to build a plugin with compatibility in mind.
Closing Thoughts to Remember
Good plugin developers try to avoid conflicts. However, it’s impossible to prevent 100% of them. So, learning how to figure this out on your own will help you take care of your own site—and help you assist developers in fixing conflicts more quickly as well.
Download the free ebook: Get 29 insights and ‘aha moments’ for new or veteran membership site business owners. Use these nuggets of wisdom to inspire or challenge you.