bbp_parse_args

Merge user defined arguments into defaults array.

Description

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

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.

Returns (array)

Merged user defined values with defaults.

Parameters (3)

0. $args (string|array)
Value to merge with $defaults
1. $defaults — Optional. (array) => array()
Array that serves as the defaults.
2. $filter_key — Optional. (string) => ''
String to key the filters from

Usage

  1. if ( !function_exists( 'bbp_parse_args' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'bbpress/includes/common/functions.php'; 
  3.  
  4. // Value to merge with $defaults 
  5. $args = null; 
  6.  
  7. // Array that serves as the defaults. 
  8. $defaults = array(); 
  9.  
  10. // String to key the filters from 
  11. $filter_key = ''; 
  12.  
  13. // NOTICE! Understand what this does before running. 
  14. $result = bbp_parse_args($args, $defaults, $filter_key); 
  15.  

Defined (1)

The function is defined in the following location(s).

/includes/common/functions.php  
  1. function bbp_parse_args( $args, $defaults = array(), $filter_key = '' ) { 
  2.  
  3. // Setup a temporary array from $args 
  4. if ( is_object( $args ) ) { 
  5. $r = get_object_vars( $args ); 
  6. } elseif ( is_array( $args ) ) { 
  7. $r =& $args; 
  8. } else { 
  9. wp_parse_str( $args, $r ); 
  10.  
  11. // Passively filter the args before the parse 
  12. if ( !empty( $filter_key ) ) { 
  13. $r = apply_filters( 'bbp_before_' . $filter_key . '_parse_args', $r ); 
  14.  
  15. // Parse 
  16. if ( is_array( $defaults ) && !empty( $defaults ) ) { 
  17. $r = array_merge( $defaults, $r ); 
  18.  
  19. // Aggressively filter the args after the parse 
  20. if ( !empty( $filter_key ) ) { 
  21. $r = apply_filters( 'bbp_after_' . $filter_key . '_parse_args', $r ); 
  22.  
  23. // Return the parsed results 
  24. return $r;