Getting Your WordPress Plugins and Themes Ready for PHP 8

On Monday, WordPress core contributor Jonathan Desrosiers published a detailed post on the Make WordPress Core blog about the upcoming PHP 8 release and how it affects WordPress.

PHP 8 Is Coming

Scheduled for release on November 26, 2020, PHP 8 is the next major update to our favorite scripting language. While previous PHP releases have not had too much of an adverse effect on the WordPress ecosystem, this update has some breaking changes that could affect backward compatibility. It should also be noted that many features that were deprecated in PHP 7.x will now be removed in PHP 8.

The Status of WordPress Core

In his post, Desrosiers highlights the work that has been done to keep the core software up to date. “WordPress Core aims to be compatible with PHP 8.0 in the 5.6 release (currently scheduled for December 8, 2020),” he wrote.

However, this does not mean it is safe to upgrade to PHP 8 when WordPress 5.6 is released. WordPress is rarely run just on its own and usually relies on at least one theme and a collection of plugins to function as a blog or web site. As such, he points out, “The state of PHP 8 support within the broader ecosystem (plugins, themes, etc.) is impossible to know. For that reason, WordPress 5.6 should be considered ‘beta compatible’ with PHP 8.

What this means, essentially, is that until most major themes and plugins are PHP 8 compatible, WordPress cannot be considered fully compatible.

Understand How PHP 8 Could Affect Your Plugin or Theme

Companies like Yoast have been preparing for this for a little while now. In late October, Yoast CTO Omar Reiss, along with fellow contributors Juliette Reinders Folmer, maintainer of the WordPress Coding Standards Sniffs for PHPCS, and Yoast DevOps manager Herre Groen, compiled and published a comprehensive WordPress/PHP 8 compatibility report.

While I highly recommend you take the time to read through the entire report, it does outline the main reason that the PHP 8 upgrade could have such a drastic effect on large WordPress sites, especially the plugin and theme ecosystem.

“However, PHP 7.* versions have seen a far larger set of deprecations than previous versions of PHP. Where PHP 5.6 to PHP 7 was a relatively simple migration, going from 7.x to 8 could be very painful, especially for very old codebases, like WordPress and many of the plugins that are available for it. For well-typed codebases or codebases which have stayed up-to-date with the latest PHP versions, there isn’t a big problem.”

As a maintainer of a few plugins, some built on code dating back eight years, it is worrisome that this upgrade could cause sites to break.

PHPCompatibility repository on GitHub.
PHPCompatibility repository.

How to Prepare Yourself

I asked Reiss and Folmer what plugin and theme developers can do to get ready, and they shared some pointers.

First and foremost, developers should inform themselves about the changes coming in PHP 8: read the Make post about PHP 8, read the Yoast PHP8 Compatibility report, read the “Migrating from PHP 7.4 to PHP 8.0” section of the PHP manual, and potentially dig deeper by reading the UPGRADING doc in the PHP 8 branch and the RFCs for PHP 8.

Some available tools can be used to help look for incompatibilities:

  • Run PHP lint on PHP 8 over their code, either via the  php -l command (making sure to iterate over all files) or by using PHP Parallel Lint.
  • Run PHPCompatibility over their code: it should be noted that nearly all PHP 8 related sniffs are in the as-of-yet-not-yet-released version 10.0.0 of PHPCompatibility, so people would need to use the develop branch or via Composer dev-develop for the time being, until version 10.0.0 is released.
  • Run the unit/integration tests for the plugin or theme on PHP 8 and fix anything which that comes up as an error. This will often mean that the test suite first needs to be made compatible with PHPUnit 9.3+. The PHPUnit Polyfills package and WP Test Utils package (both published under the Yoast GitHub organization) can help with this. It’s also important to note a considerable test coverage is needed to make this reliable.
  • Run the WordPress unit tests and WordPress e2e tests with your plugin activated, and fix any issues that arise.
  • Check whether the (strict) code coverage of said tests is high enough and if not, add more tests, making sure both happy and unhappy paths are covered.
  • If there are no tests, test everything manually, focusing especially on the “unhappy paths”, and expect to receive bug reports for the foreseeable future. At the same time, this is probably a good time to look into implementing unit/integration tests for your plugin or theme.

There Is Still Time, But It Is Running Out

As Desrosiers pointed out in the Make post, WordPress is only officially aiming to be PHP 8 ready by the time 5.6 is released in early December. Potentially, this means that many WordPress-focused hosting companies will only consider offering upgrades to their customers once WordPress core is compatible. So as plugin and theme developers, we have some time to test our products and get them ready, but that window is closing fast.

Fortunately for us, the knowledge and tools to get up to date are out there. We merely need to put them into action.

10

10 responses to “Getting Your WordPress Plugins and Themes Ready for PHP 8”

  1. Pousada Nerd says:

    I’m afraid to upgrade to the same degree I’m excited. While I think my plugins will work well, my theme is a bit outdated but it’s so fast and clean that I don’t want to change.

    Not updating for a long time can cause security issues?

    Maybe I’ll wait until things are settled and try the update.

    Hope everything works fine and we get better performance with this new version. Thank you for the great and informative article.

    See ya
    Marcos Mariano

    Report

    • Francois says:

      Yes, not updating WordPress is a security issue, not updating PHP is another thing. Next WordPress versions will stay compliant with PHP 7 for a while. So you can stay as safe as possible with php7. Plugins and themes developers will have plenty if time to update their products before PHP8 became the minimal requierment. Be careful with your themes deprecations, it become dangerous with the time..

      Report

  2. Monty Mezzi says:

    I am often obsessive to the point of being reckless when it comes to keeping software up-to-date. However, I’ll hold off on upgrading to PHP8 for at least six months considering that WordPress sites won’t really see a massive speed boost by upgrading from 7.4.x to 8.

    Report

  3. Dietrich says:

    I just recently upgraded to 7.4 and now there’s 8.0 already?

    I just can’t seem to keep up with all the major upgrades happening recently.

    Report

  4. A smart movement will be to upgrade at the begin of the next year ( Jan, Feb, etc ). Personally, I never update my sites or my client(s) sites with betas, until everything is stable. Ofc, I’ll do an install to see the features and see if there is any problem ( I can find ).

    Report

  5. Morgan says:

    We are happy if php 8 bring lot of performance improvement. It would help me who run small business using WordPress WooCommerce on shared hosting. And next year would be the big challenge when google will implementing web vitals. Hope the compatibility theme and plugin and of course hosting company with php 8 would be ready as soon as posible.

    Report

  6. Speed wise what are the benefits of moving to PHP 8?

    Report

    • Without having run any benchmarks yet, I’d say RAM/memory consumption. Depending on your usage, you might see an improvement.

      For example, for one of my SaaS’s, I’m running arount 10 nightly CRON jobs, very memory intensive (and slow, as they use cURL). I’m fine with it because it runs at night. I know that, by using PHP 8’s JIT, I would definitely see an up to 20% RAM consumption decrease, which is really good.

      Coupling this with a few more updates I’m planning, such as Apache 2.4 and full HTTP/2 cURL, I expect my 10 CRON jobs to be ready in half the time (which is around 10 minutes right now).

      Report

  7. Atul Host says:

    Thanks for the read, I was just checking out PHP8 with the current version of WordPress 5.5.3. The backend worked, although there were several issues with themes and plugins. Some hosting companies already offering PHP8, but WordPress is still not ready for that. So do not upgrade quickly even after WordPress releases 5.6.

    Report

  8. Erika says:

    Your link for “Migrating from PHP 7.4 to PHP 8.0” is currently linking to the WP Make link. I think you meant to link to this: php.net/manual/en/migration80.php

    Report

Newsletter

Subscribe Via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

%d bloggers like this: