Edit File by line
/home/barbar84/www/wp-inclu...
File: plugin.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* The plugin API is located in this file, which allows for creating actions
[2] Fix | Delete
* and filters and hooking functions, and methods. The functions or methods will
[3] Fix | Delete
* then be run when the action or filter is called.
[4] Fix | Delete
*
[5] Fix | Delete
* The API callback examples reference functions, but can be methods of classes.
[6] Fix | Delete
* To hook methods, you'll need to pass an array one of two ways.
[7] Fix | Delete
*
[8] Fix | Delete
* Any of the syntaxes explained in the PHP documentation for the
[9] Fix | Delete
* {@link https://www.php.net/manual/en/language.pseudo-types.php#language.types.callback 'callback'}
[10] Fix | Delete
* type are valid.
[11] Fix | Delete
*
[12] Fix | Delete
* Also see the {@link https://developer.wordpress.org/plugins/ Plugin API} for
[13] Fix | Delete
* more information and examples on how to use a lot of these functions.
[14] Fix | Delete
*
[15] Fix | Delete
* This file should have no external dependencies.
[16] Fix | Delete
*
[17] Fix | Delete
* @package WordPress
[18] Fix | Delete
* @subpackage Plugin
[19] Fix | Delete
* @since 1.5.0
[20] Fix | Delete
*/
[21] Fix | Delete
[22] Fix | Delete
// Initialize the filter globals.
[23] Fix | Delete
require __DIR__ . '/class-wp-hook.php';
[24] Fix | Delete
[25] Fix | Delete
/** @var WP_Hook[] $wp_filter */
[26] Fix | Delete
global $wp_filter;
[27] Fix | Delete
[28] Fix | Delete
/** @var int[] $wp_actions */
[29] Fix | Delete
global $wp_actions;
[30] Fix | Delete
[31] Fix | Delete
/** @var string[] $wp_current_filter */
[32] Fix | Delete
global $wp_current_filter;
[33] Fix | Delete
[34] Fix | Delete
if ( $wp_filter ) {
[35] Fix | Delete
$wp_filter = WP_Hook::build_preinitialized_hooks( $wp_filter );
[36] Fix | Delete
} else {
[37] Fix | Delete
$wp_filter = array();
[38] Fix | Delete
}
[39] Fix | Delete
[40] Fix | Delete
if ( ! isset( $wp_actions ) ) {
[41] Fix | Delete
$wp_actions = array();
[42] Fix | Delete
}
[43] Fix | Delete
[44] Fix | Delete
if ( ! isset( $wp_current_filter ) ) {
[45] Fix | Delete
$wp_current_filter = array();
[46] Fix | Delete
}
[47] Fix | Delete
[48] Fix | Delete
/**
[49] Fix | Delete
* Hook a function or method to a specific filter action.
[50] Fix | Delete
*
[51] Fix | Delete
* WordPress offers filter hooks to allow plugins to modify
[52] Fix | Delete
* various types of internal data at runtime.
[53] Fix | Delete
*
[54] Fix | Delete
* A plugin can modify data by binding a callback to a filter hook. When the filter
[55] Fix | Delete
* is later applied, each bound callback is run in order of priority, and given
[56] Fix | Delete
* the opportunity to modify a value by returning a new value.
[57] Fix | Delete
*
[58] Fix | Delete
* The following example shows how a callback function is bound to a filter hook.
[59] Fix | Delete
*
[60] Fix | Delete
* Note that `$example` is passed to the callback, (maybe) modified, then returned:
[61] Fix | Delete
*
[62] Fix | Delete
* function example_callback( $example ) {
[63] Fix | Delete
* // Maybe modify $example in some way.
[64] Fix | Delete
* return $example;
[65] Fix | Delete
* }
[66] Fix | Delete
* add_filter( 'example_filter', 'example_callback' );
[67] Fix | Delete
*
[68] Fix | Delete
* Bound callbacks can accept from none to the total number of arguments passed as parameters
[69] Fix | Delete
* in the corresponding apply_filters() call.
[70] Fix | Delete
*
[71] Fix | Delete
* In other words, if an apply_filters() call passes four total arguments, callbacks bound to
[72] Fix | Delete
* it can accept none (the same as 1) of the arguments or up to four. The important part is that
[73] Fix | Delete
* the `$accepted_args` value must reflect the number of arguments the bound callback *actually*
[74] Fix | Delete
* opted to accept. If no arguments were accepted by the callback that is considered to be the
[75] Fix | Delete
* same as accepting 1 argument. For example:
[76] Fix | Delete
*
[77] Fix | Delete
* // Filter call.
[78] Fix | Delete
* $value = apply_filters( 'hook', $value, $arg2, $arg3 );
[79] Fix | Delete
*
[80] Fix | Delete
* // Accepting zero/one arguments.
[81] Fix | Delete
* function example_callback() {
[82] Fix | Delete
* ...
[83] Fix | Delete
* return 'some value';
[84] Fix | Delete
* }
[85] Fix | Delete
* add_filter( 'hook', 'example_callback' ); // Where $priority is default 10, $accepted_args is default 1.
[86] Fix | Delete
*
[87] Fix | Delete
* // Accepting two arguments (three possible).
[88] Fix | Delete
* function example_callback( $value, $arg2 ) {
[89] Fix | Delete
* ...
[90] Fix | Delete
* return $maybe_modified_value;
[91] Fix | Delete
* }
[92] Fix | Delete
* add_filter( 'hook', 'example_callback', 10, 2 ); // Where $priority is 10, $accepted_args is 2.
[93] Fix | Delete
*
[94] Fix | Delete
* *Note:* The function will return true whether or not the callback is valid.
[95] Fix | Delete
* It is up to you to take care. This is done for optimization purposes, so
[96] Fix | Delete
* everything is as quick as possible.
[97] Fix | Delete
*
[98] Fix | Delete
* @since 0.71
[99] Fix | Delete
*
[100] Fix | Delete
* @global WP_Hook[] $wp_filter A multidimensional array of all hooks and the callbacks hooked to them.
[101] Fix | Delete
*
[102] Fix | Delete
* @param string $tag The name of the filter to hook the $function_to_add callback to.
[103] Fix | Delete
* @param callable $function_to_add The callback to be run when the filter is applied.
[104] Fix | Delete
* @param int $priority Optional. Used to specify the order in which the functions
[105] Fix | Delete
* associated with a particular action are executed.
[106] Fix | Delete
* Lower numbers correspond with earlier execution,
[107] Fix | Delete
* and functions with the same priority are executed
[108] Fix | Delete
* in the order in which they were added to the action. Default 10.
[109] Fix | Delete
* @param int $accepted_args Optional. The number of arguments the function accepts. Default 1.
[110] Fix | Delete
* @return true
[111] Fix | Delete
*/
[112] Fix | Delete
function add_filter( $tag, $function_to_add, $priority = 10, $accepted_args = 1 ) {
[113] Fix | Delete
global $wp_filter;
[114] Fix | Delete
if ( ! isset( $wp_filter[ $tag ] ) ) {
[115] Fix | Delete
$wp_filter[ $tag ] = new WP_Hook();
[116] Fix | Delete
}
[117] Fix | Delete
$wp_filter[ $tag ]->add_filter( $tag, $function_to_add, $priority, $accepted_args );
[118] Fix | Delete
return true;
[119] Fix | Delete
}
[120] Fix | Delete
[121] Fix | Delete
/**
[122] Fix | Delete
* Checks if any filter has been registered for a hook.
[123] Fix | Delete
*
[124] Fix | Delete
* When using the `$function_to_check` argument, this function may return a non-boolean value
[125] Fix | Delete
* that evaluates to false (e.g. 0), so use the `===` operator for testing the return value.
[126] Fix | Delete
*
[127] Fix | Delete
* @since 2.5.0
[128] Fix | Delete
*
[129] Fix | Delete
* @global WP_Hook[] $wp_filter Stores all of the filters and actions.
[130] Fix | Delete
*
[131] Fix | Delete
* @param string $tag The name of the filter hook.
[132] Fix | Delete
* @param callable|false $function_to_check Optional. The callback to check for. Default false.
[133] Fix | Delete
* @return bool|int If `$function_to_check` is omitted, returns boolean for whether the hook has
[134] Fix | Delete
* anything registered. When checking a specific function, the priority of that
[135] Fix | Delete
* hook is returned, or false if the function is not attached.
[136] Fix | Delete
*/
[137] Fix | Delete
function has_filter( $tag, $function_to_check = false ) {
[138] Fix | Delete
global $wp_filter;
[139] Fix | Delete
[140] Fix | Delete
if ( ! isset( $wp_filter[ $tag ] ) ) {
[141] Fix | Delete
return false;
[142] Fix | Delete
}
[143] Fix | Delete
[144] Fix | Delete
return $wp_filter[ $tag ]->has_filter( $tag, $function_to_check );
[145] Fix | Delete
}
[146] Fix | Delete
[147] Fix | Delete
/**
[148] Fix | Delete
* Calls the callback functions that have been added to a filter hook.
[149] Fix | Delete
*
[150] Fix | Delete
* The callback functions attached to the filter hook are invoked by calling
[151] Fix | Delete
* this function. This function can be used to create a new filter hook by
[152] Fix | Delete
* simply calling this function with the name of the new hook specified using
[153] Fix | Delete
* the `$tag` parameter.
[154] Fix | Delete
*
[155] Fix | Delete
* The function also allows for multiple additional arguments to be passed to hooks.
[156] Fix | Delete
*
[157] Fix | Delete
* Example usage:
[158] Fix | Delete
*
[159] Fix | Delete
* // The filter callback function.
[160] Fix | Delete
* function example_callback( $string, $arg1, $arg2 ) {
[161] Fix | Delete
* // (maybe) modify $string.
[162] Fix | Delete
* return $string;
[163] Fix | Delete
* }
[164] Fix | Delete
* add_filter( 'example_filter', 'example_callback', 10, 3 );
[165] Fix | Delete
*
[166] Fix | Delete
* /*
[167] Fix | Delete
* * Apply the filters by calling the 'example_callback()' function
[168] Fix | Delete
* * that's hooked onto `example_filter` above.
[169] Fix | Delete
* *
[170] Fix | Delete
* * - 'example_filter' is the filter hook.
[171] Fix | Delete
* * - 'filter me' is the value being filtered.
[172] Fix | Delete
* * - $arg1 and $arg2 are the additional arguments passed to the callback.
[173] Fix | Delete
* $value = apply_filters( 'example_filter', 'filter me', $arg1, $arg2 );
[174] Fix | Delete
*
[175] Fix | Delete
* @since 0.71
[176] Fix | Delete
*
[177] Fix | Delete
* @global WP_Hook[] $wp_filter Stores all of the filters and actions.
[178] Fix | Delete
* @global string[] $wp_current_filter Stores the list of current filters with the current one last.
[179] Fix | Delete
*
[180] Fix | Delete
* @param string $tag The name of the filter hook.
[181] Fix | Delete
* @param mixed $value The value to filter.
[182] Fix | Delete
* @param mixed ...$args Additional parameters to pass to the callback functions.
[183] Fix | Delete
* @return mixed The filtered value after all hooked functions are applied to it.
[184] Fix | Delete
*/
[185] Fix | Delete
function apply_filters( $tag, $value ) {
[186] Fix | Delete
global $wp_filter, $wp_current_filter;
[187] Fix | Delete
[188] Fix | Delete
$args = func_get_args();
[189] Fix | Delete
[190] Fix | Delete
// Do 'all' actions first.
[191] Fix | Delete
if ( isset( $wp_filter['all'] ) ) {
[192] Fix | Delete
$wp_current_filter[] = $tag;
[193] Fix | Delete
_wp_call_all_hook( $args );
[194] Fix | Delete
}
[195] Fix | Delete
[196] Fix | Delete
if ( ! isset( $wp_filter[ $tag ] ) ) {
[197] Fix | Delete
if ( isset( $wp_filter['all'] ) ) {
[198] Fix | Delete
array_pop( $wp_current_filter );
[199] Fix | Delete
}
[200] Fix | Delete
return $value;
[201] Fix | Delete
}
[202] Fix | Delete
[203] Fix | Delete
if ( ! isset( $wp_filter['all'] ) ) {
[204] Fix | Delete
$wp_current_filter[] = $tag;
[205] Fix | Delete
}
[206] Fix | Delete
[207] Fix | Delete
// Don't pass the tag name to WP_Hook.
[208] Fix | Delete
array_shift( $args );
[209] Fix | Delete
[210] Fix | Delete
$filtered = $wp_filter[ $tag ]->apply_filters( $value, $args );
[211] Fix | Delete
[212] Fix | Delete
array_pop( $wp_current_filter );
[213] Fix | Delete
[214] Fix | Delete
return $filtered;
[215] Fix | Delete
}
[216] Fix | Delete
[217] Fix | Delete
/**
[218] Fix | Delete
* Calls the callback functions that have been added to a filter hook, specifying arguments in an array.
[219] Fix | Delete
*
[220] Fix | Delete
* @since 3.0.0
[221] Fix | Delete
*
[222] Fix | Delete
* @see apply_filters() This function is identical, but the arguments passed to the
[223] Fix | Delete
* functions hooked to `$tag` are supplied using an array.
[224] Fix | Delete
*
[225] Fix | Delete
* @global WP_Hook[] $wp_filter Stores all of the filters and actions.
[226] Fix | Delete
* @global string[] $wp_current_filter Stores the list of current filters with the current one last.
[227] Fix | Delete
*
[228] Fix | Delete
* @param string $tag The name of the filter hook.
[229] Fix | Delete
* @param array $args The arguments supplied to the functions hooked to $tag.
[230] Fix | Delete
* @return mixed The filtered value after all hooked functions are applied to it.
[231] Fix | Delete
*/
[232] Fix | Delete
function apply_filters_ref_array( $tag, $args ) {
[233] Fix | Delete
global $wp_filter, $wp_current_filter;
[234] Fix | Delete
[235] Fix | Delete
// Do 'all' actions first.
[236] Fix | Delete
if ( isset( $wp_filter['all'] ) ) {
[237] Fix | Delete
$wp_current_filter[] = $tag;
[238] Fix | Delete
$all_args = func_get_args(); // phpcs:ignore PHPCompatibility.FunctionUse.ArgumentFunctionsReportCurrentValue.NeedsInspection
[239] Fix | Delete
_wp_call_all_hook( $all_args );
[240] Fix | Delete
}
[241] Fix | Delete
[242] Fix | Delete
if ( ! isset( $wp_filter[ $tag ] ) ) {
[243] Fix | Delete
if ( isset( $wp_filter['all'] ) ) {
[244] Fix | Delete
array_pop( $wp_current_filter );
[245] Fix | Delete
}
[246] Fix | Delete
return $args[0];
[247] Fix | Delete
}
[248] Fix | Delete
[249] Fix | Delete
if ( ! isset( $wp_filter['all'] ) ) {
[250] Fix | Delete
$wp_current_filter[] = $tag;
[251] Fix | Delete
}
[252] Fix | Delete
[253] Fix | Delete
$filtered = $wp_filter[ $tag ]->apply_filters( $args[0], $args );
[254] Fix | Delete
[255] Fix | Delete
array_pop( $wp_current_filter );
[256] Fix | Delete
[257] Fix | Delete
return $filtered;
[258] Fix | Delete
}
[259] Fix | Delete
[260] Fix | Delete
/**
[261] Fix | Delete
* Removes a function from a specified filter hook.
[262] Fix | Delete
*
[263] Fix | Delete
* This function removes a function attached to a specified filter hook. This
[264] Fix | Delete
* method can be used to remove default functions attached to a specific filter
[265] Fix | Delete
* hook and possibly replace them with a substitute.
[266] Fix | Delete
*
[267] Fix | Delete
* To remove a hook, the $function_to_remove and $priority arguments must match
[268] Fix | Delete
* when the hook was added. This goes for both filters and actions. No warning
[269] Fix | Delete
* will be given on removal failure.
[270] Fix | Delete
*
[271] Fix | Delete
* @since 1.2.0
[272] Fix | Delete
*
[273] Fix | Delete
* @global WP_Hook[] $wp_filter Stores all of the filters and actions.
[274] Fix | Delete
*
[275] Fix | Delete
* @param string $tag The filter hook to which the function to be removed is hooked.
[276] Fix | Delete
* @param callable $function_to_remove The name of the function which should be removed.
[277] Fix | Delete
* @param int $priority Optional. The priority of the function. Default 10.
[278] Fix | Delete
* @return bool Whether the function existed before it was removed.
[279] Fix | Delete
*/
[280] Fix | Delete
function remove_filter( $tag, $function_to_remove, $priority = 10 ) {
[281] Fix | Delete
global $wp_filter;
[282] Fix | Delete
[283] Fix | Delete
$r = false;
[284] Fix | Delete
if ( isset( $wp_filter[ $tag ] ) ) {
[285] Fix | Delete
$r = $wp_filter[ $tag ]->remove_filter( $tag, $function_to_remove, $priority );
[286] Fix | Delete
if ( ! $wp_filter[ $tag ]->callbacks ) {
[287] Fix | Delete
unset( $wp_filter[ $tag ] );
[288] Fix | Delete
}
[289] Fix | Delete
}
[290] Fix | Delete
[291] Fix | Delete
return $r;
[292] Fix | Delete
}
[293] Fix | Delete
[294] Fix | Delete
/**
[295] Fix | Delete
* Remove all of the hooks from a filter.
[296] Fix | Delete
*
[297] Fix | Delete
* @since 2.7.0
[298] Fix | Delete
*
[299] Fix | Delete
* @global WP_Hook[] $wp_filter Stores all of the filters and actions.
[300] Fix | Delete
*
[301] Fix | Delete
* @param string $tag The filter to remove hooks from.
[302] Fix | Delete
* @param int|false $priority Optional. The priority number to remove. Default false.
[303] Fix | Delete
* @return true True when finished.
[304] Fix | Delete
*/
[305] Fix | Delete
function remove_all_filters( $tag, $priority = false ) {
[306] Fix | Delete
global $wp_filter;
[307] Fix | Delete
[308] Fix | Delete
if ( isset( $wp_filter[ $tag ] ) ) {
[309] Fix | Delete
$wp_filter[ $tag ]->remove_all_filters( $priority );
[310] Fix | Delete
if ( ! $wp_filter[ $tag ]->has_filters() ) {
[311] Fix | Delete
unset( $wp_filter[ $tag ] );
[312] Fix | Delete
}
[313] Fix | Delete
}
[314] Fix | Delete
[315] Fix | Delete
return true;
[316] Fix | Delete
}
[317] Fix | Delete
[318] Fix | Delete
/**
[319] Fix | Delete
* Retrieve the name of the current filter or action.
[320] Fix | Delete
*
[321] Fix | Delete
* @since 2.5.0
[322] Fix | Delete
*
[323] Fix | Delete
* @global string[] $wp_current_filter Stores the list of current filters with the current one last
[324] Fix | Delete
*
[325] Fix | Delete
* @return string Hook name of the current filter or action.
[326] Fix | Delete
*/
[327] Fix | Delete
function current_filter() {
[328] Fix | Delete
global $wp_current_filter;
[329] Fix | Delete
return end( $wp_current_filter );
[330] Fix | Delete
}
[331] Fix | Delete
[332] Fix | Delete
/**
[333] Fix | Delete
* Retrieve the name of the current action.
[334] Fix | Delete
*
[335] Fix | Delete
* @since 3.9.0
[336] Fix | Delete
*
[337] Fix | Delete
* @return string Hook name of the current action.
[338] Fix | Delete
*/
[339] Fix | Delete
function current_action() {
[340] Fix | Delete
return current_filter();
[341] Fix | Delete
}
[342] Fix | Delete
[343] Fix | Delete
/**
[344] Fix | Delete
* Retrieve the name of a filter currently being processed.
[345] Fix | Delete
*
[346] Fix | Delete
* The function current_filter() only returns the most recent filter or action
[347] Fix | Delete
* being executed. did_action() returns true once the action is initially
[348] Fix | Delete
* processed.
[349] Fix | Delete
*
[350] Fix | Delete
* This function allows detection for any filter currently being
[351] Fix | Delete
* executed (despite not being the most recent filter to fire, in the case of
[352] Fix | Delete
* hooks called from hook callbacks) to be verified.
[353] Fix | Delete
*
[354] Fix | Delete
* @since 3.9.0
[355] Fix | Delete
*
[356] Fix | Delete
* @see current_filter()
[357] Fix | Delete
* @see did_action()
[358] Fix | Delete
* @global string[] $wp_current_filter Current filter.
[359] Fix | Delete
*
[360] Fix | Delete
* @param null|string $filter Optional. Filter to check. Defaults to null, which
[361] Fix | Delete
* checks if any filter is currently being run.
[362] Fix | Delete
* @return bool Whether the filter is currently in the stack.
[363] Fix | Delete
*/
[364] Fix | Delete
function doing_filter( $filter = null ) {
[365] Fix | Delete
global $wp_current_filter;
[366] Fix | Delete
[367] Fix | Delete
if ( null === $filter ) {
[368] Fix | Delete
return ! empty( $wp_current_filter );
[369] Fix | Delete
}
[370] Fix | Delete
[371] Fix | Delete
return in_array( $filter, $wp_current_filter, true );
[372] Fix | Delete
}
[373] Fix | Delete
[374] Fix | Delete
/**
[375] Fix | Delete
* Retrieve the name of an action currently being processed.
[376] Fix | Delete
*
[377] Fix | Delete
* @since 3.9.0
[378] Fix | Delete
*
[379] Fix | Delete
* @param string|null $action Optional. Action to check. Defaults to null, which checks
[380] Fix | Delete
* if any action is currently being run.
[381] Fix | Delete
* @return bool Whether the action is currently in the stack.
[382] Fix | Delete
*/
[383] Fix | Delete
function doing_action( $action = null ) {
[384] Fix | Delete
return doing_filter( $action );
[385] Fix | Delete
}
[386] Fix | Delete
[387] Fix | Delete
/**
[388] Fix | Delete
* Hooks a function on to a specific action.
[389] Fix | Delete
*
[390] Fix | Delete
* Actions are the hooks that the WordPress core launches at specific points
[391] Fix | Delete
* during execution, or when specific events occur. Plugins can specify that
[392] Fix | Delete
* one or more of its PHP functions are executed at these points, using the
[393] Fix | Delete
* Action API.
[394] Fix | Delete
*
[395] Fix | Delete
* @since 1.2.0
[396] Fix | Delete
*
[397] Fix | Delete
* @param string $tag The name of the action to which the $function_to_add is hooked.
[398] Fix | Delete
* @param callable $function_to_add The name of the function you wish to be called.
[399] Fix | Delete
* @param int $priority Optional. Used to specify the order in which the functions
[400] Fix | Delete
* associated with a particular action are executed. Default 10.
[401] Fix | Delete
* Lower numbers correspond with earlier execution,
[402] Fix | Delete
* and functions with the same priority are executed
[403] Fix | Delete
* in the order in which they were added to the action.
[404] Fix | Delete
* @param int $accepted_args Optional. The number of arguments the function accepts. Default 1.
[405] Fix | Delete
* @return true Will always return true.
[406] Fix | Delete
*/
[407] Fix | Delete
function add_action( $tag, $function_to_add, $priority = 10, $accepted_args = 1 ) {
[408] Fix | Delete
return add_filter( $tag, $function_to_add, $priority, $accepted_args );
[409] Fix | Delete
}
[410] Fix | Delete
[411] Fix | Delete
/**
[412] Fix | Delete
* Execute functions hooked on a specific action hook.
[413] Fix | Delete
*
[414] Fix | Delete
* This function invokes all functions attached to action hook `$tag`. It is
[415] Fix | Delete
* possible to create new action hooks by simply calling this function,
[416] Fix | Delete
* specifying the name of the new hook using the `$tag` parameter.
[417] Fix | Delete
*
[418] Fix | Delete
* You can pass extra arguments to the hooks, much like you can with `apply_filters()`.
[419] Fix | Delete
*
[420] Fix | Delete
* Example usage:
[421] Fix | Delete
*
[422] Fix | Delete
* // The action callback function.
[423] Fix | Delete
* function example_callback( $arg1, $arg2 ) {
[424] Fix | Delete
* // (maybe) do something with the args.
[425] Fix | Delete
* }
[426] Fix | Delete
* add_action( 'example_action', 'example_callback', 10, 2 );
[427] Fix | Delete
*
[428] Fix | Delete
* /*
[429] Fix | Delete
* * Trigger the actions by calling the 'example_callback()' function
[430] Fix | Delete
* * that's hooked onto `example_action` above.
[431] Fix | Delete
* *
[432] Fix | Delete
* * - 'example_action' is the action hook.
[433] Fix | Delete
* * - $arg1 and $arg2 are the additional arguments passed to the callback.
[434] Fix | Delete
* $value = do_action( 'example_action', $arg1, $arg2 );
[435] Fix | Delete
*
[436] Fix | Delete
* @since 1.2.0
[437] Fix | Delete
* @since 5.3.0 Formalized the existing and already documented `...$arg` parameter
[438] Fix | Delete
* by adding it to the function signature.
[439] Fix | Delete
*
[440] Fix | Delete
* @global WP_Hook[] $wp_filter Stores all of the filters and actions.
[441] Fix | Delete
* @global int[] $wp_actions Stores the number of times each action was triggered.
[442] Fix | Delete
* @global string[] $wp_current_filter Stores the list of current filters with the current one last.
[443] Fix | Delete
*
[444] Fix | Delete
* @param string $tag The name of the action to be executed.
[445] Fix | Delete
* @param mixed ...$arg Optional. Additional arguments which are passed on to the
[446] Fix | Delete
* functions hooked to the action. Default empty.
[447] Fix | Delete
*/
[448] Fix | Delete
function do_action( $tag, ...$arg ) {
[449] Fix | Delete
global $wp_filter, $wp_actions, $wp_current_filter;
[450] Fix | Delete
[451] Fix | Delete
if ( ! isset( $wp_actions[ $tag ] ) ) {
[452] Fix | Delete
$wp_actions[ $tag ] = 1;
[453] Fix | Delete
} else {
[454] Fix | Delete
++$wp_actions[ $tag ];
[455] Fix | Delete
}
[456] Fix | Delete
[457] Fix | Delete
// Do 'all' actions first.
[458] Fix | Delete
if ( isset( $wp_filter['all'] ) ) {
[459] Fix | Delete
$wp_current_filter[] = $tag;
[460] Fix | Delete
$all_args = func_get_args(); // phpcs:ignore PHPCompatibility.FunctionUse.ArgumentFunctionsReportCurrentValue.NeedsInspection
[461] Fix | Delete
_wp_call_all_hook( $all_args );
[462] Fix | Delete
}
[463] Fix | Delete
[464] Fix | Delete
if ( ! isset( $wp_filter[ $tag ] ) ) {
[465] Fix | Delete
if ( isset( $wp_filter['all'] ) ) {
[466] Fix | Delete
array_pop( $wp_current_filter );
[467] Fix | Delete
}
[468] Fix | Delete
return;
[469] Fix | Delete
}
[470] Fix | Delete
[471] Fix | Delete
if ( ! isset( $wp_filter['all'] ) ) {
[472] Fix | Delete
$wp_current_filter[] = $tag;
[473] Fix | Delete
}
[474] Fix | Delete
[475] Fix | Delete
if ( empty( $arg ) ) {
[476] Fix | Delete
$arg[] = '';
[477] Fix | Delete
} elseif ( is_array( $arg[0] ) && 1 === count( $arg[0] ) && isset( $arg[0][0] ) && is_object( $arg[0][0] ) ) {
[478] Fix | Delete
// Backward compatibility for PHP4-style passing of `array( &$this )` as action `$arg`.
[479] Fix | Delete
$arg[0] = $arg[0][0];
[480] Fix | Delete
}
[481] Fix | Delete
[482] Fix | Delete
$wp_filter[ $tag ]->do_action( $arg );
[483] Fix | Delete
[484] Fix | Delete
array_pop( $wp_current_filter );
[485] Fix | Delete
}
[486] Fix | Delete
[487] Fix | Delete
/**
[488] Fix | Delete
* Retrieve the number of times an action is fired.
[489] Fix | Delete
*
[490] Fix | Delete
* @since 2.1.0
[491] Fix | Delete
*
[492] Fix | Delete
* @global int[] $wp_actions Stores the number of times each action was triggered.
[493] Fix | Delete
*
[494] Fix | Delete
* @param string $tag The name of the action hook.
[495] Fix | Delete
* @return int The number of times action hook $tag is fired.
[496] Fix | Delete
*/
[497] Fix | Delete
function did_action( $tag ) {
[498] Fix | Delete
global $wp_actions;
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function