wp_parse_args() WP 1.0
Merge user defined arguments into defaults array.
This function is used throughout WordPress to allow for both string or array to be merged into another array.
Works based on: wp_parse_str()
Basis of: register_rest_field()
1 time = 0.000018s = very fast | 50000 times = 0.08s = speed of light | PHP 7.1.5, WP 4.8.2
No Hooks.
Return
Array. Merged user defined values with defaults.
Usage
wp_parse_args( $args, $defaults );
- $args(string/array/object) (required)
- Value to merge with $defaults.
- $defaults(array)
- Array that serves as the defaults.
Default: empty array
Changelog
Since 2.2.0 | Introduced. |
Since 2.3.0 | $args can now also be an object. |
Code of wp_parse_args() wp parse args WP 5.6
function wp_parse_args( $args, $defaults = array() ) {
if ( is_object( $args ) ) {
$parsed_args = get_object_vars( $args );
} elseif ( is_array( $args ) ) {
$parsed_args =& $args;
} else {
wp_parse_str( $args, $parsed_args );
}
if ( is_array( $defaults ) && $defaults ) {
return array_merge( $defaults, $parsed_args );
}
return $parsed_args;
}Related Functions
From category: Helper Functions
- __return_empty_array()
- __return_empty_string()
- __return_false()
- __return_null()
- __return_true()
- __return_zero()
- build_query()
- get_page_hierarchy()
- get_temp_dir()
- human_readable_duration()
- is_email()
- is_php_version_compatible()
- is_serialized()
- is_serialized_string()
- is_wp_version_compatible()
- map_deep()
- maybe_serialize()
- maybe_unserialize()
- path_join()
- seems_utf8()
- stripslashes_deep()
- timer_stop()
- urlencode_deep()
- wp_array_slice_assoc()
- wp_basename()
- wp_debug_backtrace_summary()
- wp_doing_ajax()
- wp_extract_urls()
- wp_filter_object_list()
- wp_generate_uuid4()
- wp_html_split()
- wp_is_json_request()
- wp_is_numeric_array()
- wp_is_uuid()
- wp_json_encode()
- wp_kses_array_lc()
- wp_kses_hair()
- wp_kses_uri_attributes()
- wp_list_filter()
- wp_list_pluck()
- wp_list_sort()
- wp_make_link_relative()
- wp_mkdir_p()
- wp_normalize_path()
- wp_parse_id_list()
- wp_parse_list()
- wp_parse_slug_list()
- wp_parse_str()
- wp_parse_url()
- wp_rand()
- wp_reset_vars()
- wp_send_json()
- wp_send_json_error()
- wp_send_json_success()
- wp_slash()
- wp_spaces_regexp()
- wp_sprintf()
- wp_tempnam()
- wp_unslash()
- wp_validate_boolean()