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