wp_parse_args( string|array|object $args, array $defaults = '' )

Merge user defined arguments into defaults array.


Description

This function is used throughout ClassicPress to allow for both string or array to be merged into another array.


Parameters

$args

(Required) Value to merge with $defaults.

$defaults

(Optional) Array that serves as the defaults.

Default value: ''


Return

(array) Merged user defined values with defaults.


Source

File: 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;
}


Changelog

Changelog
Version Description
WP-2.3.0 $args can now also be an object.
WP-2.2.0 Introduced.