1 | <?php |
---|
2 | /* |
---|
3 | Plugin name: apply_filters_ref_array tests |
---|
4 | Author: scribu |
---|
5 | Version: 1.0 |
---|
6 | */ |
---|
7 | |
---|
8 | // No additional arguments |
---|
9 | function test_func_simple($value) { |
---|
10 | return 'pass'; |
---|
11 | } |
---|
12 | add_filter('test_filter_simple', 'test_func_simple'); |
---|
13 | |
---|
14 | $new_val = apply_filters_ref_array('test_filter_simple', array('fail')); |
---|
15 | var_dump('pass' == $new_val); |
---|
16 | |
---|
17 | // An object reference as an additional argument |
---|
18 | function test_func($value, $arg) { |
---|
19 | $arg->test = 'pass'; |
---|
20 | |
---|
21 | return 'pass'; |
---|
22 | } |
---|
23 | add_filter('test_filter', 'test_func', 10, 2); |
---|
24 | |
---|
25 | $obj = new stdClass(); |
---|
26 | $obj->test = 'fail'; |
---|
27 | |
---|
28 | $new_val = apply_filters_ref_array('test_filter', array('fail', &$obj)); |
---|
29 | var_dump('pass' == $new_val && 'pass' == $obj->test); |
---|
30 | |
---|