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' ) ); + } }