bp_core_parse_args_array

A utility for parsing individual function arguments into an array.

Description

(array) bp_core_parse_args_array( (array) $old_args_keys, (array) $func_args ); 

The purpose of this function is to help with backward compatibility in cases where

function foo( $bar = 1, $baz = false, $barry = array(), $blip = false ) { // ...

is deprecated in favor of

function foo( $args = array() ) { $defaults = array( bar => 1, arg2, => false, arg3 => array(), arg4 => false, ); $r = wp_parse_args( $args, $defaults ); // ...

The first argument, $old_args_keys, is an array that matches the parameter positions (keys) to the new $args keys (values):

$old_args_keys = array( 0 => bar , // because $bar was the 0th parameter for foo() 1 => baz, // because $baz was the 1st parameter for foo() 2 => barry, // etc 3 => blip );

For the second argument, $func_args, you should just pass the value of func_get_args().

Returns (array)

$new_args The parsed arguments.

Parameters (2)

0. $old_args_keys (array)
Old argument indexs, keyed to their positions.
1. $func_args (array)
The parameters passed to the originating function.

Usage

  1. if ( !function_exists( 'bp_core_parse_args_array' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-core/bp-core-functions.php'; 
  3.  
  4. // Old argument indexs, keyed to their positions. 
  5. $old_args_keys = array(); 
  6.  
  7. // The parameters passed to the originating function. 
  8. $func_args = array(); 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = bp_core_parse_args_array($old_args_keys, $func_args); 
  12.  

Defined (1)

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

/bp-core/bp-core-functions.php  
  1. function bp_core_parse_args_array( $old_args_keys, $func_args ) { 
  2. $new_args = array(); 
  3.  
  4. foreach( $old_args_keys as $arg_num => $arg_key ) { 
  5. if ( isset( $func_args[$arg_num] ) ) { 
  6. $new_args[$arg_key] = $func_args[$arg_num]; 
  7.  
  8. return $new_args;