WordPress.org

Make WordPress Core

Ticket #35357: 35357.php

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

Plugin that uses did_filter based on patch 3

Line 
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
25add_action( 'init', 'test_did_filter' );
26function 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
33function test_did_filter_filter1( $string ){
34        var_dump( did_filter( 'test_did_filter' ) ); // Outputs 0
35        return $string . '1';
36}
37add_filter( 'test_did_filter', 'test_did_filter_filter1', 10, 1 );
38
39function test_did_filter_filter2( $string ){
40        var_dump( did_filter( 'test_did_filter' ) ); // Outputs 1
41        return $string . '1';
42}
43add_filter( 'test_did_filter', 'test_did_filter_filter2', 11, 1 );
44
45function test_did_filter_filter3( $string ){
46        var_dump( did_filter( 'test_did_filter' ) ); // Outputs 2
47        return $string . '1';
48}
49add_filter( 'test_did_filter', 'test_did_filter_filter3', 12, 1 );