<?php /** * The plugin API is located in this file, which allows for creating actions * and filters and hooking functions, and methods. The functions or methods will * then be run when the action or filter is called. * * The API callback examples reference functions, but can be methods of classes. * To hook methods, you'll need to pass an array one of two ways. * * Any of the syntaxes explained in the PHP documentation for the * {@link https://www.php.net/manual/en/language.pseudo-types.php#language.types.callback 'callback'} * type are valid. * * Also see the {@link https://developer.wordpress.org/plugins/ Plugin API} for * more information and examples on how to use a lot of these functions. * * This file should have no external dependencies. * * @package WordPress * @subpackage Plugin * @since 1.5.0 */ // Initialize the filter globals. require __DIR__ . '/class-wp-hook.php'; /** @var WP_Hook[] $wp_filter */ global $wp_filter; /** @var int[] $wp_actions */ global $wp_actions; /** @var int[] $wp_filters */ global $wp_filters; /** @var string[] $wp_current_filter */ global $wp_current_filter; if ( $wp_filter ) { $wp_filter = WP_Hook::build_preinitialized_hooks( $wp_filter ); } else { $wp_filter = array(); } if ( ! isset( $wp_actions ) ) { $wp_actions = array(); } if ( ! isset( $wp_filters ) ) { $wp_filters = array(); } if ( ! isset( $wp_current_filter ) ) { $wp_current_filter = array(); } /** * Adds a callback function to a filter hook. * * WordPress offers filter hooks to allow plugins to modify * various types of internal data at runtime. * * A plugin can modify data by binding a callback to a filter hook. When the filter * is later applied, each bound callback is run in order of priority, and given * the opportunity to modify a value by returning a new value. * * The following example shows how a callback function is bound to a filter hook. * * Note that `$example` is passed to the callback, (maybe) modified, then returned: * * function example_callback( $example ) { * // Maybe modify $example in some way. * return $example; * } * add_filter( 'example_filter', 'example_callback' ); * * Bound callbacks can accept from none to the total number of arguments passed as parameters * in the corresponding apply_filters() call. * * In other words, if an apply_filters() call passes four total arguments, callbacks bound to * it can accept none (the same as 1) of the arguments or up to four. The important part is that * the `$accepted_args` value must reflect the number of arguments the bound callback *actually* * opted to accept. If no arguments were accepted by the callback that is considered to be the * same as accepting 1 argument. For example: * * // Filter call. * $value = apply_filters( 'hook', $value, $arg2, $arg3 ); * * // Accepting zero/one arguments. * function example_callback() { * ... * return 'some value'; * } * add_filter( 'hook', 'example_callback' ); // Where $priority is default 10, $accepted_args is default 1. * * // Accepting two arguments (three possible). * function example_callback( $value, $arg2 ) { * ... * return $maybe_modified_value; * } * add_filter( 'hook', 'example_callback', 10, 2 ); // Where $priority is 10, $accepted_args is 2. * * *Note:* The function will return true whether or not the callback is valid. * It is up to you to take care. This is done for optimization purposes, so * everything is as quick as possible. * * @since 0.71 * * @global WP_Hook[] $wp_filter A multidimensional array of all hooks and the callbacks hooked to them. * * @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. * Lowe