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
This commit is contained in:
Andrew Nacin 2014-09-02 06:49:11 +00:00
parent 1cde8312b6
commit d8b80c3254
2 changed files with 22 additions and 0 deletions

View File

@ -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 ] );

View File

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