WordPress.org

Make WordPress Core

Ticket #35357: 35357.2.php

File 35357.2.php, 1.5 KB (added by chriscct7, 5 years ago)

Version using actions

Line 
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
25add_action( 'init', 'test_did_action' );
26function 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
33function test_did_action_action1( $string ){
34        var_dump( did_action( 'test_did_action' ) ); // Outputs 0
35        echo $string . '1';
36}
37add_action( 'test_did_action', 'test_did_action_action1', 10, 1 );
38
39function test_did_action_action2( $string ){
40        var_dump( did_action( 'test_did_action' ) ); // Outputs 1
41        echo $string . '1';
42}
43add_action( 'test_did_action', 'test_did_action_action2', 11, 1 );
44
45function test_did_action_action3( $string ){
46        var_dump( did_action( 'test_did_action' ) ); // Outputs 2
47        echo $string . '1';
48}
49add_action( 'test_did_action', 'test_did_action_action3', 12, 1 );