WordPress.org

Make WordPress Core

Changeset 45625


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

Code Modernisation: Introduce the spread operator in add_post_type_support().

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/post.php

    r45602 r45625  
    17801780 * @param mixed        ...$args   Optional extra arguments to pass along with certain features.
    17811781 */
    1782 function add_post_type_support( $post_type, $feature ) {
     1782function add_post_type_support( $post_type, $feature, ...$args ) {
    17831783    global $_wp_post_type_features;
    17841784
    17851785    $features = (array) $feature;
    17861786    foreach ( $features as $feature ) {
    1787         if ( func_num_args() == 2 ) {
     1787        if ( $args ) {
     1788            $_wp_post_type_features[ $post_type ][ $feature ] = $args;
     1789        } else {
    17881790            $_wp_post_type_features[ $post_type ][ $feature ] = true;
    1789         } else {
    1790             $_wp_post_type_features[ $post_type ][ $feature ] = array_slice( func_get_args(), 2 );
    17911791        }
    17921792    }
Note: See TracChangeset for help on using the changeset viewer.