Make WordPress Core

Ticket #47725: wp_parse_args_deep.diff

File wp_parse_args_deep.diff, 1.1 KB (added by tazotodua, 4 years ago)
  • src/wp-includes/functions.php

    diff --git src/wp-includes/functions.php src/wp-includes/functions.php
    index 87efed9bf0..a1da4c162a 100644
    function wp_parse_args( $args, $defaults = '' ) { 
    41224122
    41234123
    41244124
     4125/**
     4126 * Merge user defined arguments into defaults array, with recursive support.
     4127 *
     4128 * This function is used throughout WordPress to allow for both string or array
     4129 * to be merged into another array.
     4130 *
     4131 * @since 5.2.2
     4132 *
     4133 * @param string|array|object $args     Value to merge with $defaults.
     4134 * @param array               $defaults Optional. Array that serves as the defaults. Default empty.
     4135 * @return array Merged user defined values with defaults.
     4136 */
     4137
     4138function wp_parse_args_deep( &$a, $b ) {
     4139        $a = (array) $a;
     4140        $b = (array) $b;
     4141        $result = $b;
     4142        foreach ( $a as $k => &$v ) {
     4143                if ( is_array( $v ) && isset( $result[ $k ] ) ) {
     4144                        $result[ $k ] = wp_parse_args_deep( $v, $result[ $k ] );
     4145                } else {
     4146                        $result[ $k ] = $v;
     4147                }
     4148        }
     4149        return $result;
     4150}
     4151
     4152
     4153
    41254154/**
    41264155 * Cleans up an array, comma- or space-separated list of scalar values.
    41274156 *