From d8b80c3254fb35549f064ffe15564650040a7dac Mon Sep 17 00:00:00 2001 From: Andrew Nacin Date: Tue, 2 Sep 2014 06:49:11 +0000 Subject: [PATCH] Unit tests for has_filter() not resetting the array pointer. props pento. fixes #29070. see [29472]. git-svn-id: https://develop.svn.wordpress.org/trunk@29665 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/plugin.php | 1 + tests/phpunit/tests/filters.php | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/src/wp-includes/plugin.php b/src/wp-includes/plugin.php index e02139d1c1..d616a2a960 100644 --- a/src/wp-includes/plugin.php +++ b/src/wp-includes/plugin.php @@ -105,6 +105,7 @@ function add_filter( $tag, $function_to_add, $priority = 10, $accepted_args = 1 * return value. */ function has_filter($tag, $function_to_check = false) { + // Don't reset the internal array pointer $wp_filter = $GLOBALS['wp_filter']; $has = ! empty( $wp_filter[ $tag ] ); diff --git a/tests/phpunit/tests/filters.php b/tests/phpunit/tests/filters.php index 34fdf56355..b4ee12f353 100644 --- a/tests/phpunit/tests/filters.php +++ b/tests/phpunit/tests/filters.php @@ -293,4 +293,25 @@ class Tests_Filters extends WP_UnitTestCase { remove_all_filters( $tag, 12 ); $this->assertFalse( has_filter( $tag ) ); } + + /** + * @ticket 29070 + */ + function test_has_filter_doesnt_reset_wp_filter() { + add_action( 'action_test_has_filter_doesnt_reset_wp_filter', '__return_null', 1 ); + add_action( 'action_test_has_filter_doesnt_reset_wp_filter', '__return_null', 2 ); + add_action( 'action_test_has_filter_doesnt_reset_wp_filter', '__return_null', 3 ); + add_action( 'action_test_has_filter_doesnt_reset_wp_filter', array( $this, '_action_test_has_filter_doesnt_reset_wp_filter' ), 4 ); + + do_action( 'action_test_has_filter_doesnt_reset_wp_filter' ); + } + function _action_test_has_filter_doesnt_reset_wp_filter() { + global $wp_filter; + + has_action( 'action_test_has_filter_doesnt_reset_wp_filter', '_function_that_doesnt_exist' ); + + $filters = current( $wp_filter['action_test_has_filter_doesnt_reset_wp_filter'] ); + $the_ = current( $filters ); + $this->assertEquals( $the_['function'], array( $this, '_action_test_has_filter_doesnt_reset_wp_filter' ) ); + } }