Last active
May 19, 2017 16:01
-
-
Save greatislander/1999501a8145e6d2c161a027b3d28d7d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Array with filter hook. | |
$my_array = apply_filters( 'filter_my_array', array( | |
'value1', | |
'value2', | |
'value3', | |
) ); | |
/** | |
* Filter function | |
* | |
* @param array $array The input array. | |
* @return array The filtered array. | |
*/ | |
function filter_array( $array ) { | |
$array[] = 'value4'; // Add another item to the array. | |
return $array; // Return the array with the new item. | |
} | |
// Attaching our function to the filter hook. | |
add_filter( 'filter_my_array', 'filter_array' ); | |
// OR use an anonymous function (this does the same thing) | |
add_filter( 'filter_my_array', function ( $array ) { | |
$array[] = 'value4'; // Add another item to the array. | |
return $array; // Return the array with the new item. | |
} ); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment