With all the advances made in JavaScript and newer, sleeker frameworks, it’s sometimes easy to forget that WordPress is still required on the aging jQuery library. The same goes for thousands of plugins and themes in the official WordPress directories.
For some, this may seem like a journey back to the mid-2000s, a time when JavaScript felt a lot like the Wild West. jQuery solved a lot of problems for a programming language that did not keep up with what developers needed to accomplish.
A card created four years ago by Aaron Jorbin to move WordPress to the latest 3.x branch of jQuery is finally coming to fruition. However, the WordPress development team will have to make this transition in stages, especially after such a long wait.
WordPress has fallen behind while keeping jQuery updated. For a platform that routinely suggests that users should run the latest and greatest version, it’s strange that WordPress itself has not done the same with third-party code of which it is familiar. WordPress is currently bundling jQuery version 1.12.4, a version of the library released in 2016. It is also a version that supports Internet Explorer 6, 7 and 8.
“Mostly because the focus has shifted to other / modern JavaScript libraries over the last few years,” said WordPress lead developer Andrew Ozz about why the platform has fallen behind. “The number of JavaScript developers contributing to kernel is limited, and there is a very high demand.”
In the long run, he said that a future option might be to move the WordPress admin to native (vanilla) JavaScript, which is a sentiment that is shared in the comments on his announcement post to bundle the jQuery version with Update WordPress. “This would be great,” he said, “and at the same time a very great commitment.”
Far too many themes and plugins rely on this dated version of jQuery to move faster. Although plugins could choose to overwrite the bundled version of bundled jQuery with the latest version, themes did not have such an option. The official theme guide guidelines require themes to use the core-bundled scripts, including jQuery. There is a good reason for this: for the most part, it provides compatibility with core and third-party plugins.
Now, however, it’s time to move on.
What developers and users need to know
WordPress has a three-step plan to bring jQuery up to date. The core team requires theme and plugin developers to begin testing their add-ons with the Test jQuery Updates plugin. This will help them to keep code up to date during this transition period.
The first step in this process will be to remove the jQuery Migrate 1.4.1 script from WordPress 5.5, which was released earlier today. This version of jQuery Migrate makes older code compatible and helps developers migrate to jQuery 1.9+.
This move will undoubtedly break some plugins and themes. The core team has made the Enable jQuery Migrate Helper plugin available to end users. “It is intended to be implemented in production on sites that are experiencing jQuery-related issues after upgrading to 5.5,” Ozz said. “It works by re-enabling jQuery Migrate and by displaying the warnings about using outdated / deprecated jQuery features for site admin.”
The long-term goal is to get developers to update their extensions. In the meantime, this plugin should hide some of the issues.
Ozz said the biggest thing developers need to do right now is make sure they test their extensions against WordPress 5.5. “Ideally, pay more attention to all the old jQuery-based scripts and confirm that they are still working as expected,” he continued. “In almost all cases, the fixes are trivial.”
Beyond WordPress 5.5, things will start to take shape. The tentative plan is to upgrade to the latest version of jQuery and add the latest version of jQuery Migrate as part of the WordPress 5.6 release.
“Again, Migrate will be used to help update jQuery-based scripts, as well as ‘backward compatibility’ fix ‘while updating plugins and themes,’ said Ozz.” The version of Migrate in WordPress 5.6 will be different , because it matches the latest jQuery version. It will serve the same purpose as when it was first added, but now it will help update core, plugins and themes from jQuery 1.12.4 to 3.5.1 (or letter). “
The third leg of the process will be to uninstall jQuery Migrate from WordPress again. This change is tentatively planned for WordPress 5.7, which will not be released until 202. The ultimate goal is to remove the reliance on Migration and send the latest version of jQuery up to one day – maybe far in the future – there may no longer be a need to bundle this with WordPress at all.
“According to the best practices and recommendations of the jQuery team, Migrate should be used as a helper tool, and not as a permanent solution for backward compatibility,” Ozz said. “Ideally, WordPress would be able to do this.”