Make WordPress Core

Changeset 38582


Ignore:
Timestamp:
09/09/2016 12:33:52 AM (8 years ago)
Author:
pento
Message:

Tests: Use add_filter() when it's available.

The tests_add_filter() helper function directly manipulates the $wp_filter global, instead of using add_filter(). We can use add_filter() when it's available, and fall back to manipulating $wp_filter when it isn't, relying on the $wp_filter bootstrap code at the top of plugin.php to handle conversion.

Props boonebgorges, dd32 and pento: WordPress Thought Leadership Triumvirate.
Fixes #17817.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/includes/functions.php

    r38571 r38582  
    2424    global $wp_filter;
    2525
    26     $idx = _test_filter_build_unique_id($tag, $function_to_add, $priority);
    27     $wp_filter[$tag][$priority][$idx] = array('function' => $function_to_add, 'accepted_args' => $accepted_args);
     26    if ( function_exists( 'add_filter' ) ) {
     27        add_filter( $tag, $function_to_add, $priority, $accepted_args );
     28    } else {
     29        $idx = _test_filter_build_unique_id($tag, $function_to_add, $priority);
     30        $wp_filter[$tag][$priority][$idx] = array('function' => $function_to_add, 'accepted_args' => $accepted_args);
     31    }
    2832    return true;
    2933}
Note: See TracChangeset for help on using the changeset viewer.