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

Merge user defined arguments into defaults array.

Description

This function is used throughout Forums 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

$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: ''

Return

(array) Merged user defined values with defaults.

Source

File: bp-forums/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 );
	}

	// 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 );
	}

	// Return the parsed results
	return $r;
}

Changelog

Changelog
Version Description
bbPress (r3839) Introduced.

Questions?

We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.