Make WordPress Core

Changeset 55025


Ignore:
Timestamp:
01/02/2023 12:28:02 AM (16 months ago)
Author:
SergeyBiryukov
Message:

Tests: Update the terminology used for filter names in tests_add_filter().

This commit renames the $tag and $function_to_add parameters to match the add_filter() function signature.

Includes:

  • Renaming the $tag parameter to $hook_name.
  • Renaming the $function_to_add parameter to $callback.
  • Synchronizing documentation for:
    • tests_add_filter() and add_filter()
    • _test_filter_build_unique_id() and _wp_filter_build_unique_id()

Follow-up to [760/tests], [38582], [43555], [46801], [50807], [52300], [53804], [53805], [55023].

See #56793.

File:
1 edited

Legend:

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

    r55023 r55025  
    3838 * Adds hooks before loading WP.
    3939 *
     40 * @since UT (3.7.0)
     41 *
    4042 * @see add_filter()
    41  *
    42  * @param string   $tag             The name of the filter to hook the $function_to_add callback to.
    43  * @param callable $function_to_add The callback to be run when the filter is applied.
    44  * @param int      $priority        Optional. Used to specify the order in which the functions
    45  *                                  associated with a particular action are executed.
    46  *                                  Lower numbers correspond with earlier execution,
    47  *                                  and functions with the same priority are executed
    48  *                                  in the order in which they were added to the action. Default 10.
    49  * @param int      $accepted_args   Optional. The number of arguments the function accepts. Default 1.
    50  * @return true
    51  */
    52 function tests_add_filter( $tag, $function_to_add, $priority = 10, $accepted_args = 1 ) {
     43 * @global WP_Hook[] $wp_filter A multidimensional array of all hooks and the callbacks hooked to them.
     44 *
     45 * @param string   $hook_name     The name of the filter to add the callback to.
     46 * @param callable $callback      The callback to be run when the filter is applied.
     47 * @param int      $priority      Optional. Used to specify the order in which the functions
     48 *                                associated with a particular action are executed.
     49 *                                Lower numbers correspond with earlier execution,
     50 *                                and functions with the same priority are executed
     51 *                                in the order in which they were added to the action. Default 10.
     52 * @param int      $accepted_args Optional. The number of arguments the function accepts. Default 1.
     53 * @return true Always returns true.
     54 */
     55function tests_add_filter( $hook_name, $callback, $priority = 10, $accepted_args = 1 ) {
    5356    global $wp_filter;
    5457
    5558    if ( function_exists( 'add_filter' ) ) {
    56         add_filter( $tag, $function_to_add, $priority, $accepted_args );
     59        add_filter( $hook_name, $callback, $priority, $accepted_args );
    5760    } else {
    58         $idx = _test_filter_build_unique_id( $tag, $function_to_add, $priority );
    59 
    60         $wp_filter[ $tag ][ $priority ][ $idx ] = array(
    61             'function'      => $function_to_add,
     61        $idx = _test_filter_build_unique_id( $hook_name, $callback, $priority );
     62
     63        $wp_filter[ $hook_name ][ $priority ][ $idx ] = array(
     64            'function'      => $callback,
    6265            'accepted_args' => $accepted_args,
    6366        );
    6467    }
     68
    6569    return true;
    6670}
     
    6973 * Generates a unique function ID based on the given arguments.
    7074 *
     75 * @since UT (3.7.0)
     76 *
    7177 * @see _wp_filter_build_unique_id()
    7278 *
    73  * @param string   $tag      Unused. The name of the filter to build ID for.
    74  * @param callable $callback The function to generate ID for.
    75  * @param int      $priority Unused. The order in which the functions
    76  *                           associated with a particular action are executed.
     79 * @param string                $hook_name Unused. The name of the filter to build ID for.
     80 * @param callable|string|array $callback  The callback to generate ID for. The callback may
     81 *                                         or may not exist.
     82 * @param int                   $priority  Unused. The order in which the functions
     83 *                                         associated with a particular action are executed.
    7784 * @return string Unique function ID for usage as array key.
    7885 */
    79 function _test_filter_build_unique_id( $tag, $callback, $priority ) {
     86function _test_filter_build_unique_id( $hook_name, $callback, $priority ) {
    8087    if ( is_string( $callback ) ) {
    8188        return $callback;
Note: See TracChangeset for help on using the changeset viewer.