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

Merge user defined arguments into defaults array.

Description

This function is used throughout BuddyPress 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. If no $filter_key is passed, no filters are applied.

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-core/bp-core-functions.php

270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
function bp_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 ) ) {
 
        /**
         * Filters the arguments key before parsing if filter key provided.
         *
         * This is a dynamic filter dependent on the specified key.
         *
         * @since BuddyPress 2.0.0
         *
         * @param array $r Array of arguments to use.
         */
        $r = apply_filters( 'bp_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 ) ) {
 
        /**
         * Filters the arguments key after parsing if filter key provided.
         *
         * This is a dynamic filter dependent on the specified key.
         *
         * @since BuddyPress 2.0.0
         *
         * @param array $r Array of parsed arguments.
         */
        $r = apply_filters( 'bp_after_' . $filter_key . '_parse_args', $r );
    }
 
    // Return the parsed results.
    return $r;
}

Changelog

Changelog
Version Description
BuddyPress 2.0.0 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.