bp_core_parse_args_array( array $old_args_keys, array $func_args )

A utility for parsing individual function arguments into an array.


Description Description

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().


Parameters Parameters

$old_args_keys

(Required) Old argument indexes, keyed to their positions.

$func_args

(Required) The parameters passed to the originating function.


Top ↑

Return Return

(array) $new_args The parsed arguments.


Top ↑

Source Source

File: bp-core/bp-core-functions.php

function bp_core_parse_args_array( $old_args_keys, $func_args ) {
	$new_args = array();

	foreach( $old_args_keys as $arg_num => $arg_key ) {
		if ( isset( $func_args[$arg_num] ) ) {
			$new_args[$arg_key] = $func_args[$arg_num];
		}
	}

	return $new_args;
}

Top ↑

Changelog Changelog

Changelog
Version Description
1.6.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

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