Make WordPress Core

Changeset 45629


Ignore:
Timestamp:
07/12/2019 12:13:07 AM (7 years ago)
Author:
pento
Message:

Code Modernisation: Introduce the spread operator in widgets.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.
See #47678.

File:
1 edited

Legend:

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

    r45611 r45629  
    459459 * @since 2.2.0
    460460 *
    461  * @todo `$params` parameter?
    462  *
    463461 * @global array $wp_registered_widget_controls
    464462 * @global array $wp_registered_widget_updates
    … …  
    480478 * @param mixed      ...$params        Optional additional parameters to pass to the callback function when it's called.
    481479 */
    482 function wp_register_widget_control( $id, $name, $control_callback, $options = array() ) {
     480function wp_register_widget_control( $id, $name, $control_callback, $options = array(), ...$params ) {
    483481        global $wp_registered_widget_controls, $wp_registered_widget_updates, $wp_registered_widgets, $_wp_deprecated_widgets_callbacks;
    484482
    … …  
    513511                'id'       => $id,
    514512                'callback' => $control_callback,
    515                 'params'   => array_slice( func_get_args(), 4 ),
     513                'params'   => $params,
    516514        );
    517515        $widget = array_merge( $widget, $options );
    … …  
    544542 * @param mixed    ...$params       Optional additional parameters to pass to the callback function when it's called.
    545543 */
    546 function _register_widget_update_callback( $id_base, $update_callback, $options = array() ) {
     544function _register_widget_update_callback( $id_base, $update_callback, $options = array(), ...$params ) {
    547545        global $wp_registered_widget_updates;
    548546
    … …  
    556554        $widget = array(
    557555                'callback' => $update_callback,
    558                 'params'   => array_slice( func_get_args(), 3 ),
     556                'params'   => $params,
    559557        );
    560558
    … …  
    578576 */
    579577
    580 function _register_widget_form_callback( $id, $name, $form_callback, $options = array() ) {
     578function _register_widget_form_callback( $id, $name, $form_callback, $options = array(), ...$params ) {
    581579        global $wp_registered_widget_controls;
    582580
    … …  
    604602                'id'       => $id,
    605603                'callback' => $form_callback,
    606                 'params'   => array_slice( func_get_args(), 4 ),
     604                'params'   => $params,
    607605        );
    608606        $widget = array_merge( $widget, $options );
Note: See TracChangeset for help on using the changeset viewer.