bbp_parse_args( string|array $args, array $defaults = array(), string $filter_key = '' )

Merge user defined arguments into defaults array.


Description Description

This function is used throughout bbPress to allow for either a string or array to be merged into another array. It is identical to wp_parse_args() except it allows for arguments to be passively or aggressively filtered using the optional $filter_key parameter.


Parameters Parameters

$args

(Required) Value to merge with $defaults

$defaults

(Optional) Array that serves as the defaults.

Default value: array()

$filter_key

(Optional) String to key the filters from

Default value: ''


Top ↑

Return Return

(array) Merged user defined values with defaults.


Top ↑

Source Source

File: includes/common/functions.php

function bbp_parse_args( $args, $defaults = array(), $filter_key = '' ) {

	// Setup a temporary array from $args
	if ( is_object( $args ) ) {
		$r = get_object_vars( $args );
	} elseif ( is_array( $args ) ) {
		$r =& $args;
	} else {
		wp_parse_str( $args, $r );
	}

	// Passively filter the args before the parse
	if ( ! empty( $filter_key ) ) {
		$r = apply_filters( "bbp_before_{$filter_key}_parse_args", $r, $args, $defaults );
	}

	// Parse
	if ( is_array( $defaults ) && ! empty( $defaults ) ) {
		$r = array_merge( $defaults, $r );
	}

	// Aggressively filter the args after the parse
	if ( ! empty( $filter_key ) ) {
		$r = apply_filters( "bbp_after_{$filter_key}_parse_args", $r, $args, $defaults );
	}

	// Return the parsed results
	return $r;
}

Top ↑

Changelog Changelog

Changelog
Version Description
2.1.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.