Skip to content

Instantly share code, notes, and snippets.


jrfnl/ Secret

Last active Oct 9, 2019
What would you like to do?
WordPress Trac #47678 Dev Note

WP 5.3: Introducing the spread operator

In WP 5.3, the PHP 5.6 spread operator has been introduced to WordPress in a number of places.

Using the spread operator allowed for simplifying the code and improves performance - both in speed as well as memory use -, especially as it has been introduced in a number of functions which are used a multitude of times during every single pageload, such as current_user_can() and add_query_arg().

For full details, see Trac ticket #47678.

Impact on plugins/themes

Most plugins and themes should see no impact of these patches, other than the improved performance.

However, if your plugin/theme is one of the limited number of plugins and themes which extends one of the below listed classes and overloads any of the listed methods, you will need to take action.

In nearly all cases, WP 5.3 has added a new parameter to the function signature using the spread operator. This allows for an easy transition as you can adjust the function signature of the method overloading it to do the same. You may also want to adjust the code in the method to get the same performance benefits in the overloaded method. See the relevant patches linked below for the full details of each change and for inspiration.

Adding the extra argument will allow your plugin/theme to be compatible with both WP 5.3 and older WP versions, though it does raise the minimum PHP requirement for your plugin/theme to PHP 5.6. Make sure you annotate this in the readme.txt!

In only one case - wpdb::prepare() -, WP 5.3 has changed an existing parameter. In the exceptional situation that you would be overloading that method, you will need to make a choice whether you want to continue supporting older WP versions or to set the minimum WP version to WP 5.3. If you set the minimum WP version to WP 5.3, you need to change the function signature of the overloading method to match the new function signature in WP 5.3 and you may also want to simplify some code in your method too. If you want to continue to support older WP versions, you will need two versions of the class overload and an if/else toggle to load the correct one depending on the WP version being used. Note: this really only applies to overloaded wpdb::prepare() methods. There is no need to do this if you overload any of the other affected classes.

What will break if I don't make the change to my plugin/theme ?

Nothing. The world will keep turning as it did before.

You may get some complaints from end-users that they are seeing PHP warnings about a mismatched function signature in their PHP error logs, but other than that, all should still work as before.

This is not to say that you shouldn't update your plugins/themes... You should. It is just that if you don't have time to do it right away, you don't need to worry that your plugin/theme will be bringing sites down.

List of affected classses:

List of affected test classses:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment