wp/wp-includes/plugin.php
changeset 18 be944660c56a
parent 16 a86126ab1dd4
child 19 3d72ae0968f4
equal deleted inserted replaced
17:34716fd837a4 18:be944660c56a
    23 
    23 
    24 // Initialize the filter globals.
    24 // Initialize the filter globals.
    25 require __DIR__ . '/class-wp-hook.php';
    25 require __DIR__ . '/class-wp-hook.php';
    26 
    26 
    27 /** @var WP_Hook[] $wp_filter */
    27 /** @var WP_Hook[] $wp_filter */
    28 global $wp_filter, $wp_actions, $wp_current_filter;
    28 global $wp_filter;
       
    29 
       
    30 /** @var int[] $wp_actions */
       
    31 global $wp_actions;
       
    32 
       
    33 /** @var string[] $wp_current_filter */
       
    34 global $wp_current_filter;
    29 
    35 
    30 if ( $wp_filter ) {
    36 if ( $wp_filter ) {
    31 	$wp_filter = WP_Hook::build_preinitialized_hooks( $wp_filter );
    37 	$wp_filter = WP_Hook::build_preinitialized_hooks( $wp_filter );
    32 } else {
    38 } else {
    33 	$wp_filter = array();
    39 	$wp_filter = array();
    40 if ( ! isset( $wp_current_filter ) ) {
    46 if ( ! isset( $wp_current_filter ) ) {
    41 	$wp_current_filter = array();
    47 	$wp_current_filter = array();
    42 }
    48 }
    43 
    49 
    44 /**
    50 /**
    45  * Hook a function or method to a specific filter action.
    51  * Adds a callback function to a filter hook.
    46  *
    52  *
    47  * WordPress offers filter hooks to allow plugins to modify
    53  * WordPress offers filter hooks to allow plugins to modify
    48  * various types of internal data at runtime.
    54  * various types of internal data at runtime.
    49  *
    55  *
    50  * A plugin can modify data by binding a callback to a filter hook. When the filter
    56  * A plugin can modify data by binding a callback to a filter hook. When the filter
    91  * It is up to you to take care. This is done for optimization purposes, so
    97  * It is up to you to take care. This is done for optimization purposes, so
    92  * everything is as quick as possible.
    98  * everything is as quick as possible.
    93  *
    99  *
    94  * @since 0.71
   100  * @since 0.71
    95  *
   101  *
    96  * @global array $wp_filter A multidimensional array of all hooks and the callbacks hooked to them.
   102  * @global WP_Hook[] $wp_filter A multidimensional array of all hooks and the callbacks hooked to them.
    97  *
   103  *
    98  * @param string   $tag             The name of the filter to hook the $function_to_add callback to.
   104  * @param string   $hook_name     The name of the filter to add the callback to.
    99  * @param callable $function_to_add The callback to be run when the filter is applied.
   105  * @param callable $callback      The callback to be run when the filter is applied.
   100  * @param int      $priority        Optional. Used to specify the order in which the functions
   106  * @param int      $priority      Optional. Used to specify the order in which the functions
   101  *                                  associated with a particular action are executed.
   107  *                                associated with a particular filter are executed.
   102  *                                  Lower numbers correspond with earlier execution,
   108  *                                Lower numbers correspond with earlier execution,
   103  *                                  and functions with the same priority are executed
   109  *                                and functions with the same priority are executed
   104  *                                  in the order in which they were added to the action. Default 10.
   110  *                                in the order in which they were added to the filter. Default 10.
   105  * @param int      $accepted_args   Optional. The number of arguments the function accepts. Default 1.
   111  * @param int      $accepted_args Optional. The number of arguments the function accepts. Default 1.
   106  * @return true
   112  * @return true Always returns true.
   107  */
   113  */
   108 function add_filter( $tag, $function_to_add, $priority = 10, $accepted_args = 1 ) {
   114 function add_filter( $hook_name, $callback, $priority = 10, $accepted_args = 1 ) {
   109 	global $wp_filter;
   115 	global $wp_filter;
   110 	if ( ! isset( $wp_filter[ $tag ] ) ) {
   116 
   111 		$wp_filter[ $tag ] = new WP_Hook();
   117 	if ( ! isset( $wp_filter[ $hook_name ] ) ) {
   112 	}
   118 		$wp_filter[ $hook_name ] = new WP_Hook();
   113 	$wp_filter[ $tag ]->add_filter( $tag, $function_to_add, $priority, $accepted_args );
   119 	}
       
   120 
       
   121 	$wp_filter[ $hook_name ]->add_filter( $hook_name, $callback, $priority, $accepted_args );
       
   122 
   114 	return true;
   123 	return true;
   115 }
   124 }
   116 
   125 
   117 /**
   126 /**
   118  * Check if any filter has been registered for a hook.
       
   119  *
       
   120  * @since 2.5.0
       
   121  *
       
   122  * @global array $wp_filter Stores all of the filters and actions.
       
   123  *
       
   124  * @param string        $tag               The name of the filter hook.
       
   125  * @param callable|bool $function_to_check Optional. The callback to check for. Default false.
       
   126  * @return false|int If $function_to_check is omitted, returns boolean for whether the hook has
       
   127  *                   anything registered. When checking a specific function, the priority of that
       
   128  *                   hook is returned, or false if the function is not attached. When using the
       
   129  *                   $function_to_check argument, this function may return a non-boolean value
       
   130  *                   that evaluates to false (e.g.) 0, so use the === operator for testing the
       
   131  *                   return value.
       
   132  */
       
   133 function has_filter( $tag, $function_to_check = false ) {
       
   134 	global $wp_filter;
       
   135 
       
   136 	if ( ! isset( $wp_filter[ $tag ] ) ) {
       
   137 		return false;
       
   138 	}
       
   139 
       
   140 	return $wp_filter[ $tag ]->has_filter( $tag, $function_to_check );
       
   141 }
       
   142 
       
   143 /**
       
   144  * Calls the callback functions that have been added to a filter hook.
   127  * Calls the callback functions that have been added to a filter hook.
   145  *
   128  *
   146  * The callback functions attached to the filter hook are invoked by calling
   129  * This function invokes all functions attached to filter hook `$hook_name`.
   147  * this function. This function can be used to create a new filter hook by
   130  * It is possible to create new filter hooks by simply calling this function,
   148  * simply calling this function with the name of the new hook specified using
   131  * specifying the name of the new hook using the `$hook_name` parameter.
   149  * the `$tag` parameter.
       
   150  *
   132  *
   151  * The function also allows for multiple additional arguments to be passed to hooks.
   133  * The function also allows for multiple additional arguments to be passed to hooks.
   152  *
   134  *
   153  * Example usage:
   135  * Example usage:
   154  *
   136  *
   168  *      * - $arg1 and $arg2 are the additional arguments passed to the callback.
   150  *      * - $arg1 and $arg2 are the additional arguments passed to the callback.
   169  *     $value = apply_filters( 'example_filter', 'filter me', $arg1, $arg2 );
   151  *     $value = apply_filters( 'example_filter', 'filter me', $arg1, $arg2 );
   170  *
   152  *
   171  * @since 0.71
   153  * @since 0.71
   172  *
   154  *
   173  * @global array $wp_filter         Stores all of the filters and actions.
   155  * @global WP_Hook[] $wp_filter         Stores all of the filters and actions.
   174  * @global array $wp_current_filter Stores the list of current filters with the current one last.
   156  * @global string[]  $wp_current_filter Stores the list of current filters with the current one last.
   175  *
   157  *
   176  * @param string $tag     The name of the filter hook.
   158  * @param string $hook_name The name of the filter hook.
   177  * @param mixed  $value   The value to filter.
   159  * @param mixed  $value     The value to filter.
   178  * @param mixed  ...$args Additional parameters to pass to the callback functions.
   160  * @param mixed  ...$args   Additional parameters to pass to the callback functions.
   179  * @return mixed The filtered value after all hooked functions are applied to it.
   161  * @return mixed The filtered value after all hooked functions are applied to it.
   180  */
   162  */
   181 function apply_filters( $tag, $value ) {
   163 function apply_filters( $hook_name, $value ) {
   182 	global $wp_filter, $wp_current_filter;
   164 	global $wp_filter, $wp_current_filter;
   183 
   165 
   184 	$args = func_get_args();
   166 	$args = func_get_args();
   185 
   167 
   186 	// Do 'all' actions first.
   168 	// Do 'all' actions first.
   187 	if ( isset( $wp_filter['all'] ) ) {
   169 	if ( isset( $wp_filter['all'] ) ) {
   188 		$wp_current_filter[] = $tag;
   170 		$wp_current_filter[] = $hook_name;
   189 		_wp_call_all_hook( $args );
   171 		_wp_call_all_hook( $args );
   190 	}
   172 	}
   191 
   173 
   192 	if ( ! isset( $wp_filter[ $tag ] ) ) {
   174 	if ( ! isset( $wp_filter[ $hook_name ] ) ) {
   193 		if ( isset( $wp_filter['all'] ) ) {
   175 		if ( isset( $wp_filter['all'] ) ) {
   194 			array_pop( $wp_current_filter );
   176 			array_pop( $wp_current_filter );
   195 		}
   177 		}
       
   178 
   196 		return $value;
   179 		return $value;
   197 	}
   180 	}
   198 
   181 
   199 	if ( ! isset( $wp_filter['all'] ) ) {
   182 	if ( ! isset( $wp_filter['all'] ) ) {
   200 		$wp_current_filter[] = $tag;
   183 		$wp_current_filter[] = $hook_name;
   201 	}
   184 	}
   202 
   185 
   203 	// Don't pass the tag name to WP_Hook.
   186 	// Don't pass the tag name to WP_Hook.
   204 	array_shift( $args );
   187 	array_shift( $args );
   205 
   188 
   206 	$filtered = $wp_filter[ $tag ]->apply_filters( $value, $args );
   189 	$filtered = $wp_filter[ $hook_name ]->apply_filters( $value, $args );
   207 
   190 
   208 	array_pop( $wp_current_filter );
   191 	array_pop( $wp_current_filter );
   209 
   192 
   210 	return $filtered;
   193 	return $filtered;
   211 }
   194 }
   214  * Calls the callback functions that have been added to a filter hook, specifying arguments in an array.
   197  * Calls the callback functions that have been added to a filter hook, specifying arguments in an array.
   215  *
   198  *
   216  * @since 3.0.0
   199  * @since 3.0.0
   217  *
   200  *
   218  * @see apply_filters() This function is identical, but the arguments passed to the
   201  * @see apply_filters() This function is identical, but the arguments passed to the
   219  * functions hooked to `$tag` are supplied using an array.
   202  *                      functions hooked to `$hook_name` are supplied using an array.
   220  *
   203  *
   221  * @global array $wp_filter         Stores all of the filters and actions.
   204  * @global WP_Hook[] $wp_filter         Stores all of the filters and actions.
   222  * @global array $wp_current_filter Stores the list of current filters with the current one last.
   205  * @global string[]  $wp_current_filter Stores the list of current filters with the current one last.
   223  *
   206  *
   224  * @param string $tag  The name of the filter hook.
   207  * @param string $hook_name The name of the filter hook.
   225  * @param array  $args The arguments supplied to the functions hooked to $tag.
   208  * @param array  $args      The arguments supplied to the functions hooked to `$hook_name`.
   226  * @return mixed The filtered value after all hooked functions are applied to it.
   209  * @return mixed The filtered value after all hooked functions are applied to it.
   227  */
   210  */
   228 function apply_filters_ref_array( $tag, $args ) {
   211 function apply_filters_ref_array( $hook_name, $args ) {
   229 	global $wp_filter, $wp_current_filter;
   212 	global $wp_filter, $wp_current_filter;
   230 
   213 
   231 	// Do 'all' actions first.
   214 	// Do 'all' actions first.
   232 	if ( isset( $wp_filter['all'] ) ) {
   215 	if ( isset( $wp_filter['all'] ) ) {
   233 		$wp_current_filter[] = $tag;
   216 		$wp_current_filter[] = $hook_name;
   234 		$all_args            = func_get_args(); // phpcs:ignore PHPCompatibility.FunctionUse.ArgumentFunctionsReportCurrentValue.NeedsInspection
   217 		$all_args            = func_get_args(); // phpcs:ignore PHPCompatibility.FunctionUse.ArgumentFunctionsReportCurrentValue.NeedsInspection
   235 		_wp_call_all_hook( $all_args );
   218 		_wp_call_all_hook( $all_args );
   236 	}
   219 	}
   237 
   220 
   238 	if ( ! isset( $wp_filter[ $tag ] ) ) {
   221 	if ( ! isset( $wp_filter[ $hook_name ] ) ) {
   239 		if ( isset( $wp_filter['all'] ) ) {
   222 		if ( isset( $wp_filter['all'] ) ) {
   240 			array_pop( $wp_current_filter );
   223 			array_pop( $wp_current_filter );
   241 		}
   224 		}
       
   225 
   242 		return $args[0];
   226 		return $args[0];
   243 	}
   227 	}
   244 
   228 
   245 	if ( ! isset( $wp_filter['all'] ) ) {
   229 	if ( ! isset( $wp_filter['all'] ) ) {
   246 		$wp_current_filter[] = $tag;
   230 		$wp_current_filter[] = $hook_name;
   247 	}
   231 	}
   248 
   232 
   249 	$filtered = $wp_filter[ $tag ]->apply_filters( $args[0], $args );
   233 	$filtered = $wp_filter[ $hook_name ]->apply_filters( $args[0], $args );
   250 
   234 
   251 	array_pop( $wp_current_filter );
   235 	array_pop( $wp_current_filter );
   252 
   236 
   253 	return $filtered;
   237 	return $filtered;
   254 }
   238 }
   255 
   239 
   256 /**
   240 /**
   257  * Removes a function from a specified filter hook.
   241  * Checks if any filter has been registered for a hook.
   258  *
   242  *
   259  * This function removes a function attached to a specified filter hook. This
   243  * When using the `$callback` argument, this function may return a non-boolean value
   260  * method can be used to remove default functions attached to a specific filter
   244  * that evaluates to false (e.g. 0), so use the `===` operator for testing the return value.
       
   245  *
       
   246  * @since 2.5.0
       
   247  *
       
   248  * @global WP_Hook[] $wp_filter Stores all of the filters and actions.
       
   249  *
       
   250  * @param string         $hook_name The name of the filter hook.
       
   251  * @param callable|false $callback  Optional. The callback to check for. Default false.
       
   252  * @return bool|int If `$callback` is omitted, returns boolean for whether the hook has
       
   253  *                  anything registered. When checking a specific function, the priority
       
   254  *                  of that hook is returned, or false if the function is not attached.
       
   255  */
       
   256 function has_filter( $hook_name, $callback = false ) {
       
   257 	global $wp_filter;
       
   258 
       
   259 	if ( ! isset( $wp_filter[ $hook_name ] ) ) {
       
   260 		return false;
       
   261 	}
       
   262 
       
   263 	return $wp_filter[ $hook_name ]->has_filter( $hook_name, $callback );
       
   264 }
       
   265 
       
   266 /**
       
   267  * Removes a callback function from a filter hook.
       
   268  *
       
   269  * This can be used to remove default functions attached to a specific filter
   261  * hook and possibly replace them with a substitute.
   270  * hook and possibly replace them with a substitute.
   262  *
   271  *
   263  * To remove a hook, the $function_to_remove and $priority arguments must match
   272  * To remove a hook, the `$callback` and `$priority` arguments must match
   264  * when the hook was added. This goes for both filters and actions. No warning
   273  * when the hook was added. This goes for both filters and actions. No warning
   265  * will be given on removal failure.
   274  * will be given on removal failure.
   266  *
   275  *
   267  * @since 1.2.0
   276  * @since 1.2.0
   268  *
   277  *
   269  * @global array $wp_filter Stores all of the filters and actions.
   278  * @global WP_Hook[] $wp_filter Stores all of the filters and actions.
   270  *
   279  *
   271  * @param string   $tag                The filter hook to which the function to be removed is hooked.
   280  * @param string   $hook_name The filter hook to which the function to be removed is hooked.
   272  * @param callable $function_to_remove The name of the function which should be removed.
   281  * @param callable $callback  The name of the function which should be removed.
   273  * @param int      $priority           Optional. The priority of the function. Default 10.
   282  * @param int      $priority  Optional. The exact priority used when adding the original
   274  * @return bool    Whether the function existed before it was removed.
   283  *                            filter callback. Default 10.
   275  */
   284  * @return bool Whether the function existed before it was removed.
   276 function remove_filter( $tag, $function_to_remove, $priority = 10 ) {
   285  */
       
   286 function remove_filter( $hook_name, $callback, $priority = 10 ) {
   277 	global $wp_filter;
   287 	global $wp_filter;
   278 
   288 
   279 	$r = false;
   289 	$r = false;
   280 	if ( isset( $wp_filter[ $tag ] ) ) {
   290 
   281 		$r = $wp_filter[ $tag ]->remove_filter( $tag, $function_to_remove, $priority );
   291 	if ( isset( $wp_filter[ $hook_name ] ) ) {
   282 		if ( ! $wp_filter[ $tag ]->callbacks ) {
   292 		$r = $wp_filter[ $hook_name ]->remove_filter( $hook_name, $callback, $priority );
   283 			unset( $wp_filter[ $tag ] );
   293 
       
   294 		if ( ! $wp_filter[ $hook_name ]->callbacks ) {
       
   295 			unset( $wp_filter[ $hook_name ] );
   284 		}
   296 		}
   285 	}
   297 	}
   286 
   298 
   287 	return $r;
   299 	return $r;
   288 }
   300 }
   289 
   301 
   290 /**
   302 /**
   291  * Remove all of the hooks from a filter.
   303  * Removes all of the callback functions from a filter hook.
   292  *
   304  *
   293  * @since 2.7.0
   305  * @since 2.7.0
   294  *
   306  *
   295  * @global array $wp_filter Stores all of the filters and actions.
   307  * @global WP_Hook[] $wp_filter Stores all of the filters and actions.
   296  *
   308  *
   297  * @param string   $tag      The filter to remove hooks from.
   309  * @param string    $hook_name The filter to remove callbacks from.
   298  * @param int|bool $priority Optional. The priority number to remove. Default false.
   310  * @param int|false $priority  Optional. The priority number to remove them from.
   299  * @return true True when finished.
   311  *                             Default false.
   300  */
   312  * @return true Always returns true.
   301 function remove_all_filters( $tag, $priority = false ) {
   313  */
       
   314 function remove_all_filters( $hook_name, $priority = false ) {
   302 	global $wp_filter;
   315 	global $wp_filter;
   303 
   316 
   304 	if ( isset( $wp_filter[ $tag ] ) ) {
   317 	if ( isset( $wp_filter[ $hook_name ] ) ) {
   305 		$wp_filter[ $tag ]->remove_all_filters( $priority );
   318 		$wp_filter[ $hook_name ]->remove_all_filters( $priority );
   306 		if ( ! $wp_filter[ $tag ]->has_filters() ) {
   319 
   307 			unset( $wp_filter[ $tag ] );
   320 		if ( ! $wp_filter[ $hook_name ]->has_filters() ) {
       
   321 			unset( $wp_filter[ $hook_name ] );
   308 		}
   322 		}
   309 	}
   323 	}
   310 
   324 
   311 	return true;
   325 	return true;
   312 }
   326 }
   313 
   327 
   314 /**
   328 /**
   315  * Retrieve the name of the current filter or action.
   329  * Retrieves the name of the current filter hook.
   316  *
   330  *
   317  * @since 2.5.0
   331  * @since 2.5.0
   318  *
   332  *
   319  * @global array $wp_current_filter Stores the list of current filters with the current one last
   333  * @global string[] $wp_current_filter Stores the list of current filters with the current one last
   320  *
   334  *
   321  * @return string Hook name of the current filter or action.
   335  * @return string Hook name of the current filter.
   322  */
   336  */
   323 function current_filter() {
   337 function current_filter() {
   324 	global $wp_current_filter;
   338 	global $wp_current_filter;
       
   339 
   325 	return end( $wp_current_filter );
   340 	return end( $wp_current_filter );
   326 }
   341 }
   327 
   342 
   328 /**
   343 /**
   329  * Retrieve the name of the current action.
   344  * Returns whether or not a filter hook is currently being processed.
   330  *
       
   331  * @since 3.9.0
       
   332  *
       
   333  * @return string Hook name of the current action.
       
   334  */
       
   335 function current_action() {
       
   336 	return current_filter();
       
   337 }
       
   338 
       
   339 /**
       
   340  * Retrieve the name of a filter currently being processed.
       
   341  *
   345  *
   342  * The function current_filter() only returns the most recent filter or action
   346  * The function current_filter() only returns the most recent filter or action
   343  * being executed. did_action() returns true once the action is initially
   347  * being executed. did_action() returns true once the action is initially
   344  * processed.
   348  * processed.
   345  *
   349  *
   346  * This function allows detection for any filter currently being
   350  * This function allows detection for any filter currently being executed
   347  * executed (despite not being the most recent filter to fire, in the case of
   351  * (regardless of whether it's the most recent filter to fire, in the case of
   348  * hooks called from hook callbacks) to be verified.
   352  * hooks called from hook callbacks) to be verified.
   349  *
   353  *
   350  * @since 3.9.0
   354  * @since 3.9.0
   351  *
   355  *
   352  * @see current_filter()
   356  * @see current_filter()
   353  * @see did_action()
   357  * @see did_action()
   354  * @global array $wp_current_filter Current filter.
   358  * @global string[] $wp_current_filter Current filter.
   355  *
   359  *
   356  * @param null|string $filter Optional. Filter to check. Defaults to null, which
   360  * @param null|string $hook_name Optional. Filter hook to check. Defaults to null,
   357  *                            checks if any filter is currently being run.
   361  *                               which checks if any filter is currently being run.
   358  * @return bool Whether the filter is currently in the stack.
   362  * @return bool Whether the filter is currently in the stack.
   359  */
   363  */
   360 function doing_filter( $filter = null ) {
   364 function doing_filter( $hook_name = null ) {
   361 	global $wp_current_filter;
   365 	global $wp_current_filter;
   362 
   366 
   363 	if ( null === $filter ) {
   367 	if ( null === $hook_name ) {
   364 		return ! empty( $wp_current_filter );
   368 		return ! empty( $wp_current_filter );
   365 	}
   369 	}
   366 
   370 
   367 	return in_array( $filter, $wp_current_filter, true );
   371 	return in_array( $hook_name, $wp_current_filter, true );
   368 }
   372 }
   369 
   373 
   370 /**
   374 /**
   371  * Retrieve the name of an action currently being processed.
   375  * Adds a callback function to an action hook.
   372  *
       
   373  * @since 3.9.0
       
   374  *
       
   375  * @param string|null $action Optional. Action to check. Defaults to null, which checks
       
   376  *                            if any action is currently being run.
       
   377  * @return bool Whether the action is currently in the stack.
       
   378  */
       
   379 function doing_action( $action = null ) {
       
   380 	return doing_filter( $action );
       
   381 }
       
   382 
       
   383 /**
       
   384  * Hooks a function on to a specific action.
       
   385  *
   376  *
   386  * Actions are the hooks that the WordPress core launches at specific points
   377  * Actions are the hooks that the WordPress core launches at specific points
   387  * during execution, or when specific events occur. Plugins can specify that
   378  * during execution, or when specific events occur. Plugins can specify that
   388  * one or more of its PHP functions are executed at these points, using the
   379  * one or more of its PHP functions are executed at these points, using the
   389  * Action API.
   380  * Action API.
   390  *
   381  *
   391  * @since 1.2.0
   382  * @since 1.2.0
   392  *
   383  *
   393  * @param string   $tag             The name of the action to which the $function_to_add is hooked.
   384  * @param string   $hook_name       The name of the action to add the callback to.
   394  * @param callable $function_to_add The name of the function you wish to be called.
   385  * @param callable $callback        The callback to be run when the action is called.
   395  * @param int      $priority        Optional. Used to specify the order in which the functions
   386  * @param int      $priority        Optional. Used to specify the order in which the functions
   396  *                                  associated with a particular action are executed. Default 10.
   387  *                                  associated with a particular action are executed.
   397  *                                  Lower numbers correspond with earlier execution,
   388  *                                  Lower numbers correspond with earlier execution,
   398  *                                  and functions with the same priority are executed
   389  *                                  and functions with the same priority are executed
   399  *                                  in the order in which they were added to the action.
   390  *                                  in the order in which they were added to the action. Default 10.
   400  * @param int      $accepted_args   Optional. The number of arguments the function accepts. Default 1.
   391  * @param int      $accepted_args   Optional. The number of arguments the function accepts. Default 1.
   401  * @return true Will always return true.
   392  * @return true Always returns true.
   402  */
   393  */
   403 function add_action( $tag, $function_to_add, $priority = 10, $accepted_args = 1 ) {
   394 function add_action( $hook_name, $callback, $priority = 10, $accepted_args = 1 ) {
   404 	return add_filter( $tag, $function_to_add, $priority, $accepted_args );
   395 	return add_filter( $hook_name, $callback, $priority, $accepted_args );
   405 }
   396 }
   406 
   397 
   407 /**
   398 /**
   408  * Execute functions hooked on a specific action hook.
   399  * Calls the callback functions that have been added to an action hook.
   409  *
   400  *
   410  * This function invokes all functions attached to action hook `$tag`. It is
   401  * This function invokes all functions attached to action hook `$hook_name`.
   411  * possible to create new action hooks by simply calling this function,
   402  * It is possible to create new action hooks by simply calling this function,
   412  * specifying the name of the new hook using the `$tag` parameter.
   403  * specifying the name of the new hook using the `$hook_name` parameter.
   413  *
   404  *
   414  * You can pass extra arguments to the hooks, much like you can with `apply_filters()`.
   405  * You can pass extra arguments to the hooks, much like you can with `apply_filters()`.
   415  *
   406  *
   416  * Example usage:
   407  * Example usage:
   417  *
   408  *
   431  *
   422  *
   432  * @since 1.2.0
   423  * @since 1.2.0
   433  * @since 5.3.0 Formalized the existing and already documented `...$arg` parameter
   424  * @since 5.3.0 Formalized the existing and already documented `...$arg` parameter
   434  *              by adding it to the function signature.
   425  *              by adding it to the function signature.
   435  *
   426  *
   436  * @global array $wp_filter         Stores all of the filters and actions.
   427  * @global WP_Hook[] $wp_filter         Stores all of the filters and actions.
   437  * @global array $wp_actions        Increments the amount of times action was triggered.
   428  * @global int[]     $wp_actions        Stores the number of times each action was triggered.
   438  * @global array $wp_current_filter Stores the list of current filters with the current one last.
   429  * @global string[]  $wp_current_filter Stores the list of current filters with the current one last.
   439  *
   430  *
   440  * @param string $tag    The name of the action to be executed.
   431  * @param string $hook_name The name of the action to be executed.
   441  * @param mixed  ...$arg Optional. Additional arguments which are passed on to the
   432  * @param mixed  ...$arg    Optional. Additional arguments which are passed on to the
   442  *                       functions hooked to the action. Default empty.
   433  *                          functions hooked to the action. Default empty.
   443  */
   434  */
   444 function do_action( $tag, ...$arg ) {
   435 function do_action( $hook_name, ...$arg ) {
   445 	global $wp_filter, $wp_actions, $wp_current_filter;
   436 	global $wp_filter, $wp_actions, $wp_current_filter;
   446 
   437 
   447 	if ( ! isset( $wp_actions[ $tag ] ) ) {
   438 	if ( ! isset( $wp_actions[ $hook_name ] ) ) {
   448 		$wp_actions[ $tag ] = 1;
   439 		$wp_actions[ $hook_name ] = 1;
   449 	} else {
   440 	} else {
   450 		++$wp_actions[ $tag ];
   441 		++$wp_actions[ $hook_name ];
   451 	}
   442 	}
   452 
   443 
   453 	// Do 'all' actions first.
   444 	// Do 'all' actions first.
   454 	if ( isset( $wp_filter['all'] ) ) {
   445 	if ( isset( $wp_filter['all'] ) ) {
   455 		$wp_current_filter[] = $tag;
   446 		$wp_current_filter[] = $hook_name;
   456 		$all_args            = func_get_args(); // phpcs:ignore PHPCompatibility.FunctionUse.ArgumentFunctionsReportCurrentValue.NeedsInspection
   447 		$all_args            = func_get_args(); // phpcs:ignore PHPCompatibility.FunctionUse.ArgumentFunctionsReportCurrentValue.NeedsInspection
   457 		_wp_call_all_hook( $all_args );
   448 		_wp_call_all_hook( $all_args );
   458 	}
   449 	}
   459 
   450 
   460 	if ( ! isset( $wp_filter[ $tag ] ) ) {
   451 	if ( ! isset( $wp_filter[ $hook_name ] ) ) {
   461 		if ( isset( $wp_filter['all'] ) ) {
   452 		if ( isset( $wp_filter['all'] ) ) {
   462 			array_pop( $wp_current_filter );
   453 			array_pop( $wp_current_filter );
   463 		}
   454 		}
       
   455 
   464 		return;
   456 		return;
   465 	}
   457 	}
   466 
   458 
   467 	if ( ! isset( $wp_filter['all'] ) ) {
   459 	if ( ! isset( $wp_filter['all'] ) ) {
   468 		$wp_current_filter[] = $tag;
   460 		$wp_current_filter[] = $hook_name;
   469 	}
   461 	}
   470 
   462 
   471 	if ( empty( $arg ) ) {
   463 	if ( empty( $arg ) ) {
   472 		$arg[] = '';
   464 		$arg[] = '';
   473 	} elseif ( is_array( $arg[0] ) && 1 === count( $arg[0] ) && isset( $arg[0][0] ) && is_object( $arg[0][0] ) ) {
   465 	} elseif ( is_array( $arg[0] ) && 1 === count( $arg[0] ) && isset( $arg[0][0] ) && is_object( $arg[0][0] ) ) {
   474 		// Backward compatibility for PHP4-style passing of `array( &$this )` as action `$arg`.
   466 		// Backward compatibility for PHP4-style passing of `array( &$this )` as action `$arg`.
   475 		$arg[0] = $arg[0][0];
   467 		$arg[0] = $arg[0][0];
   476 	}
   468 	}
   477 
   469 
   478 	$wp_filter[ $tag ]->do_action( $arg );
   470 	$wp_filter[ $hook_name ]->do_action( $arg );
   479 
   471 
   480 	array_pop( $wp_current_filter );
   472 	array_pop( $wp_current_filter );
   481 }
   473 }
   482 
   474 
   483 /**
   475 /**
   484  * Retrieve the number of times an action is fired.
   476  * Calls the callback functions that have been added to an action hook, specifying arguments in an array.
   485  *
   477  *
   486  * @since 2.1.0
   478  * @since 2.1.0
   487  *
   479  *
   488  * @global array $wp_actions Increments the amount of times action was triggered.
       
   489  *
       
   490  * @param string $tag The name of the action hook.
       
   491  * @return int The number of times action hook $tag is fired.
       
   492  */
       
   493 function did_action( $tag ) {
       
   494 	global $wp_actions;
       
   495 
       
   496 	if ( ! isset( $wp_actions[ $tag ] ) ) {
       
   497 		return 0;
       
   498 	}
       
   499 
       
   500 	return $wp_actions[ $tag ];
       
   501 }
       
   502 
       
   503 /**
       
   504  * Calls the callback functions that have been added to an action hook, specifying arguments in an array.
       
   505  *
       
   506  * @since 2.1.0
       
   507  *
       
   508  * @see do_action() This function is identical, but the arguments passed to the
   480  * @see do_action() This function is identical, but the arguments passed to the
   509  *                  functions hooked to `$tag` are supplied using an array.
   481  *                  functions hooked to `$hook_name` are supplied using an array.
   510  * @global array $wp_filter         Stores all of the filters and actions.
   482  *
   511  * @global array $wp_actions        Increments the amount of times action was triggered.
   483  * @global WP_Hook[] $wp_filter         Stores all of the filters and actions.
   512  * @global array $wp_current_filter Stores the list of current filters with the current one last.
   484  * @global int[]     $wp_actions        Stores the number of times each action was triggered.
   513  *
   485  * @global string[]  $wp_current_filter Stores the list of current filters with the current one last.
   514  * @param string $tag  The name of the action to be executed.
   486  *
   515  * @param array  $args The arguments supplied to the functions hooked to `$tag`.
   487  * @param string $hook_name The name of the action to be executed.
   516  */
   488  * @param array  $args      The arguments supplied to the functions hooked to `$hook_name`.
   517 function do_action_ref_array( $tag, $args ) {
   489  */
       
   490 function do_action_ref_array( $hook_name, $args ) {
   518 	global $wp_filter, $wp_actions, $wp_current_filter;
   491 	global $wp_filter, $wp_actions, $wp_current_filter;
   519 
   492 
   520 	if ( ! isset( $wp_actions[ $tag ] ) ) {
   493 	if ( ! isset( $wp_actions[ $hook_name ] ) ) {
   521 		$wp_actions[ $tag ] = 1;
   494 		$wp_actions[ $hook_name ] = 1;
   522 	} else {
   495 	} else {
   523 		++$wp_actions[ $tag ];
   496 		++$wp_actions[ $hook_name ];
   524 	}
   497 	}
   525 
   498 
   526 	// Do 'all' actions first.
   499 	// Do 'all' actions first.
   527 	if ( isset( $wp_filter['all'] ) ) {
   500 	if ( isset( $wp_filter['all'] ) ) {
   528 		$wp_current_filter[] = $tag;
   501 		$wp_current_filter[] = $hook_name;
   529 		$all_args            = func_get_args(); // phpcs:ignore PHPCompatibility.FunctionUse.ArgumentFunctionsReportCurrentValue.NeedsInspection
   502 		$all_args            = func_get_args(); // phpcs:ignore PHPCompatibility.FunctionUse.ArgumentFunctionsReportCurrentValue.NeedsInspection
   530 		_wp_call_all_hook( $all_args );
   503 		_wp_call_all_hook( $all_args );
   531 	}
   504 	}
   532 
   505 
   533 	if ( ! isset( $wp_filter[ $tag ] ) ) {
   506 	if ( ! isset( $wp_filter[ $hook_name ] ) ) {
   534 		if ( isset( $wp_filter['all'] ) ) {
   507 		if ( isset( $wp_filter['all'] ) ) {
   535 			array_pop( $wp_current_filter );
   508 			array_pop( $wp_current_filter );
   536 		}
   509 		}
       
   510 
   537 		return;
   511 		return;
   538 	}
   512 	}
   539 
   513 
   540 	if ( ! isset( $wp_filter['all'] ) ) {
   514 	if ( ! isset( $wp_filter['all'] ) ) {
   541 		$wp_current_filter[] = $tag;
   515 		$wp_current_filter[] = $hook_name;
   542 	}
   516 	}
   543 
   517 
   544 	$wp_filter[ $tag ]->do_action( $args );
   518 	$wp_filter[ $hook_name ]->do_action( $args );
   545 
   519 
   546 	array_pop( $wp_current_filter );
   520 	array_pop( $wp_current_filter );
   547 }
   521 }
   548 
   522 
   549 /**
   523 /**
   550  * Check if any action has been registered for a hook.
   524  * Checks if any action has been registered for a hook.
       
   525  *
       
   526  * When using the `$callback` argument, this function may return a non-boolean value
       
   527  * that evaluates to false (e.g. 0), so use the `===` operator for testing the return value.
   551  *
   528  *
   552  * @since 2.5.0
   529  * @since 2.5.0
   553  *
   530  *
   554  * @see has_filter() has_action() is an alias of has_filter().
   531  * @see has_filter() has_action() is an alias of has_filter().
   555  *
   532  *
   556  * @param string        $tag               The name of the action hook.
   533  * @param string         $hook_name The name of the action hook.
   557  * @param callable|bool $function_to_check Optional. The callback to check for. Default false.
   534  * @param callable|false $callback  Optional. The callback to check for. Default false.
   558  * @return bool|int If $function_to_check is omitted, returns boolean for whether the hook has
   535  * @return bool|int If `$callback` is omitted, returns boolean for whether the hook has
   559  *                  anything registered. When checking a specific function, the priority of that
   536  *                  anything registered. When checking a specific function, the priority
   560  *                  hook is returned, or false if the function is not attached. When using the
   537  *                  of that hook is returned, or false if the function is not attached.
   561  *                  $function_to_check argument, this function may return a non-boolean value
   538  */
   562  *                  that evaluates to false (e.g.) 0, so use the === operator for testing the
   539 function has_action( $hook_name, $callback = false ) {
   563  *                  return value.
   540 	return has_filter( $hook_name, $callback );
   564  */
   541 }
   565 function has_action( $tag, $function_to_check = false ) {
   542 
   566 	return has_filter( $tag, $function_to_check );
   543 /**
   567 }
   544  * Removes a callback function from an action hook.
   568 
   545  *
   569 /**
   546  * This can be used to remove default functions attached to a specific action
   570  * Removes a function from a specified action hook.
       
   571  *
       
   572  * This function removes a function attached to a specified action hook. This
       
   573  * method can be used to remove default functions attached to a specific filter
       
   574  * hook and possibly replace them with a substitute.
   547  * hook and possibly replace them with a substitute.
   575  *
   548  *
       
   549  * To remove a hook, the `$callback` and `$priority` arguments must match
       
   550  * when the hook was added. This goes for both filters and actions. No warning
       
   551  * will be given on removal failure.
       
   552  *
   576  * @since 1.2.0
   553  * @since 1.2.0
   577  *
   554  *
   578  * @param string   $tag                The action hook to which the function to be removed is hooked.
   555  * @param string   $hook_name The action hook to which the function to be removed is hooked.
   579  * @param callable $function_to_remove The name of the function which should be removed.
   556  * @param callable $callback  The name of the function which should be removed.
   580  * @param int      $priority           Optional. The priority of the function. Default 10.
   557  * @param int      $priority  Optional. The exact priority used when adding the original
       
   558  *                            action callback. Default 10.
   581  * @return bool Whether the function is removed.
   559  * @return bool Whether the function is removed.
   582  */
   560  */
   583 function remove_action( $tag, $function_to_remove, $priority = 10 ) {
   561 function remove_action( $hook_name, $callback, $priority = 10 ) {
   584 	return remove_filter( $tag, $function_to_remove, $priority );
   562 	return remove_filter( $hook_name, $callback, $priority );
   585 }
   563 }
   586 
   564 
   587 /**
   565 /**
   588  * Remove all of the hooks from an action.
   566  * Removes all of the callback functions from an action hook.
   589  *
   567  *
   590  * @since 2.7.0
   568  * @since 2.7.0
   591  *
   569  *
   592  * @param string   $tag      The action to remove hooks from.
   570  * @param string    $hook_name The action to remove callbacks from.
   593  * @param int|bool $priority The priority number to remove them from. Default false.
   571  * @param int|false $priority  Optional. The priority number to remove them from.
   594  * @return true True when finished.
   572  *                             Default false.
   595  */
   573  * @return true Always returns true.
   596 function remove_all_actions( $tag, $priority = false ) {
   574  */
   597 	return remove_all_filters( $tag, $priority );
   575 function remove_all_actions( $hook_name, $priority = false ) {
       
   576 	return remove_all_filters( $hook_name, $priority );
       
   577 }
       
   578 
       
   579 /**
       
   580  * Retrieves the name of the current action hook.
       
   581  *
       
   582  * @since 3.9.0
       
   583  *
       
   584  * @return string Hook name of the current action.
       
   585  */
       
   586 function current_action() {
       
   587 	return current_filter();
       
   588 }
       
   589 
       
   590 /**
       
   591  * Returns whether or not an action hook is currently being processed.
       
   592  *
       
   593  * @since 3.9.0
       
   594  *
       
   595  * @param string|null $hook_name Optional. Action hook to check. Defaults to null,
       
   596  *                               which checks if any action is currently being run.
       
   597  * @return bool Whether the action is currently in the stack.
       
   598  */
       
   599 function doing_action( $hook_name = null ) {
       
   600 	return doing_filter( $hook_name );
       
   601 }
       
   602 
       
   603 /**
       
   604  * Retrieves the number of times an action has been fired during the current request.
       
   605  *
       
   606  * @since 2.1.0
       
   607  *
       
   608  * @global int[] $wp_actions Stores the number of times each action was triggered.
       
   609  *
       
   610  * @param string $hook_name The name of the action hook.
       
   611  * @return int The number of times the action hook has been fired.
       
   612  */
       
   613 function did_action( $hook_name ) {
       
   614 	global $wp_actions;
       
   615 
       
   616 	if ( ! isset( $wp_actions[ $hook_name ] ) ) {
       
   617 		return 0;
       
   618 	}
       
   619 
       
   620 	return $wp_actions[ $hook_name ];
   598 }
   621 }
   599 
   622 
   600 /**
   623 /**
   601  * Fires functions attached to a deprecated filter hook.
   624  * Fires functions attached to a deprecated filter hook.
   602  *
   625  *
   615  *
   638  *
   616  * @since 4.6.0
   639  * @since 4.6.0
   617  *
   640  *
   618  * @see _deprecated_hook()
   641  * @see _deprecated_hook()
   619  *
   642  *
   620  * @param string $tag         The name of the filter hook.
   643  * @param string $hook_name   The name of the filter hook.
   621  * @param array  $args        Array of additional function arguments to be passed to apply_filters().
   644  * @param array  $args        Array of additional function arguments to be passed to apply_filters().
   622  * @param string $version     The version of WordPress that deprecated the hook.
   645  * @param string $version     The version of WordPress that deprecated the hook.
   623  * @param string $replacement Optional. The hook that should have been used. Default empty.
   646  * @param string $replacement Optional. The hook that should have been used. Default empty.
   624  * @param string $message     Optional. A message regarding the change. Default empty.
   647  * @param string $message     Optional. A message regarding the change. Default empty.
   625  */
   648  */
   626 function apply_filters_deprecated( $tag, $args, $version, $replacement = '', $message = '' ) {
   649 function apply_filters_deprecated( $hook_name, $args, $version, $replacement = '', $message = '' ) {
   627 	if ( ! has_filter( $tag ) ) {
   650 	if ( ! has_filter( $hook_name ) ) {
   628 		return $args[0];
   651 		return $args[0];
   629 	}
   652 	}
   630 
   653 
   631 	_deprecated_hook( $tag, $version, $replacement, $message );
   654 	_deprecated_hook( $hook_name, $version, $replacement, $message );
   632 
   655 
   633 	return apply_filters_ref_array( $tag, $args );
   656 	return apply_filters_ref_array( $hook_name, $args );
   634 }
   657 }
   635 
   658 
   636 /**
   659 /**
   637  * Fires functions attached to a deprecated action hook.
   660  * Fires functions attached to a deprecated action hook.
   638  *
   661  *
   642  *
   665  *
   643  * @since 4.6.0
   666  * @since 4.6.0
   644  *
   667  *
   645  * @see _deprecated_hook()
   668  * @see _deprecated_hook()
   646  *
   669  *
   647  * @param string $tag         The name of the action hook.
   670  * @param string $hook_name   The name of the action hook.
   648  * @param array  $args        Array of additional function arguments to be passed to do_action().
   671  * @param array  $args        Array of additional function arguments to be passed to do_action().
   649  * @param string $version     The version of WordPress that deprecated the hook.
   672  * @param string $version     The version of WordPress that deprecated the hook.
   650  * @param string $replacement Optional. The hook that should have been used. Default empty.
   673  * @param string $replacement Optional. The hook that should have been used. Default empty.
   651  * @param string $message     Optional. A message regarding the change. Default empty.
   674  * @param string $message     Optional. A message regarding the change. Default empty.
   652  */
   675  */
   653 function do_action_deprecated( $tag, $args, $version, $replacement = '', $message = '' ) {
   676 function do_action_deprecated( $hook_name, $args, $version, $replacement = '', $message = '' ) {
   654 	if ( ! has_action( $tag ) ) {
   677 	if ( ! has_action( $hook_name ) ) {
   655 		return;
   678 		return;
   656 	}
   679 	}
   657 
   680 
   658 	_deprecated_hook( $tag, $version, $replacement, $message );
   681 	_deprecated_hook( $hook_name, $version, $replacement, $message );
   659 
   682 
   660 	do_action_ref_array( $tag, $args );
   683 	do_action_ref_array( $hook_name, $args );
   661 }
   684 }
   662 
   685 
   663 //
   686 //
   664 // Functions for handling plugins.
   687 // Functions for handling plugins.
   665 //
   688 //
   681 
   704 
   682 	// $wp_plugin_paths contains normalized paths.
   705 	// $wp_plugin_paths contains normalized paths.
   683 	$file = wp_normalize_path( $file );
   706 	$file = wp_normalize_path( $file );
   684 
   707 
   685 	arsort( $wp_plugin_paths );
   708 	arsort( $wp_plugin_paths );
       
   709 
   686 	foreach ( $wp_plugin_paths as $dir => $realdir ) {
   710 	foreach ( $wp_plugin_paths as $dir => $realdir ) {
   687 		if ( strpos( $file, $realdir ) === 0 ) {
   711 		if ( strpos( $file, $realdir ) === 0 ) {
   688 			$file = $dir . substr( $file, strlen( $realdir ) );
   712 			$file = $dir . substr( $file, strlen( $realdir ) );
   689 		}
   713 		}
   690 	}
   714 	}
   715 function wp_register_plugin_realpath( $file ) {
   739 function wp_register_plugin_realpath( $file ) {
   716 	global $wp_plugin_paths;
   740 	global $wp_plugin_paths;
   717 
   741 
   718 	// Normalize, but store as static to avoid recalculation of a constant value.
   742 	// Normalize, but store as static to avoid recalculation of a constant value.
   719 	static $wp_plugin_path = null, $wpmu_plugin_path = null;
   743 	static $wp_plugin_path = null, $wpmu_plugin_path = null;
       
   744 
   720 	if ( ! isset( $wp_plugin_path ) ) {
   745 	if ( ! isset( $wp_plugin_path ) ) {
   721 		$wp_plugin_path   = wp_normalize_path( WP_PLUGIN_DIR );
   746 		$wp_plugin_path   = wp_normalize_path( WP_PLUGIN_DIR );
   722 		$wpmu_plugin_path = wp_normalize_path( WPMU_PLUGIN_DIR );
   747 		$wpmu_plugin_path = wp_normalize_path( WPMU_PLUGIN_DIR );
   723 	}
   748 	}
   724 
   749 
   774  * 'activate_sample.php'.
   799  * 'activate_sample.php'.
   775  *
   800  *
   776  * @since 2.0.0
   801  * @since 2.0.0
   777  *
   802  *
   778  * @param string   $file     The filename of the plugin including the path.
   803  * @param string   $file     The filename of the plugin including the path.
   779  * @param callable $function The function hooked to the 'activate_PLUGIN' action.
   804  * @param callable $callback The function hooked to the 'activate_PLUGIN' action.
   780  */
   805  */
   781 function register_activation_hook( $file, $function ) {
   806 function register_activation_hook( $file, $callback ) {
   782 	$file = plugin_basename( $file );
   807 	$file = plugin_basename( $file );
   783 	add_action( 'activate_' . $file, $function );
   808 	add_action( 'activate_' . $file, $callback );
   784 }
   809 }
   785 
   810 
   786 /**
   811 /**
   787  * Set the deactivation hook for a plugin.
   812  * Sets the deactivation hook for a plugin.
   788  *
   813  *
   789  * When a plugin is deactivated, the action 'deactivate_PLUGINNAME' hook is
   814  * When a plugin is deactivated, the action 'deactivate_PLUGINNAME' hook is
   790  * called. In the name of this hook, PLUGINNAME is replaced with the name
   815  * called. In the name of this hook, PLUGINNAME is replaced with the name
   791  * of the plugin, including the optional subdirectory. For example, when the
   816  * of the plugin, including the optional subdirectory. For example, when the
   792  * plugin is located in wp-content/plugins/sampleplugin/sample.php, then
   817  * plugin is located in wp-content/plugins/sampleplugin/sample.php, then
   797  * 'deactivate_sample.php'.
   822  * 'deactivate_sample.php'.
   798  *
   823  *
   799  * @since 2.0.0
   824  * @since 2.0.0
   800  *
   825  *
   801  * @param string   $file     The filename of the plugin including the path.
   826  * @param string   $file     The filename of the plugin including the path.
   802  * @param callable $function The function hooked to the 'deactivate_PLUGIN' action.
   827  * @param callable $callback The function hooked to the 'deactivate_PLUGIN' action.
   803  */
   828  */
   804 function register_deactivation_hook( $file, $function ) {
   829 function register_deactivation_hook( $file, $callback ) {
   805 	$file = plugin_basename( $file );
   830 	$file = plugin_basename( $file );
   806 	add_action( 'deactivate_' . $file, $function );
   831 	add_action( 'deactivate_' . $file, $callback );
   807 }
   832 }
   808 
   833 
   809 /**
   834 /**
   810  * Set the uninstallation hook for a plugin.
   835  * Sets the uninstallation hook for a plugin.
   811  *
   836  *
   812  * Registers the uninstall hook that will be called when the user clicks on the
   837  * Registers the uninstall hook that will be called when the user clicks on the
   813  * uninstall link that calls for the plugin to uninstall itself. The link won't
   838  * uninstall link that calls for the plugin to uninstall itself. The link won't
   814  * be active unless the plugin hooks into the action.
   839  * be active unless the plugin hooks into the action.
   815  *
   840  *
   843 	 * cases. Emphasis should be put on using the 'uninstall.php' way of
   868 	 * cases. Emphasis should be put on using the 'uninstall.php' way of
   844 	 * uninstalling the plugin.
   869 	 * uninstalling the plugin.
   845 	 */
   870 	 */
   846 	$uninstallable_plugins = (array) get_option( 'uninstall_plugins' );
   871 	$uninstallable_plugins = (array) get_option( 'uninstall_plugins' );
   847 	$plugin_basename       = plugin_basename( $file );
   872 	$plugin_basename       = plugin_basename( $file );
       
   873 
   848 	if ( ! isset( $uninstallable_plugins[ $plugin_basename ] ) || $uninstallable_plugins[ $plugin_basename ] !== $callback ) {
   874 	if ( ! isset( $uninstallable_plugins[ $plugin_basename ] ) || $uninstallable_plugins[ $plugin_basename ] !== $callback ) {
   849 		$uninstallable_plugins[ $plugin_basename ] = $callback;
   875 		$uninstallable_plugins[ $plugin_basename ] = $callback;
   850 		update_option( 'uninstall_plugins', $uninstallable_plugins );
   876 		update_option( 'uninstall_plugins', $uninstallable_plugins );
   851 	}
   877 	}
   852 }
   878 }
   853 
   879 
   854 /**
   880 /**
   855  * Call the 'all' hook, which will process the functions hooked into it.
   881  * Calls the 'all' hook, which will process the functions hooked into it.
   856  *
   882  *
   857  * The 'all' hook passes all of the arguments or parameters that were used for
   883  * The 'all' hook passes all of the arguments or parameters that were used for
   858  * the hook, which this function was called for.
   884  * the hook, which this function was called for.
   859  *
   885  *
   860  * This function is used internally for apply_filters(), do_action(), and
   886  * This function is used internally for apply_filters(), do_action(), and
   863  * it will fail unless the all hook exists prior to this function call.
   889  * it will fail unless the all hook exists prior to this function call.
   864  *
   890  *
   865  * @since 2.5.0
   891  * @since 2.5.0
   866  * @access private
   892  * @access private
   867  *
   893  *
   868  * @global array $wp_filter Stores all of the filters and actions.
   894  * @global WP_Hook[] $wp_filter Stores all of the filters and actions.
   869  *
   895  *
   870  * @param array $args The collected parameters from the hook that was called.
   896  * @param array $args The collected parameters from the hook that was called.
   871  */
   897  */
   872 function _wp_call_all_hook( $args ) {
   898 function _wp_call_all_hook( $args ) {
   873 	global $wp_filter;
   899 	global $wp_filter;
   874 
   900 
   875 	$wp_filter['all']->do_all_hook( $args );
   901 	$wp_filter['all']->do_all_hook( $args );
   876 }
   902 }
   877 
   903 
   878 /**
   904 /**
   879  * Build Unique ID for storage and retrieval.
   905  * Builds Unique ID for storage and retrieval.
   880  *
   906  *
   881  * The old way to serialize the callback caused issues and this function is the
   907  * The old way to serialize the callback caused issues and this function is the
   882  * solution. It works by checking for objects and creating a new property in
   908  * solution. It works by checking for objects and creating a new property in
   883  * the class to keep track of the object and new objects of the same class that
   909  * the class to keep track of the object and new objects of the same class that
   884  * need to be added.
   910  * need to be added.
   894  *
   920  *
   895  * @link https://core.trac.wordpress.org/ticket/3875
   921  * @link https://core.trac.wordpress.org/ticket/3875
   896  *
   922  *
   897  * @since 2.2.3
   923  * @since 2.2.3
   898  * @since 5.3.0 Removed workarounds for spl_object_hash().
   924  * @since 5.3.0 Removed workarounds for spl_object_hash().
   899  *              `$tag` and `$priority` are no longer used,
   925  *              `$hook_name` and `$priority` are no longer used,
   900  *              and the function always returns a string.
   926  *              and the function always returns a string.
   901  * @access private
   927  * @access private
   902  *
   928  *
   903  * @param string   $tag      Unused. The name of the filter to build ID for.
   929  * @param string   $hook_name Unused. The name of the filter to build ID for.
   904  * @param callable $function The function to generate ID for.
   930  * @param callable $callback  The function to generate ID for.
   905  * @param int      $priority Unused. The order in which the functions
   931  * @param int      $priority  Unused. The order in which the functions
   906  *                           associated with a particular action are executed.
   932  *                            associated with a particular action are executed.
   907  * @return string Unique function ID for usage as array key.
   933  * @return string Unique function ID for usage as array key.
   908  */
   934  */
   909 function _wp_filter_build_unique_id( $tag, $function, $priority ) {
   935 function _wp_filter_build_unique_id( $hook_name, $callback, $priority ) {
   910 	if ( is_string( $function ) ) {
   936 	if ( is_string( $callback ) ) {
   911 		return $function;
   937 		return $callback;
   912 	}
   938 	}
   913 
   939 
   914 	if ( is_object( $function ) ) {
   940 	if ( is_object( $callback ) ) {
   915 		// Closures are currently implemented as objects.
   941 		// Closures are currently implemented as objects.
   916 		$function = array( $function, '' );
   942 		$callback = array( $callback, '' );
   917 	} else {
   943 	} else {
   918 		$function = (array) $function;
   944 		$callback = (array) $callback;
   919 	}
   945 	}
   920 
   946 
   921 	if ( is_object( $function[0] ) ) {
   947 	if ( is_object( $callback[0] ) ) {
   922 		// Object class calling.
   948 		// Object class calling.
   923 		return spl_object_hash( $function[0] ) . $function[1];
   949 		return spl_object_hash( $callback[0] ) . $callback[1];
   924 	} elseif ( is_string( $function[0] ) ) {
   950 	} elseif ( is_string( $callback[0] ) ) {
   925 		// Static calling.
   951 		// Static calling.
   926 		return $function[0] . '::' . $function[1];
   952 		return $callback[0] . '::' . $callback[1];
   927 	}
   953 	}
   928 }
   954 }