Docs: Correct @param type for the function parameter in tests_add_filter() and _test_filter_build_unique_id().

Synchronize documentation for `add_filter()`, `tests_add_filter()`, `_wp_filter_build_unique_id()`, `_test_filter_build_unique_id()`.

Add a note that `$tag` and `$priority` are no longer used in `_wp_filter_build_unique_id()` since [46220], and the function always returns a string now.

Props donmhico, remcotolsma, SergeyBiryukov.
Fixes #47407. See #48303.

git-svn-id: https://develop.svn.wordpress.org/trunk@46801 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Sergey Biryukov
2019-11-29 21:40:58 +00:00
parent a03bb54546
commit 890bd870e8
3 changed files with 56 additions and 46 deletions
+22 -11
View File
@@ -38,11 +38,17 @@ function tests_reset__SERVER() { // phpcs:ignore WordPress.NamingConventions.Val
/**
* Adds hooks before loading WP.
*
* @param string $tag The name for the filter to add.
* @param object|array $function_to_add The function/callback to execute on call.
* @param int $priority The priority.
* @param int $accepted_args The amount of accepted arguments.
* @return bool Always true.
* @see add_filter()
*
* @param string $tag The name of the filter to hook the $function_to_add callback to.
* @param callable $function_to_add The callback to be run when the filter is applied.
* @param int $priority Optional. Used to specify the order in which the functions
* associated with a particular action are executed.
* Lower numbers correspond with earlier execution,
* and functions with the same priority are executed
* in the order in which they were added to the action. Default 10.
* @param int $accepted_args Optional. The number of arguments the function accepts. Default 1.
* @return true
*/
function tests_add_filter( $tag, $function_to_add, $priority = 10, $accepted_args = 1 ) {
global $wp_filter;
@@ -50,7 +56,8 @@ function tests_add_filter( $tag, $function_to_add, $priority = 10, $accepted_arg
if ( function_exists( 'add_filter' ) ) {
add_filter( $tag, $function_to_add, $priority, $accepted_args );
} else {
$idx = _test_filter_build_unique_id( $tag, $function_to_add, $priority );
$idx = _test_filter_build_unique_id( $tag, $function_to_add, $priority );
$wp_filter[ $tag ][ $priority ][ $idx ] = array(
'function' => $function_to_add,
'accepted_args' => $accepted_args,
@@ -62,10 +69,13 @@ function tests_add_filter( $tag, $function_to_add, $priority = 10, $accepted_arg
/**
* Generates a unique function ID based on the given arguments.
*
* @param string $tag Unused. The name of the filter to build ID for.
* @param object|array $function The function to generate ID for.
* @param int $priority Unused. The priority.
* @return string Unique function ID.
* @see _wp_filter_build_unique_id()
*
* @param string $tag Unused. The name of the filter to build ID for.
* @param callable $function The function to generate ID for.
* @param int $priority Unused. The order in which the functions
* associated with a particular action are executed.
* @return string Unique function ID for usage as array key.
*/
function _test_filter_build_unique_id( $tag, $function, $priority ) {
if ( is_string( $function ) ) {
@@ -80,9 +90,10 @@ function _test_filter_build_unique_id( $tag, $function, $priority ) {
}
if ( is_object( $function[0] ) ) {
// Object class calling.
return spl_object_hash( $function[0] ) . $function[1];
} elseif ( is_string( $function[0] ) ) {
// Static Calling.
// Static calling.
return $function[0] . $function[1];
}
}