Make WordPress Core

Ticket #26673: 26673.patch

File 26673.patch, 2.0 KB (added by johnjamesjacoby, 13 years ago)
  • wp-includes/functions.php

    diff --git a/wp-includes/functions.php b/wp-includes/functions.php
    index 05acf4e..f5551cb 100644
    a b  
    25852585/**
    25862586 * Merge user defined arguments into defaults array.
    25872587 *
    2588  * This function is used throughout WordPress to allow for both string or array
    2589  * to be merged into another array.
     2588 * This function is used throughout WordPress to allow for either a string or
     2589 * array to be merged into another array. It allows for arguments to be
     2590 * passively or aggressively filtered using the optional $filter_key parameter.
     2591 * If no $filter_key is passed, no filters are applied.
    25902592 *
    25912593 * @since 2.2.0
    25922594 *
    25932595 * @param string|array $args Value to merge with $defaults
    2594  * @param array $defaults Array that serves as the defaults.
    2595  * @return array Merged user defined values with defaults.
     2596 * @param array $defaults Array that serves as the defaults
     2597 * @param string $filter_key String to key the filters from
     2598 * @return array Merged user defined values with defaults
    25962599 */
    2597 function wp_parse_args( $args, $defaults = '' ) {
    2598         if ( is_object( $args ) )
    2599                 $r = get_object_vars( $args );
    2600         elseif ( is_array( $args ) )
    2601                 $r =& $args;
    2602         else
    2603                 wp_parse_str( $args, $r );
     2600function wp_parse_args( $args, $defaults = '', $filter_key = '' ) {
    26042601
    2605         if ( is_array( $defaults ) )
    2606                 return array_merge( $defaults, $r );
     2602        // Setup a temporary array from $args
     2603        if ( is_object( $args ) ) {
     2604                $r = get_object_vars( $args );
     2605        } elseif ( is_array( $args ) ) {
     2606                $r =& $args;
     2607        } else {
     2608                wp_parse_str( $args, $r );
     2609        }
     2610
     2611        // Passively filter the args before the parse
     2612        if ( !empty( $filter_key ) ) {
     2613                $r = apply_filters( 'wp_before_' . $filter_key . '_parse_args', $r );
     2614        }
     2615
     2616        // Parse
     2617        if ( is_array( $defaults ) && !empty( $defaults ) ) {
     2618                $r = array_merge( $defaults, $r );
     2619        }
     2620
     2621        // Aggressively filter the args after the parse
     2622        if ( !empty( $filter_key ) ) {
     2623                $r = apply_filters( 'wp_after_' . $filter_key . '_parse_args', $r );
     2624        }
     2625
     2626        // Return the parsed results
    26072627        return $r;
    26082628}
    26092629