Code Modernisation: Introduce the spread operator in `theme.php`.

Rather than relying `func_get_args()` to retrieve arbitrary function arguments, we can now use the spread operator to assign them directly to a variable.

Props jrf, pento.
See #47678.

Built from https://develop.svn.wordpress.org/trunk@45628


git-svn-id: http://core.svn.wordpress.org/trunk@45439 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Gary Pendergast 2019-07-12 00:10:56 +00:00
parent 1af80c2106
commit afdbf749d7
2 changed files with 7 additions and 12 deletions

View File

@ -2353,13 +2353,11 @@ function get_theme_starter_content() {
* @param mixed ...$args Optional extra arguments to pass along with certain features.
* @return void|bool False on failure, void otherwise.
*/
function add_theme_support( $feature ) {
function add_theme_support( $feature, ...$args ) {
global $_wp_theme_features;
if ( func_num_args() == 1 ) {
if ( ! $args ) {
$args = true;
} else {
$args = array_slice( func_get_args(), 1 );
}
switch ( $feature ) {
@ -2665,17 +2663,16 @@ function _custom_logo_header_styles() {
* @param mixed ...$args Optional extra arguments to be checked against certain features.
* @return mixed The array of extra arguments or the value for the registered feature.
*/
function get_theme_support( $feature ) {
function get_theme_support( $feature, ...$args ) {
global $_wp_theme_features;
if ( ! isset( $_wp_theme_features[ $feature ] ) ) {
return false;
}
if ( func_num_args() <= 1 ) {
if ( ! $args ) {
return $_wp_theme_features[ $feature ];
}
$args = array_slice( func_get_args(), 1 );
switch ( $feature ) {
case 'custom-logo':
case 'custom-header':
@ -2786,7 +2783,7 @@ function _remove_theme_support( $feature ) {
* @param mixed ...$args Optional extra arguments to be checked against certain features.
* @return bool True if the current theme supports the feature, false otherwise.
*/
function current_theme_supports( $feature ) {
function current_theme_supports( $feature, ...$args ) {
global $_wp_theme_features;
if ( 'custom-header-uploads' == $feature ) {
@ -2798,12 +2795,10 @@ function current_theme_supports( $feature ) {
}
// If no args passed then no extra checks need be performed
if ( func_num_args() <= 1 ) {
if ( ! $args ) {
return true;
}
$args = array_slice( func_get_args(), 1 );
switch ( $feature ) {
case 'post-thumbnails':
// post-thumbnails can be registered for only certain content/post types by passing

View File

@ -13,7 +13,7 @@
*
* @global string $wp_version
*/
$wp_version = '5.3-alpha-45627';
$wp_version = '5.3-alpha-45628';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.