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. It’s also important to note a considerable test coverage is needed to make this reliable.
  • 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.
  • 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.

Is WP Notify the Silver Bullet WordPress Needs to End Admin Notification Spam?

A short while ago, Justin Tadlock posted an article titled Are Plugin Authors to Blame for the Poor Admin Notices Experience?. If you haven’t already, I recommend reading his article. It describes in detail one question I’ve been pondering since I originally posted the WP Notify feature project proposal almost a year ago now: Will a new notification system for WordPress solve the notification spam, or just move it elsewhere?

The answer might not be as simple as we think.

I have been building, maintaining, and supporting a number of free, paid, and client plugins for the past five years. During that time I have also been an active contributor — as much as I possibly can outside of work and my personal life — to the WordPress open source project. Now that’s definitely a drop in the ocean compared to some folks, but whenever I see the mess that can occur when multiple plugins or themes register admin_notices on EVERY SINGLE ADMIN PAGE, it strengthens my resolve in the idea that WordPress needs a centrally managed notification system. 

If you read Justin’s article, or you are a plugin or theme developer yourself, you know that the notifications system (aka admin notices, a reference to the WordPress hook that prints these notices) in WordPress is limited at best. We need to be honest with ourselves, however, admin notices was not designed to function as a notification system. Admin notices should really only be used to display useful information to the user about state changes in the system. Messages like when a post has been updated or deleted, or a database upgrade is required. Short, useful, and more importantly, relevant.

As developers, we usually look for the root cause of a problem. And in the case of admin notices, the root cause is not the current notification system, or the fact that plugin developers use it for things other than, well, admin notices. The root cause is the fact that there has never existed a mechanism for notifications other than admin notices to be displayed to the user. This means that whenever a plugin developer has needed, or in fact wanted, to communicate with their users, via “in app messages,” admin notices has been the only way they can do so.

Want to let your users know about a new upgrade? Admin notice. Want to ask them to leave a review? Admin notice. Your premium license is about to expire! Admin notice. Hey, we’ve got a new sale on our premium products! Admin notice. It all soon adds up to an almighty mess.

And that’s the problem with a project like WP Notify. We’ve had admin notices, in its current iteration at least, since 2011. That means we have been using it for all our user facing messages now for nine years at least – nine years of plugin and theme developers using admin notices to send messages to users. 

If you have children, imagine telling your nine year old that the way they have been walking is wrong, and they now need to learn a completely new way of doing it. Good Luck!

So, as much as it pains me to admit it, WP Notify is not the silver bullet that will magically fix the problem at its core. As Matt Mullenweg pointed out in the comments on Justin’s article, “I don’t think a notification center is the solution to this problem. It may be useful for other reasons, but not that one.”

However, not having a specific solution for notifications other than those that are necessary, means that developers will keep on doing things the way they have always been. Enforcing new guidelines around the current functionality nine years later is going to be hard, especially since enforcing these guidelines will have to be done by a small group of volunteers, namely the theme and plugin review teams. 

By building WP Notify, we create a new and hopefully better way for plugin and theme developers to connect and communicate with their users. At the same time, we provide a tool by which we can more easily enforce any new guidelines. A guideline could be created for example, that unless your message is strictly within the realms of informing the user about state changes in the system, it needs to be displayed in the notifications center, and not as an admin notice.

So no, I don’t believe WP Notify will be a silver bullet solution. We’re not going to build it, ship it, and suddenly all the notification spam goes away the next day. That kind of change takes time.

But I do believe it’s a step in the right direction.

If you agree with me, why not join our merry band and help us build it

Attend the Great WP Virtual Summit for Free: August 19-23

For five days next week, from August 19-23, the inaugural event of The Great WP Virtual Summit will be taking place.

Conceived by South African based WordPress developer Anchen le Roux, the summit aims to bring together experts from various fields within the WordPress ecosystem to share their knowledge over the five days

I reached out to Le Roux, to find out why she came up with the idea of the summit, and what her goals are for the event.

“Being an organiser of WordCamp Johannesburg for the last few years, I’ve been very aware of how only a small number of people are actually able to attend an event like WordCamp. 

Obviously there are a lot of reasons, but for the most part travelling, accommodation, and other logistical items seemed to be the biggest hindrance.”

Being based at the tip of Africa, Le Roux also realized that many other African countries don’t even have a WordCamp, and started wondering what she could do to bring WordCamp to them. The idea for the summit was born.

“I’m hoping an online summit can introduce aspects of WordPress, and being part of the WordPress community, to those living in areas where it’s not easily accessible. It’s also my hope that this will plant a seed with folks, to start their own local communities around WordPress, and ultimately lead to more local WordCamps.”

Anchen is hoping to recreate some of the atmosphere and energy that takes place at a local WordCamp, at this online event.

“I know nothing can substitute for the in-person experience of a WordCamp but I’m trusting that some bits of what makes WordCamps awesome can be recreated in what we do. I’m hoping for this to be the first of many. This first one is very much an experiment but I’m anticipating for it to grow into something that more people can be involved in.“

I asked Le Roux what she hopes attendees will take away from the event.

“Firstly, the goal is to allow folks to learn from top authorities in the WordPress realm on a variety of topics. We have four different tracks catering to all types of  WordPress users. Topics range from branding and design, development, and running your business with WordPress, to running a WordPress agency or being a WP freelancer. 

Above and beyond that, I’m hoping that folks who are new to the community, or are operating on the fringes of our community, are encouraged to become a bigger part of the WordPress community, by giving them the opportunity to chat with other community members, ask questions and/or share ideas.

We have 20+ experts over 5 days, who will teach you strategies you can use to both improve and scale your WordPress business, no matter which stage you’re at, or what type of user you are.”

The Great WP Virtual Summit is happening August 19 – 23 and you can get your free tickets to the event right now by visiting the tickets page.