3v4l.org

run code in 300+ PHP versions simultaneously
<?php global $wp_test_hooks; if(!is_array($wp_test_hooks)) { $wp_test_hooks = []; } if(!function_exists('add_filter')) { function add_filter( $hook_name, $callback, $priority = 10, $accepted_args = 1 ) { global $wp_test_hooks; $wp_test_hooks[$hook_name][] = [ $callback, $priority, $accepted_args, ]; return true; } } if(!function_exists('add_action')) { function add_action( $hook_name, $callback, $priority = 10, $accepted_args = 1 ) { return add_filter( $hook_name, $callback, $priority, $accepted_args ); } } if(!function_exists('apply_filters')){ function apply_filters( $hook_name, ...$values ) { $value = array_shift($values); global $wp_test_hooks; if(array_key_exists($hook_name, $wp_test_hooks)){ foreach($wp_test_hooks[$hook_name] as $parts){ list($callback, $priority, $accepted_args) = $parts; $value = $callback($value, ...$values); } } return $value; } } if(!function_exists('do_action')){ function do_action( $hook_name, ...$arg ) { global $wp_test_hooks; if(array_key_exists($hook_name, $wp_test_hooks)){ foreach($wp_test_hooks[$hook_name] as $parts){ list($callback, $priority, $accepted_args) = $parts; $callback(...$arg); } } } } add_action('name1', static function(){echo 'In the Action';}); add_filter('name2', static function($originalValue){return 'In the Filter';}); do_action('name1', 'test', 'stuff'); echo PHP_EOL; echo apply_filters('name2', 'test', 'stuff');
Output for 7.4.0 - 7.4.33, 8.0.1 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.27, 8.4.1 - 8.4.14
In the Action In the Filter

preferences:
123.89 ms | 406 KiB | 5 Q