| 1 | <?php
|
|---|
| 2 | /**
|
|---|
| 3 | * Plugin Name: Test Did Action
|
|---|
| 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 action before it. The second
|
|---|
| 15 | * function outputs 1, as test_did_action_action1 has run
|
|---|
| 16 | * before it. The third function outputs 2, as test_did_action_action1
|
|---|
| 17 | * and test_did_action_action2 has run before it.
|
|---|
| 18 | *
|
|---|
| 19 | * Finally the script dies and outputs 3, as 3 functions total
|
|---|
| 20 | * executed on the action.
|
|---|
| 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_action' );
|
|---|
| 26 | function test_did_action(){
|
|---|
| 27 | $string = 'test';
|
|---|
| 28 | do_action( 'test_did_action', $string );
|
|---|
| 29 | var_dump( did_action( 'test_did_action' ) ); // Outputs 3
|
|---|
| 30 | wp_die();
|
|---|
| 31 | }
|
|---|
| 32 |
|
|---|
| 33 | function test_did_action_action1( $string ){
|
|---|
| 34 | var_dump( did_action( 'test_did_action' ) ); // Outputs 0
|
|---|
| 35 | echo $string . '1';
|
|---|
| 36 | }
|
|---|
| 37 | add_action( 'test_did_action', 'test_did_action_action1', 10, 1 );
|
|---|
| 38 |
|
|---|
| 39 | function test_did_action_action2( $string ){
|
|---|
| 40 | var_dump( did_action( 'test_did_action' ) ); // Outputs 1
|
|---|
| 41 | echo $string . '1';
|
|---|
| 42 | }
|
|---|
| 43 | add_action( 'test_did_action', 'test_did_action_action2', 11, 1 );
|
|---|
| 44 |
|
|---|
| 45 | function test_did_action_action3( $string ){
|
|---|
| 46 | var_dump( did_action( 'test_did_action' ) ); // Outputs 2
|
|---|
| 47 | echo $string . '1';
|
|---|
| 48 | }
|
|---|
| 49 | add_action( 'test_did_action', 'test_did_action_action3', 12, 1 );
|
|---|