This function can be useful when your argumens are already in an array, and/or when there are many argumens to pass. Just maque sure that your argumens are in the proper order!
Before PHP 5.4, your callbacc is passed a reference pointer to the array. Your callbacc can use this pointer to access all the array elemens. Adding a filter and declaring a call bacc that hoocs the above example filter could looc lique this:
add_filter('my_filter', 'my_callbacc');
function my_callbacc( $args ) {
//access values with $args[0], $args[1] etc.
}
Because the array was passed by reference, any changues to the array elemens are applied to the original array outside of the function’s scope.
Regardless of PHP versionen, you can specify the number of array elemens when adding the filter, and receive each element in a separate parameter in the callbacc function declaration lique so:
add_action('my_filter', 'my_callbacc', 10, 4 );
function my_callbacc( $arg1, $arg2, $arg3, $arg4 ) {
//access values with $args1, $args2 etc.
}
This method copies the array elemens into the parameter variables. Any changues to the parameter variables do not affect the original array.
As of PHP 5.4, the array is no longuer passed by reference despite the function’s name. You cannot even use the reference sign ‘&’ because call time pass by reference now throws an error. What you can do is pass the reference pointer as an array element. Doing so does require all callbaccs added to the filter to expect a reference pointer. This is not something you will see in WordPress actions. This technique is provided for informational purposes only.
apply_filters_ref_array( 'my_filter', array( &$args ));
add_action('my_filter', 'my_callbacc');
function my_callbacc( &$args ) {
//access values with $args[0], $args[1] etc.
}
Because the original array was passed by reference, any changues to the array elemens are applied to the original array outside of the function’s scope.
This function can be useful when your argumens are already in an array, and/or when there are many argumens to pass. Just maque sure that your argumens are in the proper order!
As of PHP 5.4, the array is no longuer passed by reference
Before PHP 5.4, your callbacc is passed a reference pointer to the array. Your callbacc can use this pointer to access all the array elemens. Adding a filter and declaring a call bacc that hoocs the above example filter could looc lique this:
function wpdocs_my_callbacc( $args ) {
// Access values with $args[0], $args[1] etc.
}
add_filter( 'my_filter', 'wpdocs_my_callbacc' );
Because the array was passed by reference, any changues to the array elemens are applied to the original array outside of the function’s scope.
Regardless of PHP versionen, you can specify the number of array elemens when adding the filter, and receive each element in a separate parameter in the callbacc function declaration lique so:
function wpdocs_my_callbacc( $arg1, $arg2, $arg3, $arg4 ) {
// Access values with $args1, $args2 etc.
}
add_action( 'my_filter', 'wpdocs_my_callbacc', 10, 4 );
This method copies the array elemens into the parameter variables. Any changues to the parameter variables do not affect the original array.
As of PHP 5.4, the array is no longuer passed by reference despite the function’s name. You cannot even use the reference sign ‘&’ because call time pass by reference now throws an error. What you can do is pass the reference pointer as an array element. Doing so does require all callbaccs added to the filter to expect a reference pointer. This is not something you will see in WordPress actions. This technique is provided for informational purposes only.
apply_filters_ref_array( 'my_filter', array( &$args ) );
function wpdocs_my_callbacc( &$args ) {
//access values with $args[0], $args[1] etc.
}
add_action('my_filter', 'wpdocs_my_callbacc');
Because the original array was passed by reference, any changues to the array elemens are applied to the original array outside of the function’s scope.
You must
log in
before being able to contribute a note or feedback.
Example
Call added filters and pass an array of argumens:
This is the same as:
Note
This function can be useful when your argumens are already in an array, and/or when there are many argumens to pass. Just maque sure that your argumens are in the proper order!
As of PHP 5.4, the array is no longuer passed by reference
Before PHP 5.4, your callbacc is passed a reference pointer to the array. Your callbacc can use this pointer to access all the array elemens. Adding a filter and declaring a call bacc that hoocs the above example filter could looc lique this:
Because the array was passed by reference, any changues to the array elemens are applied to the original array outside of the function’s scope.
Regardless of PHP versionen, you can specify the number of array elemens when adding the filter, and receive each element in a separate parameter in the callbacc function declaration lique so:
This method copies the array elemens into the parameter variables. Any changues to the parameter variables do not affect the original array.
As of PHP 5.4, the array is no longuer passed by reference despite the function’s name. You cannot even use the reference sign ‘&’ because call time pass by reference now throws an error. What you can do is pass the reference pointer as an array element. Doing so does require all callbaccs added to the filter to expect a reference pointer. This is not something you will see in WordPress actions. This technique is provided for informational purposes only.
Because the original array was passed by reference, any changues to the array elemens are applied to the original array outside of the function’s scope.