wp/wp-includes/plugin.php
author ymh <ymh.work@gmail.com>
Tue, 27 Sep 2022 16:37:53 +0200
changeset 19 3d72ae0968f4
parent 18 be944660c56a
child 21 48c4eec2b7e6
permissions -rw-r--r--
upgrade wordpress to 6.0.2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     1
<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     2
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     3
 * The plugin API is located in this file, which allows for creating actions
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     4
 * and filters and hooking functions, and methods. The functions or methods will
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     5
 * then be run when the action or filter is called.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     6
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     7
 * The API callback examples reference functions, but can be methods of classes.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     8
 * To hook methods, you'll need to pass an array one of two ways.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     9
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    10
 * Any of the syntaxes explained in the PHP documentation for the
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    11
 * {@link https://www.php.net/manual/en/language.pseudo-types.php#language.types.callback 'callback'}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    12
 * type are valid.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    13
 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    14
 * Also see the {@link https://developer.wordpress.org/plugins/ Plugin API} for
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    15
 * more information and examples on how to use a lot of these functions.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    16
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    17
 * This file should have no external dependencies.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    18
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    19
 * @package WordPress
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    20
 * @subpackage Plugin
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    21
 * @since 1.5.0
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    22
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    23
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    24
// Initialize the filter globals.
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    25
require __DIR__ . '/class-wp-hook.php';
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    26
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    27
/** @var WP_Hook[] $wp_filter */
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
    28
global $wp_filter;
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
    29
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
    30
/** @var int[] $wp_actions */
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
    31
global $wp_actions;
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
    32
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
    33
/** @var string[] $wp_current_filter */
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
    34
global $wp_current_filter;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    35
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    36
if ( $wp_filter ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    37
	$wp_filter = WP_Hook::build_preinitialized_hooks( $wp_filter );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    38
} else {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    39
	$wp_filter = array();
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    40
}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    41
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    42
if ( ! isset( $wp_actions ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    43
	$wp_actions = array();
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    44
}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    45
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    46
if ( ! isset( $wp_current_filter ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    47
	$wp_current_filter = array();
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    48
}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    49
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    50
/**
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
    51
 * Adds a callback function to a filter hook.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    52
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    53
 * WordPress offers filter hooks to allow plugins to modify
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    54
 * various types of internal data at runtime.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    55
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    56
 * A plugin can modify data by binding a callback to a filter hook. When the filter
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    57
 * is later applied, each bound callback is run in order of priority, and given
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    58
 * the opportunity to modify a value by returning a new value.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    59
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    60
 * The following example shows how a callback function is bound to a filter hook.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    61
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    62
 * Note that `$example` is passed to the callback, (maybe) modified, then returned:
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    63
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    64
 *     function example_callback( $example ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    65
 *         // Maybe modify $example in some way.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    66
 *         return $example;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    67
 *     }
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    68
 *     add_filter( 'example_filter', 'example_callback' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    69
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    70
 * Bound callbacks can accept from none to the total number of arguments passed as parameters
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    71
 * in the corresponding apply_filters() call.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    72
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    73
 * In other words, if an apply_filters() call passes four total arguments, callbacks bound to
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    74
 * it can accept none (the same as 1) of the arguments or up to four. The important part is that
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    75
 * the `$accepted_args` value must reflect the number of arguments the bound callback *actually*
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    76
 * opted to accept. If no arguments were accepted by the callback that is considered to be the
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    77
 * same as accepting 1 argument. For example:
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    78
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    79
 *     // Filter call.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    80
 *     $value = apply_filters( 'hook', $value, $arg2, $arg3 );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    81
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    82
 *     // Accepting zero/one arguments.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    83
 *     function example_callback() {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    84
 *         ...
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    85
 *         return 'some value';
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    86
 *     }
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    87
 *     add_filter( 'hook', 'example_callback' ); // Where $priority is default 10, $accepted_args is default 1.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    88
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    89
 *     // Accepting two arguments (three possible).
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    90
 *     function example_callback( $value, $arg2 ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    91
 *         ...
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    92
 *         return $maybe_modified_value;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    93
 *     }
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    94
 *     add_filter( 'hook', 'example_callback', 10, 2 ); // Where $priority is 10, $accepted_args is 2.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    95
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    96
 * *Note:* The function will return true whether or not the callback is valid.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    97
 * It is up to you to take care. This is done for optimization purposes, so
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    98
 * everything is as quick as possible.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    99
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   100
 * @since 0.71
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   101
 *
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   102
 * @global WP_Hook[] $wp_filter A multidimensional array of all hooks and the callbacks hooked to them.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   103
 *
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   104
 * @param string   $hook_name     The name of the filter to add the callback to.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   105
 * @param callable $callback      The callback to be run when the filter is applied.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   106
 * @param int      $priority      Optional. Used to specify the order in which the functions
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   107
 *                                associated with a particular filter are executed.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   108
 *                                Lower numbers correspond with earlier execution,
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   109
 *                                and functions with the same priority are executed
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   110
 *                                in the order in which they were added to the filter. Default 10.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   111
 * @param int      $accepted_args Optional. The number of arguments the function accepts. Default 1.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   112
 * @return true Always returns true.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   113
 */
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   114
function add_filter( $hook_name, $callback, $priority = 10, $accepted_args = 1 ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   115
	global $wp_filter;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   116
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   117
	if ( ! isset( $wp_filter[ $hook_name ] ) ) {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   118
		$wp_filter[ $hook_name ] = new WP_Hook();
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   119
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   120
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   121
	$wp_filter[ $hook_name ]->add_filter( $hook_name, $callback, $priority, $accepted_args );
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   122
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   123
	return true;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   124
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   125
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   126
/**
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   127
 * Calls the callback functions that have been added to a filter hook.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   128
 *
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   129
 * This function invokes all functions attached to filter hook `$hook_name`.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   130
 * It is possible to create new filter hooks by simply calling this function,
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   131
 * specifying the name of the new hook using the `$hook_name` parameter.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   132
 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   133
 * The function also allows for multiple additional arguments to be passed to hooks.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   134
 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   135
 * Example usage:
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   136
 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   137
 *     // The filter callback function.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   138
 *     function example_callback( $string, $arg1, $arg2 ) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   139
 *         // (maybe) modify $string.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   140
 *         return $string;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   141
 *     }
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   142
 *     add_filter( 'example_filter', 'example_callback', 10, 3 );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   143
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   144
 *     /*
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   145
 *      * Apply the filters by calling the 'example_callback()' function
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   146
 *      * that's hooked onto `example_filter` above.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   147
 *      *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   148
 *      * - 'example_filter' is the filter hook.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   149
 *      * - 'filter me' is the value being filtered.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   150
 *      * - $arg1 and $arg2 are the additional arguments passed to the callback.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   151
 *     $value = apply_filters( 'example_filter', 'filter me', $arg1, $arg2 );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   152
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   153
 * @since 0.71
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   154
 * @since 6.0.0 Formalized the existing and already documented `...$args` parameter
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   155
 *              by adding it to the function signature.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   156
 *
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   157
 * @global WP_Hook[] $wp_filter         Stores all of the filters and actions.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   158
 * @global string[]  $wp_current_filter Stores the list of current filters with the current one last.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   159
 *
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   160
 * @param string $hook_name The name of the filter hook.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   161
 * @param mixed  $value     The value to filter.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   162
 * @param mixed  ...$args   Additional parameters to pass to the callback functions.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   163
 * @return mixed The filtered value after all hooked functions are applied to it.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   164
 */
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   165
function apply_filters( $hook_name, $value, ...$args ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   166
	global $wp_filter, $wp_current_filter;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   167
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   168
	// Do 'all' actions first.
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   169
	if ( isset( $wp_filter['all'] ) ) {
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   170
		$wp_current_filter[] = $hook_name;
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   171
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   172
		$all_args = func_get_args(); // phpcs:ignore PHPCompatibility.FunctionUse.ArgumentFunctionsReportCurrentValue.NeedsInspection
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   173
		_wp_call_all_hook( $all_args );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   174
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   175
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   176
	if ( ! isset( $wp_filter[ $hook_name ] ) ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   177
		if ( isset( $wp_filter['all'] ) ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   178
			array_pop( $wp_current_filter );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   179
		}
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   180
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   181
		return $value;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   182
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   183
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   184
	if ( ! isset( $wp_filter['all'] ) ) {
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   185
		$wp_current_filter[] = $hook_name;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   186
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   187
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   188
	// Pass the value to WP_Hook.
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   189
	array_unshift( $args, $value );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   190
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   191
	$filtered = $wp_filter[ $hook_name ]->apply_filters( $value, $args );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   192
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   193
	array_pop( $wp_current_filter );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   194
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   195
	return $filtered;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   196
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   197
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   198
/**
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   199
 * Calls the callback functions that have been added to a filter hook, specifying arguments in an array.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   200
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   201
 * @since 3.0.0
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   202
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   203
 * @see apply_filters() This function is identical, but the arguments passed to the
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   204
 *                      functions hooked to `$hook_name` are supplied using an array.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   205
 *
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   206
 * @global WP_Hook[] $wp_filter         Stores all of the filters and actions.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   207
 * @global string[]  $wp_current_filter Stores the list of current filters with the current one last.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   208
 *
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   209
 * @param string $hook_name The name of the filter hook.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   210
 * @param array  $args      The arguments supplied to the functions hooked to `$hook_name`.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   211
 * @return mixed The filtered value after all hooked functions are applied to it.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   212
 */
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   213
function apply_filters_ref_array( $hook_name, $args ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   214
	global $wp_filter, $wp_current_filter;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   215
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   216
	// Do 'all' actions first.
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   217
	if ( isset( $wp_filter['all'] ) ) {
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   218
		$wp_current_filter[] = $hook_name;
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   219
		$all_args            = func_get_args(); // phpcs:ignore PHPCompatibility.FunctionUse.ArgumentFunctionsReportCurrentValue.NeedsInspection
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   220
		_wp_call_all_hook( $all_args );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   221
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   222
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   223
	if ( ! isset( $wp_filter[ $hook_name ] ) ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   224
		if ( isset( $wp_filter['all'] ) ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   225
			array_pop( $wp_current_filter );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   226
		}
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   227
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   228
		return $args[0];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   229
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   230
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   231
	if ( ! isset( $wp_filter['all'] ) ) {
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   232
		$wp_current_filter[] = $hook_name;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   233
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   234
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   235
	$filtered = $wp_filter[ $hook_name ]->apply_filters( $args[0], $args );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   236
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   237
	array_pop( $wp_current_filter );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   238
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   239
	return $filtered;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   240
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   241
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   242
/**
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   243
 * Checks if any filter has been registered for a hook.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   244
 *
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   245
 * When using the `$callback` argument, this function may return a non-boolean value
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   246
 * that evaluates to false (e.g. 0), so use the `===` operator for testing the return value.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   247
 *
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   248
 * @since 2.5.0
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   249
 *
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   250
 * @global WP_Hook[] $wp_filter Stores all of the filters and actions.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   251
 *
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   252
 * @param string                      $hook_name The name of the filter hook.
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   253
 * @param callable|string|array|false $callback  Optional. The callback to check for.
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   254
 *                                               This function can be called unconditionally to speculatively check
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   255
 *                                               a callback that may or may not exist. Default false.
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   256
 * @return bool|int If `$callback` is omitted, returns boolean for whether the hook has
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   257
 *                  anything registered. When checking a specific function, the priority
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   258
 *                  of that hook is returned, or false if the function is not attached.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   259
 */
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   260
function has_filter( $hook_name, $callback = false ) {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   261
	global $wp_filter;
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   262
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   263
	if ( ! isset( $wp_filter[ $hook_name ] ) ) {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   264
		return false;
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   265
	}
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   266
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   267
	return $wp_filter[ $hook_name ]->has_filter( $hook_name, $callback );
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   268
}
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   269
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   270
/**
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   271
 * Removes a callback function from a filter hook.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   272
 *
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   273
 * This can be used to remove default functions attached to a specific filter
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   274
 * hook and possibly replace them with a substitute.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   275
 *
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   276
 * To remove a hook, the `$callback` and `$priority` arguments must match
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   277
 * when the hook was added. This goes for both filters and actions. No warning
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   278
 * will be given on removal failure.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   279
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   280
 * @since 1.2.0
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   281
 *
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   282
 * @global WP_Hook[] $wp_filter Stores all of the filters and actions.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   283
 *
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   284
 * @param string                $hook_name The filter hook to which the function to be removed is hooked.
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   285
 * @param callable|string|array $callback  The callback to be removed from running when the filter is applied.
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   286
 *                                         This function can be called unconditionally to speculatively remove
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   287
 *                                         a callback that may or may not exist.
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   288
 * @param int                   $priority  Optional. The exact priority used when adding the original
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   289
 *                                         filter callback. Default 10.
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   290
 * @return bool Whether the function existed before it was removed.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   291
 */
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   292
function remove_filter( $hook_name, $callback, $priority = 10 ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   293
	global $wp_filter;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   294
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   295
	$r = false;
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   296
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   297
	if ( isset( $wp_filter[ $hook_name ] ) ) {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   298
		$r = $wp_filter[ $hook_name ]->remove_filter( $hook_name, $callback, $priority );
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   299
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   300
		if ( ! $wp_filter[ $hook_name ]->callbacks ) {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   301
			unset( $wp_filter[ $hook_name ] );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   302
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   303
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   304
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   305
	return $r;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   306
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   307
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   308
/**
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   309
 * Removes all of the callback functions from a filter hook.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   310
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   311
 * @since 2.7.0
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   312
 *
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   313
 * @global WP_Hook[] $wp_filter Stores all of the filters and actions.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   314
 *
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   315
 * @param string    $hook_name The filter to remove callbacks from.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   316
 * @param int|false $priority  Optional. The priority number to remove them from.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   317
 *                             Default false.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   318
 * @return true Always returns true.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   319
 */
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   320
function remove_all_filters( $hook_name, $priority = false ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   321
	global $wp_filter;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   322
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   323
	if ( isset( $wp_filter[ $hook_name ] ) ) {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   324
		$wp_filter[ $hook_name ]->remove_all_filters( $priority );
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   325
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   326
		if ( ! $wp_filter[ $hook_name ]->has_filters() ) {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   327
			unset( $wp_filter[ $hook_name ] );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   328
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   329
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   330
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   331
	return true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   332
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   333
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   334
/**
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   335
 * Retrieves the name of the current filter hook.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   336
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   337
 * @since 2.5.0
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   338
 *
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   339
 * @global string[] $wp_current_filter Stores the list of current filters with the current one last
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   340
 *
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   341
 * @return string Hook name of the current filter.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   342
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   343
function current_filter() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   344
	global $wp_current_filter;
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   345
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   346
	return end( $wp_current_filter );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   347
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   348
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   349
/**
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   350
 * Returns whether or not a filter hook is currently being processed.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   351
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   352
 * The function current_filter() only returns the most recent filter or action
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   353
 * being executed. did_action() returns true once the action is initially
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   354
 * processed.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   355
 *
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   356
 * This function allows detection for any filter currently being executed
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   357
 * (regardless of whether it's the most recent filter to fire, in the case of
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   358
 * hooks called from hook callbacks) to be verified.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   359
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   360
 * @since 3.9.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   361
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   362
 * @see current_filter()
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   363
 * @see did_action()
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   364
 * @global string[] $wp_current_filter Current filter.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   365
 *
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   366
 * @param null|string $hook_name Optional. Filter hook to check. Defaults to null,
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   367
 *                               which checks if any filter is currently being run.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   368
 * @return bool Whether the filter is currently in the stack.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   369
 */
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   370
function doing_filter( $hook_name = null ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   371
	global $wp_current_filter;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   372
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   373
	if ( null === $hook_name ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   374
		return ! empty( $wp_current_filter );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   375
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   376
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   377
	return in_array( $hook_name, $wp_current_filter, true );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   378
}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   379
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   380
/**
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   381
 * Adds a callback function to an action hook.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   382
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   383
 * Actions are the hooks that the WordPress core launches at specific points
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   384
 * during execution, or when specific events occur. Plugins can specify that
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   385
 * one or more of its PHP functions are executed at these points, using the
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   386
 * Action API.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   387
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   388
 * @since 1.2.0
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   389
 *
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   390
 * @param string   $hook_name       The name of the action to add the callback to.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   391
 * @param callable $callback        The callback to be run when the action is called.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   392
 * @param int      $priority        Optional. Used to specify the order in which the functions
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   393
 *                                  associated with a particular action are executed.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   394
 *                                  Lower numbers correspond with earlier execution,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   395
 *                                  and functions with the same priority are executed
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   396
 *                                  in the order in which they were added to the action. Default 10.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   397
 * @param int      $accepted_args   Optional. The number of arguments the function accepts. Default 1.
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   398
 * @return true Always returns true.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   399
 */
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   400
function add_action( $hook_name, $callback, $priority = 10, $accepted_args = 1 ) {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   401
	return add_filter( $hook_name, $callback, $priority, $accepted_args );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   402
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   403
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   404
/**
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   405
 * Calls the callback functions that have been added to an action hook.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   406
 *
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   407
 * This function invokes all functions attached to action hook `$hook_name`.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   408
 * It is possible to create new action hooks by simply calling this function,
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   409
 * specifying the name of the new hook using the `$hook_name` parameter.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   410
 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   411
 * You can pass extra arguments to the hooks, much like you can with `apply_filters()`.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   412
 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   413
 * Example usage:
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   414
 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   415
 *     // The action callback function.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   416
 *     function example_callback( $arg1, $arg2 ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   417
 *         // (maybe) do something with the args.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   418
 *     }
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   419
 *     add_action( 'example_action', 'example_callback', 10, 2 );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   420
 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   421
 *     /*
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   422
 *      * Trigger the actions by calling the 'example_callback()' function
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   423
 *      * that's hooked onto `example_action` above.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   424
 *      *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   425
 *      * - 'example_action' is the action hook.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   426
 *      * - $arg1 and $arg2 are the additional arguments passed to the callback.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   427
 *     $value = do_action( 'example_action', $arg1, $arg2 );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   428
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   429
 * @since 1.2.0
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   430
 * @since 5.3.0 Formalized the existing and already documented `...$arg` parameter
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   431
 *              by adding it to the function signature.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   432
 *
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   433
 * @global WP_Hook[] $wp_filter         Stores all of the filters and actions.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   434
 * @global int[]     $wp_actions        Stores the number of times each action was triggered.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   435
 * @global string[]  $wp_current_filter Stores the list of current filters with the current one last.
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   436
 *
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   437
 * @param string $hook_name The name of the action to be executed.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   438
 * @param mixed  ...$arg    Optional. Additional arguments which are passed on to the
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   439
 *                          functions hooked to the action. Default empty.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   440
 */
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   441
function do_action( $hook_name, ...$arg ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   442
	global $wp_filter, $wp_actions, $wp_current_filter;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   443
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   444
	if ( ! isset( $wp_actions[ $hook_name ] ) ) {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   445
		$wp_actions[ $hook_name ] = 1;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   446
	} else {
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   447
		++$wp_actions[ $hook_name ];
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   448
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   449
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   450
	// Do 'all' actions first.
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   451
	if ( isset( $wp_filter['all'] ) ) {
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   452
		$wp_current_filter[] = $hook_name;
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   453
		$all_args            = func_get_args(); // phpcs:ignore PHPCompatibility.FunctionUse.ArgumentFunctionsReportCurrentValue.NeedsInspection
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   454
		_wp_call_all_hook( $all_args );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   455
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   456
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   457
	if ( ! isset( $wp_filter[ $hook_name ] ) ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   458
		if ( isset( $wp_filter['all'] ) ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   459
			array_pop( $wp_current_filter );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   460
		}
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   461
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   462
		return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   463
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   464
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   465
	if ( ! isset( $wp_filter['all'] ) ) {
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   466
		$wp_current_filter[] = $hook_name;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   467
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   468
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   469
	if ( empty( $arg ) ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   470
		$arg[] = '';
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   471
	} elseif ( is_array( $arg[0] ) && 1 === count( $arg[0] ) && isset( $arg[0][0] ) && is_object( $arg[0][0] ) ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   472
		// Backward compatibility for PHP4-style passing of `array( &$this )` as action `$arg`.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   473
		$arg[0] = $arg[0][0];
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   474
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   475
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   476
	$wp_filter[ $hook_name ]->do_action( $arg );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   477
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   478
	array_pop( $wp_current_filter );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   479
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   480
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   481
/**
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   482
 * Calls the callback functions that have been added to an action hook, specifying arguments in an array.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   483
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   484
 * @since 2.1.0
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   485
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   486
 * @see do_action() This function is identical, but the arguments passed to the
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   487
 *                  functions hooked to `$hook_name` are supplied using an array.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   488
 *
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   489
 * @global WP_Hook[] $wp_filter         Stores all of the filters and actions.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   490
 * @global int[]     $wp_actions        Stores the number of times each action was triggered.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   491
 * @global string[]  $wp_current_filter Stores the list of current filters with the current one last.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   492
 *
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   493
 * @param string $hook_name The name of the action to be executed.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   494
 * @param array  $args      The arguments supplied to the functions hooked to `$hook_name`.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   495
 */
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   496
function do_action_ref_array( $hook_name, $args ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   497
	global $wp_filter, $wp_actions, $wp_current_filter;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   498
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   499
	if ( ! isset( $wp_actions[ $hook_name ] ) ) {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   500
		$wp_actions[ $hook_name ] = 1;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   501
	} else {
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   502
		++$wp_actions[ $hook_name ];
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   503
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   504
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   505
	// Do 'all' actions first.
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   506
	if ( isset( $wp_filter['all'] ) ) {
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   507
		$wp_current_filter[] = $hook_name;
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   508
		$all_args            = func_get_args(); // phpcs:ignore PHPCompatibility.FunctionUse.ArgumentFunctionsReportCurrentValue.NeedsInspection
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   509
		_wp_call_all_hook( $all_args );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   510
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   511
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   512
	if ( ! isset( $wp_filter[ $hook_name ] ) ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   513
		if ( isset( $wp_filter['all'] ) ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   514
			array_pop( $wp_current_filter );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   515
		}
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   516
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   517
		return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   518
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   519
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   520
	if ( ! isset( $wp_filter['all'] ) ) {
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   521
		$wp_current_filter[] = $hook_name;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   522
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   523
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   524
	$wp_filter[ $hook_name ]->do_action( $args );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   525
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   526
	array_pop( $wp_current_filter );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   527
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   528
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   529
/**
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   530
 * Checks if any action has been registered for a hook.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   531
 *
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   532
 * When using the `$callback` argument, this function may return a non-boolean value
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   533
 * that evaluates to false (e.g. 0), so use the `===` operator for testing the return value.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   534
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   535
 * @since 2.5.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   536
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   537
 * @see has_filter() has_action() is an alias of has_filter().
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   538
 *
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   539
 * @param string                      $hook_name The name of the action hook.
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   540
 * @param callable|string|array|false $callback  Optional. The callback to check for.
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   541
 *                                               This function can be called unconditionally to speculatively check
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   542
 *                                               a callback that may or may not exist. Default false.
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   543
 * @return bool|int If `$callback` is omitted, returns boolean for whether the hook has
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   544
 *                  anything registered. When checking a specific function, the priority
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   545
 *                  of that hook is returned, or false if the function is not attached.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   546
 */
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   547
function has_action( $hook_name, $callback = false ) {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   548
	return has_filter( $hook_name, $callback );
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   549
}
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   550
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   551
/**
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   552
 * Removes a callback function from an action hook.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   553
 *
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   554
 * This can be used to remove default functions attached to a specific action
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   555
 * hook and possibly replace them with a substitute.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   556
 *
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   557
 * To remove a hook, the `$callback` and `$priority` arguments must match
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   558
 * when the hook was added. This goes for both filters and actions. No warning
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   559
 * will be given on removal failure.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   560
 *
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   561
 * @since 1.2.0
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   562
 *
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   563
 * @param string                $hook_name The action hook to which the function to be removed is hooked.
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   564
 * @param callable|string|array $callback  The name of the function which should be removed.
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   565
 *                                         This function can be called unconditionally to speculatively remove
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   566
 *                                         a callback that may or may not exist.
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   567
 * @param int                   $priority  Optional. The exact priority used when adding the original
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   568
 *                                         action callback. Default 10.
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   569
 * @return bool Whether the function is removed.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   570
 */
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   571
function remove_action( $hook_name, $callback, $priority = 10 ) {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   572
	return remove_filter( $hook_name, $callback, $priority );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   573
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   574
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   575
/**
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   576
 * Removes all of the callback functions from an action hook.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   577
 *
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   578
 * @since 2.7.0
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   579
 *
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   580
 * @param string    $hook_name The action to remove callbacks from.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   581
 * @param int|false $priority  Optional. The priority number to remove them from.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   582
 *                             Default false.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   583
 * @return true Always returns true.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   584
 */
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   585
function remove_all_actions( $hook_name, $priority = false ) {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   586
	return remove_all_filters( $hook_name, $priority );
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   587
}
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   588
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   589
/**
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   590
 * Retrieves the name of the current action hook.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   591
 *
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   592
 * @since 3.9.0
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   593
 *
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   594
 * @return string Hook name of the current action.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   595
 */
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   596
function current_action() {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   597
	return current_filter();
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   598
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   599
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   600
/**
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   601
 * Returns whether or not an action hook is currently being processed.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   602
 *
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   603
 * @since 3.9.0
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   604
 *
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   605
 * @param string|null $hook_name Optional. Action hook to check. Defaults to null,
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   606
 *                               which checks if any action is currently being run.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   607
 * @return bool Whether the action is currently in the stack.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   608
 */
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   609
function doing_action( $hook_name = null ) {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   610
	return doing_filter( $hook_name );
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   611
}
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   612
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   613
/**
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   614
 * Retrieves the number of times an action has been fired during the current request.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   615
 *
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   616
 * @since 2.1.0
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   617
 *
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   618
 * @global int[] $wp_actions Stores the number of times each action was triggered.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   619
 *
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   620
 * @param string $hook_name The name of the action hook.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   621
 * @return int The number of times the action hook has been fired.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   622
 */
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   623
function did_action( $hook_name ) {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   624
	global $wp_actions;
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   625
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   626
	if ( ! isset( $wp_actions[ $hook_name ] ) ) {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   627
		return 0;
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   628
	}
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   629
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   630
	return $wp_actions[ $hook_name ];
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   631
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   632
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   633
/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   634
 * Fires functions attached to a deprecated filter hook.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   635
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   636
 * When a filter hook is deprecated, the apply_filters() call is replaced with
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   637
 * apply_filters_deprecated(), which triggers a deprecation notice and then fires
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   638
 * the original filter hook.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   639
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   640
 * Note: the value and extra arguments passed to the original apply_filters() call
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   641
 * must be passed here to `$args` as an array. For example:
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   642
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   643
 *     // Old filter.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   644
 *     return apply_filters( 'wpdocs_filter', $value, $extra_arg );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   645
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   646
 *     // Deprecated.
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   647
 *     return apply_filters_deprecated( 'wpdocs_filter', array( $value, $extra_arg ), '4.9.0', 'wpdocs_new_filter' );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   648
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   649
 * @since 4.6.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   650
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   651
 * @see _deprecated_hook()
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   652
 *
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   653
 * @param string $hook_name   The name of the filter hook.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   654
 * @param array  $args        Array of additional function arguments to be passed to apply_filters().
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   655
 * @param string $version     The version of WordPress that deprecated the hook.
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   656
 * @param string $replacement Optional. The hook that should have been used. Default empty.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   657
 * @param string $message     Optional. A message regarding the change. Default empty.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   658
 */
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   659
function apply_filters_deprecated( $hook_name, $args, $version, $replacement = '', $message = '' ) {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   660
	if ( ! has_filter( $hook_name ) ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   661
		return $args[0];
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   662
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   663
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   664
	_deprecated_hook( $hook_name, $version, $replacement, $message );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   665
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   666
	return apply_filters_ref_array( $hook_name, $args );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   667
}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   668
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   669
/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   670
 * Fires functions attached to a deprecated action hook.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   671
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   672
 * When an action hook is deprecated, the do_action() call is replaced with
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   673
 * do_action_deprecated(), which triggers a deprecation notice and then fires
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   674
 * the original hook.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   675
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   676
 * @since 4.6.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   677
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   678
 * @see _deprecated_hook()
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   679
 *
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   680
 * @param string $hook_name   The name of the action hook.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   681
 * @param array  $args        Array of additional function arguments to be passed to do_action().
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   682
 * @param string $version     The version of WordPress that deprecated the hook.
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   683
 * @param string $replacement Optional. The hook that should have been used. Default empty.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   684
 * @param string $message     Optional. A message regarding the change. Default empty.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   685
 */
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   686
function do_action_deprecated( $hook_name, $args, $version, $replacement = '', $message = '' ) {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   687
	if ( ! has_action( $hook_name ) ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   688
		return;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   689
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   690
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   691
	_deprecated_hook( $hook_name, $version, $replacement, $message );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   692
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   693
	do_action_ref_array( $hook_name, $args );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   694
}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   695
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   696
//
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   697
// Functions for handling plugins.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   698
//
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   699
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   700
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   701
 * Gets the basename of a plugin.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   702
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   703
 * This method extracts the name of a plugin from its filename.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   704
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   705
 * @since 1.5.0
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   706
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   707
 * @global array $wp_plugin_paths
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   708
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   709
 * @param string $file The filename of plugin.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   710
 * @return string The name of a plugin.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   711
 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   712
function plugin_basename( $file ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   713
	global $wp_plugin_paths;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   714
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   715
	// $wp_plugin_paths contains normalized paths.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   716
	$file = wp_normalize_path( $file );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   717
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   718
	arsort( $wp_plugin_paths );
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   719
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   720
	foreach ( $wp_plugin_paths as $dir => $realdir ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   721
		if ( strpos( $file, $realdir ) === 0 ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   722
			$file = $dir . substr( $file, strlen( $realdir ) );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   723
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   724
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   725
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   726
	$plugin_dir    = wp_normalize_path( WP_PLUGIN_DIR );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   727
	$mu_plugin_dir = wp_normalize_path( WPMU_PLUGIN_DIR );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   728
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   729
	// Get relative path from plugins directory.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   730
	$file = preg_replace( '#^' . preg_quote( $plugin_dir, '#' ) . '/|^' . preg_quote( $mu_plugin_dir, '#' ) . '/#', '', $file );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   731
	$file = trim( $file, '/' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   732
	return $file;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   733
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   734
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   735
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   736
 * Register a plugin's real path.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   737
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   738
 * This is used in plugin_basename() to resolve symlinked paths.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   739
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   740
 * @since 3.9.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   741
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   742
 * @see wp_normalize_path()
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   743
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   744
 * @global array $wp_plugin_paths
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   745
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   746
 * @param string $file Known path to the file.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   747
 * @return bool Whether the path was able to be registered.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   748
 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   749
function wp_register_plugin_realpath( $file ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   750
	global $wp_plugin_paths;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   751
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   752
	// Normalize, but store as static to avoid recalculation of a constant value.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   753
	static $wp_plugin_path = null, $wpmu_plugin_path = null;
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   754
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   755
	if ( ! isset( $wp_plugin_path ) ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   756
		$wp_plugin_path   = wp_normalize_path( WP_PLUGIN_DIR );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   757
		$wpmu_plugin_path = wp_normalize_path( WPMU_PLUGIN_DIR );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   758
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   759
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   760
	$plugin_path     = wp_normalize_path( dirname( $file ) );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   761
	$plugin_realpath = wp_normalize_path( dirname( realpath( $file ) ) );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   762
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   763
	if ( $plugin_path === $wp_plugin_path || $plugin_path === $wpmu_plugin_path ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   764
		return false;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   765
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   766
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   767
	if ( $plugin_path !== $plugin_realpath ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   768
		$wp_plugin_paths[ $plugin_path ] = $plugin_realpath;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   769
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   770
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   771
	return true;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   772
}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   773
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   774
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   775
 * Get the filesystem directory path (with trailing slash) for the plugin __FILE__ passed in.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   776
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   777
 * @since 2.8.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   778
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   779
 * @param string $file The filename of the plugin (__FILE__).
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   780
 * @return string the filesystem path of the directory that contains the plugin.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   781
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   782
function plugin_dir_path( $file ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   783
	return trailingslashit( dirname( $file ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   784
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   785
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   786
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   787
 * Get the URL directory path (with trailing slash) for the plugin __FILE__ passed in.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   788
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   789
 * @since 2.8.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   790
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   791
 * @param string $file The filename of the plugin (__FILE__).
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   792
 * @return string the URL path of the directory that contains the plugin.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   793
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   794
function plugin_dir_url( $file ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   795
	return trailingslashit( plugins_url( '', $file ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   796
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   797
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   798
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   799
 * Set the activation hook for a plugin.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   800
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   801
 * When a plugin is activated, the action 'activate_PLUGINNAME' hook is
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   802
 * called. In the name of this hook, PLUGINNAME is replaced with the name
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   803
 * of the plugin, including the optional subdirectory. For example, when the
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   804
 * plugin is located in wp-content/plugins/sampleplugin/sample.php, then
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   805
 * the name of this hook will become 'activate_sampleplugin/sample.php'.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   806
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   807
 * When the plugin consists of only one file and is (as by default) located at
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   808
 * wp-content/plugins/sample.php the name of this hook will be
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   809
 * 'activate_sample.php'.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   810
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   811
 * @since 2.0.0
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   812
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   813
 * @param string   $file     The filename of the plugin including the path.
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   814
 * @param callable $callback The function hooked to the 'activate_PLUGIN' action.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   815
 */
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   816
function register_activation_hook( $file, $callback ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   817
	$file = plugin_basename( $file );
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   818
	add_action( 'activate_' . $file, $callback );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   819
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   820
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   821
/**
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   822
 * Sets the deactivation hook for a plugin.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   823
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   824
 * When a plugin is deactivated, the action 'deactivate_PLUGINNAME' hook is
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   825
 * called. In the name of this hook, PLUGINNAME is replaced with the name
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   826
 * of the plugin, including the optional subdirectory. For example, when the
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   827
 * plugin is located in wp-content/plugins/sampleplugin/sample.php, then
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   828
 * the name of this hook will become 'deactivate_sampleplugin/sample.php'.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   829
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   830
 * When the plugin consists of only one file and is (as by default) located at
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   831
 * wp-content/plugins/sample.php the name of this hook will be
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   832
 * 'deactivate_sample.php'.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   833
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   834
 * @since 2.0.0
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   835
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   836
 * @param string   $file     The filename of the plugin including the path.
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   837
 * @param callable $callback The function hooked to the 'deactivate_PLUGIN' action.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   838
 */
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   839
function register_deactivation_hook( $file, $callback ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   840
	$file = plugin_basename( $file );
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   841
	add_action( 'deactivate_' . $file, $callback );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   842
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   843
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   844
/**
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   845
 * Sets the uninstallation hook for a plugin.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   846
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   847
 * Registers the uninstall hook that will be called when the user clicks on the
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   848
 * uninstall link that calls for the plugin to uninstall itself. The link won't
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   849
 * be active unless the plugin hooks into the action.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   850
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   851
 * The plugin should not run arbitrary code outside of functions, when
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   852
 * registering the uninstall hook. In order to run using the hook, the plugin
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   853
 * will have to be included, which means that any code laying outside of a
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   854
 * function will be run during the uninstallation process. The plugin should not
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   855
 * hinder the uninstallation process.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   856
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   857
 * If the plugin can not be written without running code within the plugin, then
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   858
 * the plugin should create a file named 'uninstall.php' in the base plugin
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   859
 * folder. This file will be called, if it exists, during the uninstallation process
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   860
 * bypassing the uninstall hook. The plugin, when using the 'uninstall.php'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   861
 * should always check for the 'WP_UNINSTALL_PLUGIN' constant, before
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   862
 * executing.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   863
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   864
 * @since 2.7.0
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   865
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   866
 * @param string   $file     Plugin file.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   867
 * @param callable $callback The callback to run when the hook is called. Must be
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   868
 *                           a static method or function.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   869
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   870
function register_uninstall_hook( $file, $callback ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   871
	if ( is_array( $callback ) && is_object( $callback[0] ) ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   872
		_doing_it_wrong( __FUNCTION__, __( 'Only a static class method or function can be used in an uninstall hook.' ), '3.1.0' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   873
		return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   874
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   875
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   876
	/*
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   877
	 * The option should not be autoloaded, because it is not needed in most
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   878
	 * cases. Emphasis should be put on using the 'uninstall.php' way of
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   879
	 * uninstalling the plugin.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   880
	 */
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   881
	$uninstallable_plugins = (array) get_option( 'uninstall_plugins' );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   882
	$plugin_basename       = plugin_basename( $file );
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   883
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   884
	if ( ! isset( $uninstallable_plugins[ $plugin_basename ] ) || $uninstallable_plugins[ $plugin_basename ] !== $callback ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   885
		$uninstallable_plugins[ $plugin_basename ] = $callback;
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   886
		update_option( 'uninstall_plugins', $uninstallable_plugins );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   887
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   888
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   889
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   890
/**
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   891
 * Calls the 'all' hook, which will process the functions hooked into it.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   892
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   893
 * The 'all' hook passes all of the arguments or parameters that were used for
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   894
 * the hook, which this function was called for.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   895
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   896
 * This function is used internally for apply_filters(), do_action(), and
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   897
 * do_action_ref_array() and is not meant to be used from outside those
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   898
 * functions. This function does not check for the existence of the all hook, so
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   899
 * it will fail unless the all hook exists prior to this function call.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   900
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   901
 * @since 2.5.0
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   902
 * @access private
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   903
 *
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   904
 * @global WP_Hook[] $wp_filter Stores all of the filters and actions.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   905
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   906
 * @param array $args The collected parameters from the hook that was called.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   907
 */
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   908
function _wp_call_all_hook( $args ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   909
	global $wp_filter;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   910
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   911
	$wp_filter['all']->do_all_hook( $args );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   912
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   913
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   914
/**
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   915
 * Builds Unique ID for storage and retrieval.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   916
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   917
 * The old way to serialize the callback caused issues and this function is the
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   918
 * solution. It works by checking for objects and creating a new property in
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   919
 * the class to keep track of the object and new objects of the same class that
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   920
 * need to be added.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   921
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   922
 * It also allows for the removal of actions and filters for objects after they
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   923
 * change class properties. It is possible to include the property $wp_filter_id
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   924
 * in your class and set it to "null" or a number to bypass the workaround.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   925
 * However this will prevent you from adding new classes and any new classes
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   926
 * will overwrite the previous hook by the same class.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   927
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   928
 * Functions and static method callbacks are just returned as strings and
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   929
 * shouldn't have any speed penalty.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   930
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   931
 * @link https://core.trac.wordpress.org/ticket/3875
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   932
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   933
 * @since 2.2.3
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   934
 * @since 5.3.0 Removed workarounds for spl_object_hash().
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   935
 *              `$hook_name` and `$priority` are no longer used,
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   936
 *              and the function always returns a string.
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   937
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   938
 * @access private
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   939
 *
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   940
 * @param string                $hook_name Unused. The name of the filter to build ID for.
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   941
 * @param callable|string|array $callback  The callback to generate ID for. The callback may
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   942
 *                                         or may not exist.
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   943
 * @param int                   $priority  Unused. The order in which the functions
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   944
 *                                         associated with a particular action are executed.
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   945
 * @return string Unique function ID for usage as array key.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   946
 */
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   947
function _wp_filter_build_unique_id( $hook_name, $callback, $priority ) {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   948
	if ( is_string( $callback ) ) {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   949
		return $callback;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   950
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   951
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   952
	if ( is_object( $callback ) ) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   953
		// Closures are currently implemented as objects.
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   954
		$callback = array( $callback, '' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   955
	} else {
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   956
		$callback = (array) $callback;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   957
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   958
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   959
	if ( is_object( $callback[0] ) ) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   960
		// Object class calling.
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   961
		return spl_object_hash( $callback[0] ) . $callback[1];
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   962
	} elseif ( is_string( $callback[0] ) ) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   963
		// Static calling.
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   964
		return $callback[0] . '::' . $callback[1];
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   965
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   966
}