| 1 | <?php |
|---|
| 2 | /** |
|---|
| 3 | * Plugin Name: Test Did Filter |
|---|
| 4 | * Plugin URI: https://core.trac.wordpress.org/ticket/35357 |
|---|
| 5 | * Author: Chris Christoff |
|---|
| 6 | * Version: 1.0 |
|---|
| 7 | */ |
|---|
| 8 | |
|---|
| 9 | /** |
|---|
| 10 | * Based on patch 3 for ticket 35357. Requires |
|---|
| 11 | * patch has been applied before activating this plugin. |
|---|
| 12 | * |
|---|
| 13 | * The first function that hooks in will output 0, as no |
|---|
| 14 | * functions have run on the filter before it. The second |
|---|
| 15 | * function outputs 1, as test_did_filter_filter1 has run |
|---|
| 16 | * before it. The third function outputs 2, as test_did_filter_filter1 |
|---|
| 17 | * and test_did_filter_filter2 has run before it. |
|---|
| 18 | * |
|---|
| 19 | * Finally the script dies and outputs 3, as 3 functions total |
|---|
| 20 | * executed on the filter. |
|---|
| 21 | * |
|---|
| 22 | * The result is a var_dump of (ints) 0 then 1 then 2 then 3. |
|---|
| 23 | */ |
|---|
| 24 | |
|---|
| 25 | add_action( 'init', 'test_did_filter' ); |
|---|
| 26 | function test_did_filter(){ |
|---|
| 27 | $string = 'test'; |
|---|
| 28 | $string = apply_filters( 'test_did_filter', $string ); |
|---|
| 29 | var_dump( did_filter( 'test_did_filter' ) ); // Outputs 3 |
|---|
| 30 | wp_die(); |
|---|
| 31 | } |
|---|
| 32 | |
|---|
| 33 | function test_did_filter_filter1( $string ){ |
|---|
| 34 | var_dump( did_filter( 'test_did_filter' ) ); // Outputs 0 |
|---|
| 35 | return $string . '1'; |
|---|
| 36 | } |
|---|
| 37 | add_filter( 'test_did_filter', 'test_did_filter_filter1', 10, 1 ); |
|---|
| 38 | |
|---|
| 39 | function test_did_filter_filter2( $string ){ |
|---|
| 40 | var_dump( did_filter( 'test_did_filter' ) ); // Outputs 1 |
|---|
| 41 | return $string . '1'; |
|---|
| 42 | } |
|---|
| 43 | add_filter( 'test_did_filter', 'test_did_filter_filter2', 11, 1 ); |
|---|
| 44 | |
|---|
| 45 | function test_did_filter_filter3( $string ){ |
|---|
| 46 | var_dump( did_filter( 'test_did_filter' ) ); // Outputs 2 |
|---|
| 47 | return $string . '1'; |
|---|
| 48 | } |
|---|
| 49 | add_filter( 'test_did_filter', 'test_did_filter_filter3', 12, 1 ); |
|---|