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