WordPress.org

Make WordPress Core

Changeset 45628


Ignore:
Timestamp:
07/12/2019 12:09:31 AM (8 months ago)
Author:
pento
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/theme.php

    r45621 r45628  
    23542354 * @return void|bool False on failure, void otherwise.
    23552355 */
    2356 function add_theme_support( $feature ) {
     2356function add_theme_support( $feature, ...$args ) {
    23572357    global $_wp_theme_features;
    23582358
    2359     if ( func_num_args() == 1 ) {
     2359    if ( ! $args ) {
    23602360        $args = true;
    2361     } else {
    2362         $args = array_slice( func_get_args(), 1 );
    23632361    }
    23642362
     
    26662664 * @return mixed The array of extra arguments or the value for the registered feature.
    26672665 */
    2668 function get_theme_support( $feature ) {
     2666function get_theme_support( $feature, ...$args ) {
    26692667    global $_wp_theme_features;
    26702668    if ( ! isset( $_wp_theme_features[ $feature ] ) ) {
     
    26722670    }
    26732671
    2674     if ( func_num_args() <= 1 ) {
     2672    if ( ! $args ) {
    26752673        return $_wp_theme_features[ $feature ];
    26762674    }
    26772675
    2678     $args = array_slice( func_get_args(), 1 );
    26792676    switch ( $feature ) {
    26802677        case 'custom-logo':
     
    27872784 * @return bool True if the current theme supports the feature, false otherwise.
    27882785 */
    2789 function current_theme_supports( $feature ) {
     2786function current_theme_supports( $feature, ...$args ) {
    27902787    global $_wp_theme_features;
    27912788
     
    27992796
    28002797    // If no args passed then no extra checks need be performed
    2801     if ( func_num_args() <= 1 ) {
     2798    if ( ! $args ) {
    28022799        return true;
    28032800    }
    2804 
    2805     $args = array_slice( func_get_args(), 1 );
    28062801
    28072802    switch ( $feature ) {
Note: See TracChangeset for help on using the changeset viewer.