wp_parse_args
Merge user defined arguments into defaults array.
Description
This function is used throughout WordPress to allow for both string or array to be merged into another array.
Returns (array)
Merged user defined values with defaults.
Parameters (2)
- 0. $args (string|array|object)
- Value to merge with
$defaults
. - 1. $defaults — Optional. (string) =>
''
- Array that serves as the defaults. Default empty.
Usage
if ( !function_exists( 'wp_parse_args' ) ) { require_once ABSPATH . WPINC . '/functions.php'; } // Value to merge with $defaults. $args = null; // Optional. Array that serves as the defaults. Default empty. $defaults = ''; // NOTICE! Understand what this does before running. $result = wp_parse_args($args, $defaults);
Defined (1)
The function is defined in the following location(s).
- /wp-includes/functions.php
- function wp_parse_args( $args, $defaults = '' ) {
- if ( is_object( $args ) )
- $r = get_object_vars( $args );
- elseif ( is_array( $args ) )
- $r =& $args;
- else
- wp_parse_str( $args, $r );
- if ( is_array( $defaults ) )
- return array_merge( $defaults, $r );
- return $r;
- }