Miscellaneous developer focused changes in WordPress 5.6

WordPress 5.6 includes several small, developer-focused, changes. Here’s a summary of what you can expect.

General: Replace older-style PHPPHP The web scripting language in which WordPress is primarily architected. WordPress requires PHP 5.6.20 or higher type conversion functions with type casts

PHP’s intval(), strval(), floatval(), and boolval() typecasting functions are artifacts in the WordPress code base from the PHP 4 days. In PHP 5 and later direct type casting is available, which is often many times more performant than their function predecessors.

In WordPress CoreCore Core is the set of software required to run WordPress. The Core Development Team builds WordPress., over 250 remaining occurrences of typecasting functions were removed in favor of direct typecasting. This improves performance, readability, and consistency throughout Core.

  • intval()(int)
  • strval()(string)
  • floatval()(float)

For more information, check out the related ticketticket Created for both bug reports and feature development on the bug tracker. on TracTrac An open source project by Edgewall Software that serves as a bug tracker and project management tool for WordPress.: #42918.

General: Introduce the ability to merge multiple WP_Error objects into one another, and to store more than one item of data for an error

The WP_Error class is used throughout WordPress to indicate an error has occurred with some more specific details (an error code, message, etc.). While this class supports storing multiple error messages and codes in a single instance, it’s not currently possible to merge two WP_Error instances into one without doing so manually.

In WordPress 5.6, three new methods have been added to the WP_Error class to help with these scenarios. 

<?php
$error_1 = new WP_Error(
    'code1',
    'This is my first error message.',
    'Error_Data'
);

$error_2 = new WP_Error(
    'code2',
    'This is my second error message.',
    'Error_Data2'
);

// Merge from another WP_Error.
$error_1->merge_from( $error_2 );

// Retrieve all error data, optionally for a specific error code.
$error_1->get_all_error_data( 'code2' );

// Export to another WP_Error
$error_1->export_to( $error_2 );

For more information, check out the related ticket on Trac: #38777.

Pings/Trackbacks: Split do_all_pings() into several functions

The do_all_pings() function is responsible for performing pingbacks, trackbacks, enclosures, and updates for a site. However, in its current state, it’s impossible to disable just one of those services.

In WordPress 5.6, each service has been split out into its own function.

  • do_all_pingbacks()
  • do_all_enclosures()
  • do_all_trackbacks()
  • generic_ping() has existed since WordPress 1.2

The do_all_pings() function will remain in order to prevent changing the behavior configured by any pluginPlugin A plugin is a piece of software containing a group of functions that can be added to a WordPress website. They can extend functionality or add new features to your WordPress websites. WordPress plugins are written in the PHP programming language and integrate seamlessly with WordPress. These can be free in the WordPress.org Plugin Directory https://wordpress.org/plugins/ or can be cost-based plugin from a third-party currently unhooking do_all_pings() from the do_pings action. do_all_pings() will now fire a new action, do_all_pings, with the four functions above attached.

As an example, let’s say you wish to disable only trackbacks. The following snippet would unhook the trackbacks function, preventing trackbacks from being performed.

 <?php
 remove_action( ‘do_all_pings’, ‘do_all_trackbacks’ ); 

For more information, check out the related ticket on Trac: #36576.

TaxonomyTaxonomy A taxonomy is a way to group things together. In WordPress, some common taxonomies are category, link, tag, or post format. https://codex.wordpress.org/Taxonomies#Default_Taxonomies.: Allow for wp_count_terms( $args ) signature, making passing a taxonomy optional

In WordPress 4.3, the concept of shared taxonomy terms was eliminated. This paved the road for many taxonomy related features and improvements in the following years, including the WP_Term class (#14162) and term metaMeta Meta is a term that refers to the inside workings of a group. For us, this is the team that works on internal WordPress sites like WordCamp Central and Make WordPress. (#10142) in WordPress 4.4, and making the $taxonomy parameter optional when calling get_terms() (see #35495).

In WordPress 5.6, the wp_count_terms() function signature has been updated for consistency and now matches that of get_terms(). This also makes it more apparent that wp_count_terms() can be used to count all terms, and not just ones from a certain taxonomy.

Similar to the change previously made to get_terms(), no deprecation warnings are triggered when using the legacy function signature.

For more information, check out the related ticket on Trac: #36399.

Build/Test Tools: Fix code coverage generation

The phpunit.xml.dist file that configures the PHPUnit test suite was incorrectly configuring the code coverage setup to generate a code coverage report from the src directory. Because the WP_RUN_CORE_TESTS constant is also defined as 1 in the ruleset, the codebase is run from the build directory. This was resulting in an empty and inaccurate coverage report.

This makes the coverage setup consistent with other parts of the test suite when the WP_RUN_CORE_TESTS constant is set to 1.

Note: If you have a local phpunit.xml file that changes the WP_RUN_CORE_TESTS constant to 0, you should also – in the same file – change the code coverage setup to use the src directory instead.

For more information, check out the related ticket on Trac: #50267.

Networks and Sites: New filters and actions

In WordPress 5.6, two new filters have been introduced to provide more control over the email sent out to administrators when a new site is created.

First, the new_site_email_filter has been added to allow developers to alter the following parts of this email: to, subject, message, and headers.

Second, the send_new_site_email has been added to allow developers to disable this email entirely. Returning false to this filterFilter Filters are one of the two types of Hooks https://codex.wordpress.org/Plugin_API/Hooks. They provide a way for functions to modify data of other functions. They are the counterpart to Actions. Unlike Actions, filters are meant to work in an isolated manner, and should never have side effects such as affecting global variables and output. will prevent the email from being sent at all.

For more information on these filters, check out the related ticket on Trac: #42134.

Additionally, the network_site_info_form action has been added in the site info form within the networknetwork (versus site, blog) adminadmin (and super admin). This action hook allows developers to add additional fields to the form.

For more information, check out the related ticket on Trac: #50704.

Database: Deprecated post_category column removed

In WordPress 2.8, the posts.post_category database column was dropped from the database schema and, it will no longer be added to new sites. However, the column was never removed from sites created with WordPress 2.7 or earlier.

Upon upgrading to WordPress 5.6, the posts.post-category column will be removed from the posts table if present in the database.

For more information, check out the related ticket on Trac: #51288.

General: Add $options parameter to JSONJSON JSON, or JavaScript Object Notation, is a minimal, readable format for structuring data. It is used primarily to transmit data between a server and web application, as an alternative to XML. response functions

WordPress has several utility functions for sending proper JSON responses to requests. Eventually, they all call wp_json_encode(), which accepts an $options parameter. This gets passed to the PHP internal json_encode() function as the $flags argument.

The following functions now accept an $options parameter:

  • wp_send_json()
  • wp_send_json_success()
  • wp_send_json_error()

For more information, check out the related ticket on Trac: #51293.

Additional developer changes

  • Administration: Restore alternative admin menu position for menu items with the same position value as an existing menu item (see #42918).
    Comments: Adds a comments_template_top_level_query_args filter for top level comments query arguments in comments_template() (see  #38074).
  • Media: sanitize_file_name() now removes accents, making it more consistent with sanitize_title() and sanitize_user() (see #22363).
  • Media: The image_sideload_extensions filter has been added to the list of allowed file extensions when sideloading an image from a URLURL A specific web address of a website or web page on the Internet, such as a website’s URL www.wordpress.org (see #50695).
  • Media: Stream wrappers are now supported by the WP_Image_Editor_Imagick image editing class (see #42663).
  • Media: The wp_get_attachment_image filter has been introduced within wp_get_attachment_image() to filter the HTMLHTML HyperText Markup Language. The semantic scripting language primarily used for outputting content in web browsers. output (see #50801).
  • Multisitemultisite Used to describe a WordPress installation with a network of multiple blogs, grouped by sites. This installation type has shared users tables, and creates separate database tables for each blog (wp_posts becomes wp_0_posts). See also network, blog, site: get_dirsize() now has a more contextual cache, storing sizes by directory resulting in a performance improvement (see #19879).
  • Quick/Bulk Edit: The quick_edit_dropdown_authors_args filter has been introduced to allow the authors dropdown within the Quick Edit interface to be modified (see #47685).
  • Site Health: The recovery_mode_email filter has been updated to support attachments. This adds the ability for developers to add attachments to pass to wp_mail() (see #51276).
  • Users: Introduce email_exists filter, to complement username_exists (see #51379).
  • Users: Introduce the invited_user_email filter for filtering the contents of the email sent when an existing user is invited to a site on Multisite (see #42132).
  • Upgrade/Install: Introduce the wp_installed_email filter for filtering the contents of the email sent when WordPress is installed, without needing to override the wp_new_blog_notification() pluggable function (see #42133).
  • Widgets: When support for the HTML5 navigation-widgets is declared, the tagtag A directory in Subversion. WordPress uses tags to store a single snapshot of a version (3.6, 3.6.1, etc.), the common convention of tags in version control systems. (Not to be confused with post tags.) cloud widgetWidget A WordPress Widget is a small block that performs a specific function. You can add these widgets in sidebars also known as widget-ready areas on your web page. WordPress widgets were originally created to provide a simple and easy-to-use way of giving design and structure control of the WordPress theme to the user. is now properly wrapped in a <nav> element to improve semantics and accessibilityAccessibility Accessibility (commonly shortened to a11y) refers to the design of products, devices, services, or environments for people with disabilities. The concept of accessible design ensures both “direct access” (i.e. unassisted) and “indirect access” meaning compatibility with a person’s assistive technology (for example, computer screen readers). (https://en.wikipedia.org/wiki/Accessibility) (see #51455).

Props @desrosj and @newyorkerlaura for helping to draft/review.

#5-6, #dev-notes