--- a/wp/wp-includes/plugin.php Tue Dec 15 15:52:01 2020 +0100
+++ b/wp/wp-includes/plugin.php Wed Sep 21 18:19:35 2022 +0200
@@ -25,7 +25,13 @@
require __DIR__ . '/class-wp-hook.php';
/** @var WP_Hook[] $wp_filter */
-global $wp_filter, $wp_actions, $wp_current_filter;
+global $wp_filter;
+
+/** @var int[] $wp_actions */
+global $wp_actions;
+
+/** @var string[] $wp_current_filter */
+global $wp_current_filter;
if ( $wp_filter ) {
$wp_filter = WP_Hook::build_preinitialized_hooks( $wp_filter );
@@ -42,7 +48,7 @@
}
/**
- * Hook a function or method to a specific filter action.
+ * Adds a callback function to a filter hook.
*
* WordPress offers filter hooks to allow plugins to modify
* various types of internal data at runtime.
@@ -93,60 +99,36 @@
*
* @since 0.71
*
- * @global array $wp_filter A multidimensional array of all hooks and the callbacks hooked to them.
+ * @global WP_Hook[] $wp_filter A multidimensional array of all hooks and the callbacks hooked to them.
*
- * @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
+ * @param string $hook_name The name of the filter to add the callback to.
+ * @param callable $callback 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 filter 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 filter. Default 10.
+ * @param int $accepted_args Optional. The number of arguments the function accepts. Default 1.
+ * @return true Always returns true.
*/
-function add_filter( $tag, $function_to_add, $priority = 10, $accepted_args = 1 ) {
- global $wp_filter;
- if ( ! isset( $wp_filter[ $tag ] ) ) {
- $wp_filter[ $tag ] = new WP_Hook();
- }
- $wp_filter[ $tag ]->add_filter( $tag, $function_to_add, $priority, $accepted_args );
- return true;
-}
-
-/**
- * Check if any filter has been registered for a hook.
- *
- * @since 2.5.0
- *
- * @global array $wp_filter Stores all of the filters and actions.
- *
- * @param string $tag The name of the filter hook.
- * @param callable|bool $function_to_check Optional. The callback to check for. Default false.
- * @return false|int If $function_to_check is omitted, returns boolean for whether the hook has
- * anything registered. When checking a specific function, the priority of that
- * hook is returned, or false if the function is not attached. When using the
- * $function_to_check argument, this function may return a non-boolean value
- * that evaluates to false (e.g.) 0, so use the === operator for testing the
- * return value.
- */
-function has_filter( $tag, $function_to_check = false ) {
+function add_filter( $hook_name, $callback, $priority = 10, $accepted_args = 1 ) {
global $wp_filter;
- if ( ! isset( $wp_filter[ $tag ] ) ) {
- return false;
+ if ( ! isset( $wp_filter[ $hook_name ] ) ) {
+ $wp_filter[ $hook_name ] = new WP_Hook();
}
- return $wp_filter[ $tag ]->has_filter( $tag, $function_to_check );
+ $wp_filter[ $hook_name ]->add_filter( $hook_name, $callback, $priority, $accepted_args );
+
+ return true;
}
/**
* Calls the callback functions that have been added to a filter hook.
*
- * The callback functions attached to the filter hook are invoked by calling
- * this function. This function can be used to create a new filter hook by
- * simply calling this function with the name of the new hook specified using
- * the `$tag` parameter.
+ * This function invokes all functions attached to filter hook `$hook_name`.
+ * It is possible to create new filter hooks by simply calling this function,
+ * specifying the name of the new hook using the `$hook_name` parameter.
*
* The function also allows for multiple additional arguments to be passed to hooks.
*
@@ -170,40 +152,41 @@
*
* @since 0.71
*
- * @global array $wp_filter Stores all of the filters and actions.
- * @global array $wp_current_filter Stores the list of current filters with the current one last.
+ * @global WP_Hook[] $wp_filter Stores all of the filters and actions.
+ * @global string[] $wp_current_filter Stores the list of current filters with the current one last.
*
- * @param string $tag The name of the filter hook.
- * @param mixed $value The value to filter.
- * @param mixed ...$args Additional parameters to pass to the callback functions.
+ * @param string $hook_name The name of the filter hook.
+ * @param mixed $value The value to filter.
+ * @param mixed ...$args Additional parameters to pass to the callback functions.
* @return mixed The filtered value after all hooked functions are applied to it.
*/
-function apply_filters( $tag, $value ) {
+function apply_filters( $hook_name, $value ) {
global $wp_filter, $wp_current_filter;
$args = func_get_args();
// Do 'all' actions first.
if ( isset( $wp_filter['all'] ) ) {
- $wp_current_filter[] = $tag;
+ $wp_current_filter[] = $hook_name;
_wp_call_all_hook( $args );
}
- if ( ! isset( $wp_filter[ $tag ] ) ) {
+ if ( ! isset( $wp_filter[ $hook_name ] ) ) {
if ( isset( $wp_filter['all'] ) ) {
array_pop( $wp_current_filter );
}
+
return $value;
}
if ( ! isset( $wp_filter['all'] ) ) {
- $wp_current_filter[] = $tag;
+ $wp_current_filter[] = $hook_name;
}
// Don't pass the tag name to WP_Hook.
array_shift( $args );
- $filtered = $wp_filter[ $tag ]->apply_filters( $value, $args );
+ $filtered = $wp_filter[ $hook_name ]->apply_filters( $value, $args );
array_pop( $wp_current_filter );
@@ -216,37 +199,38 @@
* @since 3.0.0
*
* @see apply_filters() This function is identical, but the arguments passed to the
- * functions hooked to `$tag` are supplied using an array.
+ * functions hooked to `$hook_name` are supplied using an array.
*
- * @global array $wp_filter Stores all of the filters and actions.
- * @global array $wp_current_filter Stores the list of current filters with the current one last.
+ * @global WP_Hook[] $wp_filter Stores all of the filters and actions.
+ * @global string[] $wp_current_filter Stores the list of current filters with the current one last.
*
- * @param string $tag The name of the filter hook.
- * @param array $args The arguments supplied to the functions hooked to $tag.
+ * @param string $hook_name The name of the filter hook.
+ * @param array $args The arguments supplied to the functions hooked to `$hook_name`.
* @return mixed The filtered value after all hooked functions are applied to it.
*/
-function apply_filters_ref_array( $tag, $args ) {
+function apply_filters_ref_array( $hook_name, $args ) {
global $wp_filter, $wp_current_filter;
// Do 'all' actions first.
if ( isset( $wp_filter['all'] ) ) {
- $wp_current_filter[] = $tag;
+ $wp_current_filter[] = $hook_name;
$all_args = func_get_args(); // phpcs:ignore PHPCompatibility.FunctionUse.ArgumentFunctionsReportCurrentValue.NeedsInspection
_wp_call_all_hook( $all_args );
}
- if ( ! isset( $wp_filter[ $tag ] ) ) {
+ if ( ! isset( $wp_filter[ $hook_name ] ) ) {
if ( isset( $wp_filter['all'] ) ) {
array_pop( $wp_current_filter );
}
+
return $args[0];
}
if ( ! isset( $wp_filter['all'] ) ) {
- $wp_current_filter[] = $tag;
+ $wp_current_filter[] = $hook_name;
}
- $filtered = $wp_filter[ $tag ]->apply_filters( $args[0], $args );
+ $filtered = $wp_filter[ $hook_name ]->apply_filters( $args[0], $args );
array_pop( $wp_current_filter );
@@ -254,33 +238,61 @@
}
/**
- * Removes a function from a specified filter hook.
+ * Checks if any filter has been registered for a hook.
+ *
+ * When using the `$callback` argument, this function may return a non-boolean value
+ * that evaluates to false (e.g. 0), so use the `===` operator for testing the return value.
+ *
+ * @since 2.5.0
+ *
+ * @global WP_Hook[] $wp_filter Stores all of the filters and actions.
*
- * This function removes a function attached to a specified filter hook. This
- * method can be used to remove default functions attached to a specific filter
+ * @param string $hook_name The name of the filter hook.
+ * @param callable|false $callback Optional. The callback to check for. Default false.
+ * @return bool|int If `$callback` is omitted, returns boolean for whether the hook has
+ * anything registered. When checking a specific function, the priority
+ * of that hook is returned, or false if the function is not attached.
+ */
+function has_filter( $hook_name, $callback = false ) {
+ global $wp_filter;
+
+ if ( ! isset( $wp_filter[ $hook_name ] ) ) {
+ return false;
+ }
+
+ return $wp_filter[ $hook_name ]->has_filter( $hook_name, $callback );
+}
+
+/**
+ * Removes a callback function from a filter hook.
+ *
+ * This can be used to remove default functions attached to a specific filter
* hook and possibly replace them with a substitute.
*
- * To remove a hook, the $function_to_remove and $priority arguments must match
+ * To remove a hook, the `$callback` and `$priority` arguments must match
* when the hook was added. This goes for both filters and actions. No warning
* will be given on removal failure.
*
* @since 1.2.0
*
- * @global array $wp_filter Stores all of the filters and actions.
+ * @global WP_Hook[] $wp_filter Stores all of the filters and actions.
*
- * @param string $tag The filter hook to which the function to be removed is hooked.
- * @param callable $function_to_remove The name of the function which should be removed.
- * @param int $priority Optional. The priority of the function. Default 10.
- * @return bool Whether the function existed before it was removed.
+ * @param string $hook_name The filter hook to which the function to be removed is hooked.
+ * @param callable $callback The name of the function which should be removed.
+ * @param int $priority Optional. The exact priority used when adding the original
+ * filter callback. Default 10.
+ * @return bool Whether the function existed before it was removed.
*/
-function remove_filter( $tag, $function_to_remove, $priority = 10 ) {
+function remove_filter( $hook_name, $callback, $priority = 10 ) {
global $wp_filter;
$r = false;
- if ( isset( $wp_filter[ $tag ] ) ) {
- $r = $wp_filter[ $tag ]->remove_filter( $tag, $function_to_remove, $priority );
- if ( ! $wp_filter[ $tag ]->callbacks ) {
- unset( $wp_filter[ $tag ] );
+
+ if ( isset( $wp_filter[ $hook_name ] ) ) {
+ $r = $wp_filter[ $hook_name ]->remove_filter( $hook_name, $callback, $priority );
+
+ if ( ! $wp_filter[ $hook_name ]->callbacks ) {
+ unset( $wp_filter[ $hook_name ] );
}
}
@@ -288,23 +300,25 @@
}
/**
- * Remove all of the hooks from a filter.
+ * Removes all of the callback functions from a filter hook.
*
* @since 2.7.0
*
- * @global array $wp_filter Stores all of the filters and actions.
+ * @global WP_Hook[] $wp_filter Stores all of the filters and actions.
*
- * @param string $tag The filter to remove hooks from.
- * @param int|bool $priority Optional. The priority number to remove. Default false.
- * @return true True when finished.
+ * @param string $hook_name The filter to remove callbacks from.
+ * @param int|false $priority Optional. The priority number to remove them from.
+ * Default false.
+ * @return true Always returns true.
*/
-function remove_all_filters( $tag, $priority = false ) {
+function remove_all_filters( $hook_name, $priority = false ) {
global $wp_filter;
- if ( isset( $wp_filter[ $tag ] ) ) {
- $wp_filter[ $tag ]->remove_all_filters( $priority );
- if ( ! $wp_filter[ $tag ]->has_filters() ) {
- unset( $wp_filter[ $tag ] );
+ if ( isset( $wp_filter[ $hook_name ] ) ) {
+ $wp_filter[ $hook_name ]->remove_all_filters( $priority );
+
+ if ( ! $wp_filter[ $hook_name ]->has_filters() ) {
+ unset( $wp_filter[ $hook_name ] );
}
}
@@ -312,76 +326,53 @@
}
/**
- * Retrieve the name of the current filter or action.
+ * Retrieves the name of the current filter hook.
*
* @since 2.5.0
*
- * @global array $wp_current_filter Stores the list of current filters with the current one last
+ * @global string[] $wp_current_filter Stores the list of current filters with the current one last
*
- * @return string Hook name of the current filter or action.
+ * @return string Hook name of the current filter.
*/
function current_filter() {
global $wp_current_filter;
+
return end( $wp_current_filter );
}
/**
- * Retrieve the name of the current action.
- *
- * @since 3.9.0
- *
- * @return string Hook name of the current action.
- */
-function current_action() {
- return current_filter();
-}
-
-/**
- * Retrieve the name of a filter currently being processed.
+ * Returns whether or not a filter hook is currently being processed.
*
* The function current_filter() only returns the most recent filter or action
* being executed. did_action() returns true once the action is initially
* processed.
*
- * This function allows detection for any filter currently being
- * executed (despite not being the most recent filter to fire, in the case of
+ * This function allows detection for any filter currently being executed
+ * (regardless of whether it's the most recent filter to fire, in the case of
* hooks called from hook callbacks) to be verified.
*
* @since 3.9.0
*
* @see current_filter()
* @see did_action()
- * @global array $wp_current_filter Current filter.
+ * @global string[] $wp_current_filter Current filter.
*
- * @param null|string $filter Optional. Filter to check. Defaults to null, which
- * checks if any filter is currently being run.
+ * @param null|string $hook_name Optional. Filter hook to check. Defaults to null,
+ * which checks if any filter is currently being run.
* @return bool Whether the filter is currently in the stack.
*/
-function doing_filter( $filter = null ) {
+function doing_filter( $hook_name = null ) {
global $wp_current_filter;
- if ( null === $filter ) {
+ if ( null === $hook_name ) {
return ! empty( $wp_current_filter );
}
- return in_array( $filter, $wp_current_filter, true );
+ return in_array( $hook_name, $wp_current_filter, true );
}
/**
- * Retrieve the name of an action currently being processed.
- *
- * @since 3.9.0
- *
- * @param string|null $action Optional. Action to check. Defaults to null, which checks
- * if any action is currently being run.
- * @return bool Whether the action is currently in the stack.
- */
-function doing_action( $action = null ) {
- return doing_filter( $action );
-}
-
-/**
- * Hooks a function on to a specific action.
+ * Adds a callback function to an action hook.
*
* Actions are the hooks that the WordPress core launches at specific points
* during execution, or when specific events occur. Plugins can specify that
@@ -390,26 +381,26 @@
*
* @since 1.2.0
*
- * @param string $tag The name of the action to which the $function_to_add is hooked.
- * @param callable $function_to_add The name of the function you wish to be called.
+ * @param string $hook_name The name of the action to add the callback to.
+ * @param callable $callback The callback to be run when the action is called.
* @param int $priority Optional. Used to specify the order in which the functions
- * associated with a particular action are executed. Default 10.
+ * 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.
+ * 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 Will always return true.
+ * @return true Always returns true.
*/
-function add_action( $tag, $function_to_add, $priority = 10, $accepted_args = 1 ) {
- return add_filter( $tag, $function_to_add, $priority, $accepted_args );
+function add_action( $hook_name, $callback, $priority = 10, $accepted_args = 1 ) {
+ return add_filter( $hook_name, $callback, $priority, $accepted_args );
}
/**
- * Execute functions hooked on a specific action hook.
+ * Calls the callback functions that have been added to an action hook.
*
- * This function invokes all functions attached to action hook `$tag`. It is
- * possible to create new action hooks by simply calling this function,
- * specifying the name of the new hook using the `$tag` parameter.
+ * This function invokes all functions attached to action hook `$hook_name`.
+ * It is possible to create new action hooks by simply calling this function,
+ * specifying the name of the new hook using the `$hook_name` parameter.
*
* You can pass extra arguments to the hooks, much like you can with `apply_filters()`.
*
@@ -433,39 +424,40 @@
* @since 5.3.0 Formalized the existing and already documented `...$arg` parameter
* by adding it to the function signature.
*
- * @global array $wp_filter Stores all of the filters and actions.
- * @global array $wp_actions Increments the amount of times action was triggered.
- * @global array $wp_current_filter Stores the list of current filters with the current one last.
+ * @global WP_Hook[] $wp_filter Stores all of the filters and actions.
+ * @global int[] $wp_actions Stores the number of times each action was triggered.
+ * @global string[] $wp_current_filter Stores the list of current filters with the current one last.
*
- * @param string $tag The name of the action to be executed.
- * @param mixed ...$arg Optional. Additional arguments which are passed on to the
- * functions hooked to the action. Default empty.
+ * @param string $hook_name The name of the action to be executed.
+ * @param mixed ...$arg Optional. Additional arguments which are passed on to the
+ * functions hooked to the action. Default empty.
*/
-function do_action( $tag, ...$arg ) {
+function do_action( $hook_name, ...$arg ) {
global $wp_filter, $wp_actions, $wp_current_filter;
- if ( ! isset( $wp_actions[ $tag ] ) ) {
- $wp_actions[ $tag ] = 1;
+ if ( ! isset( $wp_actions[ $hook_name ] ) ) {
+ $wp_actions[ $hook_name ] = 1;
} else {
- ++$wp_actions[ $tag ];
+ ++$wp_actions[ $hook_name ];
}
// Do 'all' actions first.
if ( isset( $wp_filter['all'] ) ) {
- $wp_current_filter[] = $tag;
+ $wp_current_filter[] = $hook_name;
$all_args = func_get_args(); // phpcs:ignore PHPCompatibility.FunctionUse.ArgumentFunctionsReportCurrentValue.NeedsInspection
_wp_call_all_hook( $all_args );
}
- if ( ! isset( $wp_filter[ $tag ] ) ) {
+ if ( ! isset( $wp_filter[ $hook_name ] ) ) {
if ( isset( $wp_filter['all'] ) ) {
array_pop( $wp_current_filter );
}
+
return;
}
if ( ! isset( $wp_filter['all'] ) ) {
- $wp_current_filter[] = $tag;
+ $wp_current_filter[] = $hook_name;
}
if ( empty( $arg ) ) {
@@ -475,126 +467,157 @@
$arg[0] = $arg[0][0];
}
- $wp_filter[ $tag ]->do_action( $arg );
+ $wp_filter[ $hook_name ]->do_action( $arg );
array_pop( $wp_current_filter );
}
/**
- * Retrieve the number of times an action is fired.
- *
- * @since 2.1.0
- *
- * @global array $wp_actions Increments the amount of times action was triggered.
- *
- * @param string $tag The name of the action hook.
- * @return int The number of times action hook $tag is fired.
- */
-function did_action( $tag ) {
- global $wp_actions;
-
- if ( ! isset( $wp_actions[ $tag ] ) ) {
- return 0;
- }
-
- return $wp_actions[ $tag ];
-}
-
-/**
* Calls the callback functions that have been added to an action hook, specifying arguments in an array.
*
* @since 2.1.0
*
* @see do_action() This function is identical, but the arguments passed to the
- * functions hooked to `$tag` are supplied using an array.
- * @global array $wp_filter Stores all of the filters and actions.
- * @global array $wp_actions Increments the amount of times action was triggered.
- * @global array $wp_current_filter Stores the list of current filters with the current one last.
+ * functions hooked to `$hook_name` are supplied using an array.
*
- * @param string $tag The name of the action to be executed.
- * @param array $args The arguments supplied to the functions hooked to `$tag`.
+ * @global WP_Hook[] $wp_filter Stores all of the filters and actions.
+ * @global int[] $wp_actions Stores the number of times each action was triggered.
+ * @global string[] $wp_current_filter Stores the list of current filters with the current one last.
+ *
+ * @param string $hook_name The name of the action to be executed.
+ * @param array $args The arguments supplied to the functions hooked to `$hook_name`.
*/
-function do_action_ref_array( $tag, $args ) {
+function do_action_ref_array( $hook_name, $args ) {
global $wp_filter, $wp_actions, $wp_current_filter;
- if ( ! isset( $wp_actions[ $tag ] ) ) {
- $wp_actions[ $tag ] = 1;
+ if ( ! isset( $wp_actions[ $hook_name ] ) ) {
+ $wp_actions[ $hook_name ] = 1;
} else {
- ++$wp_actions[ $tag ];
+ ++$wp_actions[ $hook_name ];
}
// Do 'all' actions first.
if ( isset( $wp_filter['all'] ) ) {
- $wp_current_filter[] = $tag;
+ $wp_current_filter[] = $hook_name;
$all_args = func_get_args(); // phpcs:ignore PHPCompatibility.FunctionUse.ArgumentFunctionsReportCurrentValue.NeedsInspection
_wp_call_all_hook( $all_args );
}
- if ( ! isset( $wp_filter[ $tag ] ) ) {
+ if ( ! isset( $wp_filter[ $hook_name ] ) ) {
if ( isset( $wp_filter['all'] ) ) {
array_pop( $wp_current_filter );
}
+
return;
}
if ( ! isset( $wp_filter['all'] ) ) {
- $wp_current_filter[] = $tag;
+ $wp_current_filter[] = $hook_name;
}
- $wp_filter[ $tag ]->do_action( $args );
+ $wp_filter[ $hook_name ]->do_action( $args );
array_pop( $wp_current_filter );
}
/**
- * Check if any action has been registered for a hook.
+ * Checks if any action has been registered for a hook.
+ *
+ * When using the `$callback` argument, this function may return a non-boolean value
+ * that evaluates to false (e.g. 0), so use the `===` operator for testing the return value.
*
* @since 2.5.0
*
* @see has_filter() has_action() is an alias of has_filter().
*
- * @param string $tag The name of the action hook.
- * @param callable|bool $function_to_check Optional. The callback to check for. Default false.
- * @return bool|int If $function_to_check is omitted, returns boolean for whether the hook has
- * anything registered. When checking a specific function, the priority of that
- * hook is returned, or false if the function is not attached. When using the
- * $function_to_check argument, this function may return a non-boolean value
- * that evaluates to false (e.g.) 0, so use the === operator for testing the
- * return value.
+ * @param string $hook_name The name of the action hook.
+ * @param callable|false $callback Optional. The callback to check for. Default false.
+ * @return bool|int If `$callback` is omitted, returns boolean for whether the hook has
+ * anything registered. When checking a specific function, the priority
+ * of that hook is returned, or false if the function is not attached.
*/
-function has_action( $tag, $function_to_check = false ) {
- return has_filter( $tag, $function_to_check );
+function has_action( $hook_name, $callback = false ) {
+ return has_filter( $hook_name, $callback );
+}
+
+/**
+ * Removes a callback function from an action hook.
+ *
+ * This can be used to remove default functions attached to a specific action
+ * hook and possibly replace them with a substitute.
+ *
+ * To remove a hook, the `$callback` and `$priority` arguments must match
+ * when the hook was added. This goes for both filters and actions. No warning
+ * will be given on removal failure.
+ *
+ * @since 1.2.0
+ *
+ * @param string $hook_name The action hook to which the function to be removed is hooked.
+ * @param callable $callback The name of the function which should be removed.
+ * @param int $priority Optional. The exact priority used when adding the original
+ * action callback. Default 10.
+ * @return bool Whether the function is removed.
+ */
+function remove_action( $hook_name, $callback, $priority = 10 ) {
+ return remove_filter( $hook_name, $callback, $priority );
}
/**
- * Removes a function from a specified action hook.
+ * Removes all of the callback functions from an action hook.
*
- * This function removes a function attached to a specified action hook. This
- * method can be used to remove default functions attached to a specific filter
- * hook and possibly replace them with a substitute.
- *
- * @since 1.2.0
+ * @since 2.7.0
*
- * @param string $tag The action hook to which the function to be removed is hooked.
- * @param callable $function_to_remove The name of the function which should be removed.
- * @param int $priority Optional. The priority of the function. Default 10.
- * @return bool Whether the function is removed.
+ * @param string $hook_name The action to remove callbacks from.
+ * @param int|false $priority Optional. The priority number to remove them from.
+ * Default false.
+ * @return true Always returns true.
*/
-function remove_action( $tag, $function_to_remove, $priority = 10 ) {
- return remove_filter( $tag, $function_to_remove, $priority );
+function remove_all_actions( $hook_name, $priority = false ) {
+ return remove_all_filters( $hook_name, $priority );
+}
+
+/**
+ * Retrieves the name of the current action hook.
+ *
+ * @since 3.9.0
+ *
+ * @return string Hook name of the current action.
+ */
+function current_action() {
+ return current_filter();
}
/**
- * Remove all of the hooks from an action.
+ * Returns whether or not an action hook is currently being processed.
+ *
+ * @since 3.9.0
*
- * @since 2.7.0
+ * @param string|null $hook_name Optional. Action hook to check. Defaults to null,
+ * which checks if any action is currently being run.
+ * @return bool Whether the action is currently in the stack.
+ */
+function doing_action( $hook_name = null ) {
+ return doing_filter( $hook_name );
+}
+
+/**
+ * Retrieves the number of times an action has been fired during the current request.
*
- * @param string $tag The action to remove hooks from.
- * @param int|bool $priority The priority number to remove them from. Default false.
- * @return true True when finished.
+ * @since 2.1.0
+ *
+ * @global int[] $wp_actions Stores the number of times each action was triggered.
+ *
+ * @param string $hook_name The name of the action hook.
+ * @return int The number of times the action hook has been fired.
*/
-function remove_all_actions( $tag, $priority = false ) {
- return remove_all_filters( $tag, $priority );
+function did_action( $hook_name ) {
+ global $wp_actions;
+
+ if ( ! isset( $wp_actions[ $hook_name ] ) ) {
+ return 0;
+ }
+
+ return $wp_actions[ $hook_name ];
}
/**
@@ -617,20 +640,20 @@
*
* @see _deprecated_hook()
*
- * @param string $tag The name of the filter hook.
+ * @param string $hook_name The name of the filter hook.
* @param array $args Array of additional function arguments to be passed to apply_filters().
* @param string $version The version of WordPress that deprecated the hook.
* @param string $replacement Optional. The hook that should have been used. Default empty.
* @param string $message Optional. A message regarding the change. Default empty.
*/
-function apply_filters_deprecated( $tag, $args, $version, $replacement = '', $message = '' ) {
- if ( ! has_filter( $tag ) ) {
+function apply_filters_deprecated( $hook_name, $args, $version, $replacement = '', $message = '' ) {
+ if ( ! has_filter( $hook_name ) ) {
return $args[0];
}
- _deprecated_hook( $tag, $version, $replacement, $message );
+ _deprecated_hook( $hook_name, $version, $replacement, $message );
- return apply_filters_ref_array( $tag, $args );
+ return apply_filters_ref_array( $hook_name, $args );
}
/**
@@ -644,20 +667,20 @@
*
* @see _deprecated_hook()
*
- * @param string $tag The name of the action hook.
+ * @param string $hook_name The name of the action hook.
* @param array $args Array of additional function arguments to be passed to do_action().
* @param string $version The version of WordPress that deprecated the hook.
* @param string $replacement Optional. The hook that should have been used. Default empty.
* @param string $message Optional. A message regarding the change. Default empty.
*/
-function do_action_deprecated( $tag, $args, $version, $replacement = '', $message = '' ) {
- if ( ! has_action( $tag ) ) {
+function do_action_deprecated( $hook_name, $args, $version, $replacement = '', $message = '' ) {
+ if ( ! has_action( $hook_name ) ) {
return;
}
- _deprecated_hook( $tag, $version, $replacement, $message );
+ _deprecated_hook( $hook_name, $version, $replacement, $message );
- do_action_ref_array( $tag, $args );
+ do_action_ref_array( $hook_name, $args );
}
//
@@ -683,6 +706,7 @@
$file = wp_normalize_path( $file );
arsort( $wp_plugin_paths );
+
foreach ( $wp_plugin_paths as $dir => $realdir ) {
if ( strpos( $file, $realdir ) === 0 ) {
$file = $dir . substr( $file, strlen( $realdir ) );
@@ -717,6 +741,7 @@
// Normalize, but store as static to avoid recalculation of a constant value.
static $wp_plugin_path = null, $wpmu_plugin_path = null;
+
if ( ! isset( $wp_plugin_path ) ) {
$wp_plugin_path = wp_normalize_path( WP_PLUGIN_DIR );
$wpmu_plugin_path = wp_normalize_path( WPMU_PLUGIN_DIR );
@@ -776,15 +801,15 @@
* @since 2.0.0
*
* @param string $file The filename of the plugin including the path.
- * @param callable $function The function hooked to the 'activate_PLUGIN' action.
+ * @param callable $callback The function hooked to the 'activate_PLUGIN' action.
*/
-function register_activation_hook( $file, $function ) {
+function register_activation_hook( $file, $callback ) {
$file = plugin_basename( $file );
- add_action( 'activate_' . $file, $function );
+ add_action( 'activate_' . $file, $callback );
}
/**
- * Set the deactivation hook for a plugin.
+ * Sets the deactivation hook for a plugin.
*
* When a plugin is deactivated, the action 'deactivate_PLUGINNAME' hook is
* called. In the name of this hook, PLUGINNAME is replaced with the name
@@ -799,15 +824,15 @@
* @since 2.0.0
*
* @param string $file The filename of the plugin including the path.
- * @param callable $function The function hooked to the 'deactivate_PLUGIN' action.
+ * @param callable $callback The function hooked to the 'deactivate_PLUGIN' action.
*/
-function register_deactivation_hook( $file, $function ) {
+function register_deactivation_hook( $file, $callback ) {
$file = plugin_basename( $file );
- add_action( 'deactivate_' . $file, $function );
+ add_action( 'deactivate_' . $file, $callback );
}
/**
- * Set the uninstallation hook for a plugin.
+ * Sets the uninstallation hook for a plugin.
*
* Registers the uninstall hook that will be called when the user clicks on the
* uninstall link that calls for the plugin to uninstall itself. The link won't
@@ -845,6 +870,7 @@
*/
$uninstallable_plugins = (array) get_option( 'uninstall_plugins' );
$plugin_basename = plugin_basename( $file );
+
if ( ! isset( $uninstallable_plugins[ $plugin_basename ] ) || $uninstallable_plugins[ $plugin_basename ] !== $callback ) {
$uninstallable_plugins[ $plugin_basename ] = $callback;
update_option( 'uninstall_plugins', $uninstallable_plugins );
@@ -852,7 +878,7 @@
}
/**
- * Call the 'all' hook, which will process the functions hooked into it.
+ * Calls the 'all' hook, which will process the functions hooked into it.
*
* The 'all' hook passes all of the arguments or parameters that were used for
* the hook, which this function was called for.
@@ -865,7 +891,7 @@
* @since 2.5.0
* @access private
*
- * @global array $wp_filter Stores all of the filters and actions.
+ * @global WP_Hook[] $wp_filter Stores all of the filters and actions.
*
* @param array $args The collected parameters from the hook that was called.
*/
@@ -876,7 +902,7 @@
}
/**
- * Build Unique ID for storage and retrieval.
+ * Builds Unique ID for storage and retrieval.
*
* The old way to serialize the callback caused issues and this function is the
* solution. It works by checking for objects and creating a new property in
@@ -896,33 +922,33 @@
*
* @since 2.2.3
* @since 5.3.0 Removed workarounds for spl_object_hash().
- * `$tag` and `$priority` are no longer used,
+ * `$hook_name` and `$priority` are no longer used,
* and the function always returns a string.
* @access private
*
- * @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.
+ * @param string $hook_name Unused. The name of the filter to build ID for.
+ * @param callable $callback 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 _wp_filter_build_unique_id( $tag, $function, $priority ) {
- if ( is_string( $function ) ) {
- return $function;
+function _wp_filter_build_unique_id( $hook_name, $callback, $priority ) {
+ if ( is_string( $callback ) ) {
+ return $callback;
}
- if ( is_object( $function ) ) {
+ if ( is_object( $callback ) ) {
// Closures are currently implemented as objects.
- $function = array( $function, '' );
+ $callback = array( $callback, '' );
} else {
- $function = (array) $function;
+ $callback = (array) $callback;
}
- if ( is_object( $function[0] ) ) {
+ if ( is_object( $callback[0] ) ) {
// Object class calling.
- return spl_object_hash( $function[0] ) . $function[1];
- } elseif ( is_string( $function[0] ) ) {
+ return spl_object_hash( $callback[0] ) . $callback[1];
+ } elseif ( is_string( $callback[0] ) ) {
// Static calling.
- return $function[0] . '::' . $function[1];
+ return $callback[0] . '::' . $callback[1];
}
}