raw
mp-wp_genesis           1 <?php
mp-wp_genesis 2 /**
mp-wp_genesis 3 * The plugin API is located in this file, which allows for creating actions
mp-wp_genesis 4 * and filters and hooking functions, and methods. The functions or methods will
mp-wp_genesis 5 * then be run when the action or filter is called.
mp-wp_genesis 6 *
mp-wp_genesis 7 * The API callback examples reference functions, but can be methods of classes.
mp-wp_genesis 8 * To hook methods, you'll need to pass an array one of two ways.
mp-wp_genesis 9 *
mp-wp_genesis 10 * Any of the syntaxes explained in the PHP documentation for the
mp-wp_genesis 11 * {@link http://us2.php.net/manual/en/language.pseudo-types.php#language.types.callback 'callback'}
mp-wp_genesis 12 * type are valid.
mp-wp_genesis 13 *
mp-wp_genesis 14 * Also see the {@link http://codex.wordpress.org/Plugin_API Plugin API} for
mp-wp_genesis 15 * more information and examples on how to use a lot of these functions.
mp-wp_genesis 16 *
mp-wp_genesis 17 * @package WordPress
mp-wp_genesis 18 * @subpackage Plugin
mp-wp_genesis 19 * @since 1.5
mp-wp_genesis 20 */
mp-wp_genesis 21
mp-wp_genesis 22 /**
mp-wp_genesis 23 * Hooks a function or method to a specific filter action.
mp-wp_genesis 24 *
mp-wp_genesis 25 * Filters are the hooks that WordPress launches to modify text of various types
mp-wp_genesis 26 * before adding it to the database or sending it to the browser screen. Plugins
mp-wp_genesis 27 * can specify that one or more of its PHP functions is executed to
mp-wp_genesis 28 * modify specific types of text at these times, using the Filter API.
mp-wp_genesis 29 *
mp-wp_genesis 30 * To use the API, the following code should be used to bind a callback to the
mp-wp_genesis 31 * filter.
mp-wp_genesis 32 *
mp-wp_genesis 33 * <code>
mp-wp_genesis 34 * function example_hook($example) { echo $example; }
mp-wp_genesis 35 * add_filter('example_filter', 'example_hook');
mp-wp_genesis 36 * </code>
mp-wp_genesis 37 *
mp-wp_genesis 38 * In WordPress 1.5.1+, hooked functions can take extra arguments that are set
mp-wp_genesis 39 * when the matching do_action() or apply_filters() call is run. The
mp-wp_genesis 40 * $accepted_args allow for calling functions only when the number of args
mp-wp_genesis 41 * match. Hooked functions can take extra arguments that are set when the
mp-wp_genesis 42 * matching do_action() or apply_filters() call is run. For example, the action
mp-wp_genesis 43 * comment_id_not_found will pass any functions that hook onto it the ID of the
mp-wp_genesis 44 * requested comment.
mp-wp_genesis 45 *
mp-wp_genesis 46 * <strong>Note:</strong> the function will return true no matter if the
mp-wp_genesis 47 * function was hooked fails or not. There are no checks for whether the
mp-wp_genesis 48 * function exists beforehand and no checks to whether the <tt>$function_to_add
mp-wp_genesis 49 * is even a string. It is up to you to take care and this is done for
mp-wp_genesis 50 * optimization purposes, so everything is as quick as possible.
mp-wp_genesis 51 *
mp-wp_genesis 52 * @package WordPress
mp-wp_genesis 53 * @subpackage Plugin
mp-wp_genesis 54 * @since 0.71
mp-wp_genesis 55 * @global array $wp_filter Stores all of the filters added in the form of
mp-wp_genesis 56 * wp_filter['tag']['array of priorities']['array of functions serialized']['array of ['array (functions, accepted_args)]']
mp-wp_genesis 57 * @global array $merged_filters Tracks the tags that need to be merged for later. If the hook is added, it doesn't need to run through that process.
mp-wp_genesis 58 *
mp-wp_genesis 59 * @param string $tag The name of the filter to hook the $function_to_add to.
mp-wp_genesis 60 * @param callback $function_to_add The name of the function to be called when the filter is applied.
mp-wp_genesis 61 * @param int $priority optional. Used to specify the order in which the functions associated with a particular action are executed (default: 10). Lower numbers correspond with earlier execution, and functions with the same priority are executed in the order in which they were added to the action.
mp-wp_genesis 62 * @param int $accepted_args optional. The number of arguments the function accept (default 1).
mp-wp_genesis 63 * @return boolean true
mp-wp_genesis 64 */
mp-wp_genesis 65 function add_filter($tag, $function_to_add, $priority = 10, $accepted_args = 1) {
mp-wp_genesis 66 global $wp_filter, $merged_filters;
mp-wp_genesis 67
mp-wp_genesis 68 $idx = _wp_filter_build_unique_id($tag, $function_to_add, $priority);
mp-wp_genesis 69 $wp_filter[$tag][$priority][$idx] = array('function' => $function_to_add, 'accepted_args' => $accepted_args);
mp-wp_genesis 70 unset( $merged_filters[ $tag ] );
mp-wp_genesis 71 return true;
mp-wp_genesis 72 }
mp-wp_genesis 73
mp-wp_genesis 74 /**
mp-wp_genesis 75 * Check if any filter has been registered for a hook.
mp-wp_genesis 76 *
mp-wp_genesis 77 * @package WordPress
mp-wp_genesis 78 * @subpackage Plugin
mp-wp_genesis 79 * @since 2.5
mp-wp_genesis 80 * @global array $wp_filter Stores all of the filters
mp-wp_genesis 81 *
mp-wp_genesis 82 * @param string $tag The name of the filter hook.
mp-wp_genesis 83 * @param callback $function_to_check optional. If specified, return the priority of that function on this hook or false if not attached.
mp-wp_genesis 84 * @return int|boolean Optionally returns the priority on that hook for the specified function.
mp-wp_genesis 85 */
mp-wp_genesis 86 function has_filter($tag, $function_to_check = false) {
mp-wp_genesis 87 global $wp_filter;
mp-wp_genesis 88
mp-wp_genesis 89 $has = !empty($wp_filter[$tag]);
mp-wp_genesis 90 if ( false === $function_to_check || false == $has )
mp-wp_genesis 91 return $has;
mp-wp_genesis 92
mp-wp_genesis 93 if ( !$idx = _wp_filter_build_unique_id($tag, $function_to_check, false) )
mp-wp_genesis 94 return false;
mp-wp_genesis 95
mp-wp_genesis 96 foreach ( (array) array_keys($wp_filter[$tag]) as $priority ) {
mp-wp_genesis 97 if ( isset($wp_filter[$tag][$priority][$idx]) )
mp-wp_genesis 98 return $priority;
mp-wp_genesis 99 }
mp-wp_genesis 100
mp-wp_genesis 101 return false;
mp-wp_genesis 102 }
mp-wp_genesis 103
mp-wp_genesis 104 /**
mp-wp_genesis 105 * Call the functions added to a filter hook.
mp-wp_genesis 106 *
mp-wp_genesis 107 * The callback functions attached to filter hook $tag are invoked by calling
mp-wp_genesis 108 * this function. This function can be used to create a new filter hook by
mp-wp_genesis 109 * simply calling this function with the name of the new hook specified using
mp-wp_genesis 110 * the $tag parameter.
mp-wp_genesis 111 *
mp-wp_genesis 112 * The function allows for additional arguments to be added and passed to hooks.
mp-wp_genesis 113 * <code>
mp-wp_genesis 114 * function example_hook($string, $arg1, $arg2)
mp-wp_genesis 115 * {
mp-wp_genesis 116 * //Do stuff
mp-wp_genesis 117 * return $string;
mp-wp_genesis 118 * }
mp-wp_genesis 119 * $value = apply_filters('example_filter', 'filter me', 'arg1', 'arg2');
mp-wp_genesis 120 * </code>
mp-wp_genesis 121 *
mp-wp_genesis 122 * @package WordPress
mp-wp_genesis 123 * @subpackage Plugin
mp-wp_genesis 124 * @since 0.71
mp-wp_genesis 125 * @global array $wp_filter Stores all of the filters
mp-wp_genesis 126 * @global array $merged_filters Merges the filter hooks using this function.
mp-wp_genesis 127 * @global array $wp_current_filter stores the list of current filters with the current one last
mp-wp_genesis 128 *
mp-wp_genesis 129 * @param string $tag The name of the filter hook.
mp-wp_genesis 130 * @param mixed $value The value on which the filters hooked to <tt>$tag</tt> are applied on.
mp-wp_genesis 131 * @param mixed $var,... Additional variables passed to the functions hooked to <tt>$tag</tt>.
mp-wp_genesis 132 * @return mixed The filtered value after all hooked functions are applied to it.
mp-wp_genesis 133 */
mp-wp_genesis 134 function apply_filters($tag, $value) {
mp-wp_genesis 135 global $wp_filter, $merged_filters, $wp_current_filter;
mp-wp_genesis 136
mp-wp_genesis 137 $args = array();
mp-wp_genesis 138 $wp_current_filter[] = $tag;
mp-wp_genesis 139
mp-wp_genesis 140 // Do 'all' actions first
mp-wp_genesis 141 if ( isset($wp_filter['all']) ) {
mp-wp_genesis 142 $args = func_get_args();
mp-wp_genesis 143 _wp_call_all_hook($args);
mp-wp_genesis 144 }
mp-wp_genesis 145
mp-wp_genesis 146 if ( !isset($wp_filter[$tag]) ) {
mp-wp_genesis 147 array_pop($wp_current_filter);
mp-wp_genesis 148 return $value;
mp-wp_genesis 149 }
mp-wp_genesis 150
mp-wp_genesis 151 // Sort
mp-wp_genesis 152 if ( !isset( $merged_filters[ $tag ] ) ) {
mp-wp_genesis 153 ksort($wp_filter[$tag]);
mp-wp_genesis 154 $merged_filters[ $tag ] = true;
mp-wp_genesis 155 }
mp-wp_genesis 156
mp-wp_genesis 157 reset( $wp_filter[ $tag ] );
mp-wp_genesis 158
mp-wp_genesis 159 if ( empty($args) )
mp-wp_genesis 160 $args = func_get_args();
mp-wp_genesis 161
mp-wp_genesis 162 do {
mp-wp_genesis 163 foreach( (array) current($wp_filter[$tag]) as $the_ )
mp-wp_genesis 164 if ( !is_null($the_['function']) ){
mp-wp_genesis 165 $args[1] = $value;
mp-wp_genesis 166 $value = call_user_func_array($the_['function'], array_slice($args, 1, (int) $the_['accepted_args']));
mp-wp_genesis 167 }
mp-wp_genesis 168
mp-wp_genesis 169 } while ( next($wp_filter[$tag]) !== false );
mp-wp_genesis 170
mp-wp_genesis 171 array_pop( $wp_current_filter );
mp-wp_genesis 172
mp-wp_genesis 173 return $value;
mp-wp_genesis 174 }
mp-wp_genesis 175
mp-wp_genesis 176 /**
mp-wp_genesis 177 * Removes a function from a specified filter hook.
mp-wp_genesis 178 *
mp-wp_genesis 179 * This function removes a function attached to a specified filter hook. This
mp-wp_genesis 180 * method can be used to remove default functions attached to a specific filter
mp-wp_genesis 181 * hook and possibly replace them with a substitute.
mp-wp_genesis 182 *
mp-wp_genesis 183 * To remove a hook, the $function_to_remove and $priority arguments must match
mp-wp_genesis 184 * when the hook was added. This goes for both filters and actions. No warning
mp-wp_genesis 185 * will be given on removal failure.
mp-wp_genesis 186 *
mp-wp_genesis 187 * @package WordPress
mp-wp_genesis 188 * @subpackage Plugin
mp-wp_genesis 189 * @since 1.2
mp-wp_genesis 190 *
mp-wp_genesis 191 * @param string $tag The filter hook to which the function to be removed is hooked.
mp-wp_genesis 192 * @param callback $function_to_remove The name of the function which should be removed.
mp-wp_genesis 193 * @param int $priority optional. The priority of the function (default: 10).
mp-wp_genesis 194 * @param int $accepted_args optional. The number of arguments the function accpets (default: 1).
mp-wp_genesis 195 * @return boolean Whether the function existed before it was removed.
mp-wp_genesis 196 */
mp-wp_genesis 197 function remove_filter($tag, $function_to_remove, $priority = 10, $accepted_args = 1) {
mp-wp_genesis 198 $function_to_remove = _wp_filter_build_unique_id($tag, $function_to_remove, $priority);
mp-wp_genesis 199
mp-wp_genesis 200 $r = isset($GLOBALS['wp_filter'][$tag][$priority][$function_to_remove]);
mp-wp_genesis 201
mp-wp_genesis 202 if ( true === $r) {
mp-wp_genesis 203 unset($GLOBALS['wp_filter'][$tag][$priority][$function_to_remove]);
mp-wp_genesis 204 if ( empty($GLOBALS['wp_filter'][$tag][$priority]) )
mp-wp_genesis 205 unset($GLOBALS['wp_filter'][$tag][$priority]);
mp-wp_genesis 206 unset($GLOBALS['merged_filters'][$tag]);
mp-wp_genesis 207 }
mp-wp_genesis 208
mp-wp_genesis 209 return $r;
mp-wp_genesis 210 }
mp-wp_genesis 211
mp-wp_genesis 212 /**
mp-wp_genesis 213 * Remove all of the hooks from a filter.
mp-wp_genesis 214 *
mp-wp_genesis 215 * @since 2.7
mp-wp_genesis 216 *
mp-wp_genesis 217 * @param string $tag The filter to remove hooks from.
mp-wp_genesis 218 * @param int $priority The priority number to remove.
mp-wp_genesis 219 * @return bool True when finished.
mp-wp_genesis 220 */
mp-wp_genesis 221 function remove_all_filters($tag, $priority = false) {
mp-wp_genesis 222 global $wp_filter, $merged_filters;
mp-wp_genesis 223
mp-wp_genesis 224 if( isset($wp_filter[$tag]) ) {
mp-wp_genesis 225 if( false !== $priority && isset($$wp_filter[$tag][$priority]) )
mp-wp_genesis 226 unset($wp_filter[$tag][$priority]);
mp-wp_genesis 227 else
mp-wp_genesis 228 unset($wp_filter[$tag]);
mp-wp_genesis 229 }
mp-wp_genesis 230
mp-wp_genesis 231 if( isset($merged_filters[$tag]) )
mp-wp_genesis 232 unset($merged_filters[$tag]);
mp-wp_genesis 233
mp-wp_genesis 234 return true;
mp-wp_genesis 235 }
mp-wp_genesis 236
mp-wp_genesis 237 /**
mp-wp_genesis 238 * Retrieve the name of the current filter or action.
mp-wp_genesis 239 *
mp-wp_genesis 240 * @package WordPress
mp-wp_genesis 241 * @subpackage Plugin
mp-wp_genesis 242 * @since 2.5
mp-wp_genesis 243 *
mp-wp_genesis 244 * @return string Hook name of the current filter or action.
mp-wp_genesis 245 */
mp-wp_genesis 246 function current_filter() {
mp-wp_genesis 247 global $wp_current_filter;
mp-wp_genesis 248 return end( $wp_current_filter );
mp-wp_genesis 249 }
mp-wp_genesis 250
mp-wp_genesis 251
mp-wp_genesis 252 /**
mp-wp_genesis 253 * Hooks a function on to a specific action.
mp-wp_genesis 254 *
mp-wp_genesis 255 * Actions are the hooks that the WordPress core launches at specific points
mp-wp_genesis 256 * during execution, or when specific events occur. Plugins can specify that
mp-wp_genesis 257 * one or more of its PHP functions are executed at these points, using the
mp-wp_genesis 258 * Action API.
mp-wp_genesis 259 *
mp-wp_genesis 260 * @uses add_filter() Adds an action. Parameter list and functionality are the same.
mp-wp_genesis 261 *
mp-wp_genesis 262 * @package WordPress
mp-wp_genesis 263 * @subpackage Plugin
mp-wp_genesis 264 * @since 1.2
mp-wp_genesis 265 *
mp-wp_genesis 266 * @param string $tag The name of the action to which the $function_to_add is hooked.
mp-wp_genesis 267 * @param callback $function_to_add The name of the function you wish to be called.
mp-wp_genesis 268 * @param int $priority optional. Used to specify the order in which the functions associated with a particular action are executed (default: 10). Lower numbers correspond with earlier execution, and functions with the same priority are executed in the order in which they were added to the action.
mp-wp_genesis 269 * @param int $accepted_args optional. The number of arguments the function accept (default 1).
mp-wp_genesis 270 */
mp-wp_genesis 271 function add_action($tag, $function_to_add, $priority = 10, $accepted_args = 1) {
mp-wp_genesis 272 return add_filter($tag, $function_to_add, $priority, $accepted_args);
mp-wp_genesis 273 }
mp-wp_genesis 274
mp-wp_genesis 275
mp-wp_genesis 276 /**
mp-wp_genesis 277 * Execute functions hooked on a specific action hook.
mp-wp_genesis 278 *
mp-wp_genesis 279 * This function invokes all functions attached to action hook $tag. It is
mp-wp_genesis 280 * possible to create new action hooks by simply calling this function,
mp-wp_genesis 281 * specifying the name of the new hook using the <tt>$tag</tt> parameter.
mp-wp_genesis 282 *
mp-wp_genesis 283 * You can pass extra arguments to the hooks, much like you can with
mp-wp_genesis 284 * apply_filters().
mp-wp_genesis 285 *
mp-wp_genesis 286 * @see apply_filters() This function works similar with the exception that
mp-wp_genesis 287 * nothing is returned and only the functions or methods are called.
mp-wp_genesis 288 *
mp-wp_genesis 289 * @package WordPress
mp-wp_genesis 290 * @subpackage Plugin
mp-wp_genesis 291 * @since 1.2
mp-wp_genesis 292 * @global array $wp_filter Stores all of the filters
mp-wp_genesis 293 * @global array $wp_actions Increments the amount of times action was triggered.
mp-wp_genesis 294 *
mp-wp_genesis 295 * @param string $tag The name of the action to be executed.
mp-wp_genesis 296 * @param mixed $arg,... Optional additional arguments which are passed on to the functions hooked to the action.
mp-wp_genesis 297 * @return null Will return null if $tag does not exist in $wp_filter array
mp-wp_genesis 298 */
mp-wp_genesis 299 function do_action($tag, $arg = '') {
mp-wp_genesis 300 global $wp_filter, $wp_actions, $merged_filters, $wp_current_filter;
mp-wp_genesis 301
mp-wp_genesis 302 if ( is_array($wp_actions) )
mp-wp_genesis 303 $wp_actions[] = $tag;
mp-wp_genesis 304 else
mp-wp_genesis 305 $wp_actions = array($tag);
mp-wp_genesis 306
mp-wp_genesis 307 $wp_current_filter[] = $tag;
mp-wp_genesis 308
mp-wp_genesis 309 // Do 'all' actions first
mp-wp_genesis 310 if ( isset($wp_filter['all']) ) {
mp-wp_genesis 311 $all_args = func_get_args();
mp-wp_genesis 312 _wp_call_all_hook($all_args);
mp-wp_genesis 313 }
mp-wp_genesis 314
mp-wp_genesis 315 if ( !isset($wp_filter[$tag]) ) {
mp-wp_genesis 316 array_pop($wp_current_filter);
mp-wp_genesis 317 return;
mp-wp_genesis 318 }
mp-wp_genesis 319
mp-wp_genesis 320 $args = array();
mp-wp_genesis 321 if ( is_array($arg) && 1 == count($arg) && is_object($arg[0]) ) // array(&$this)
mp-wp_genesis 322 $args[] =& $arg[0];
mp-wp_genesis 323 else
mp-wp_genesis 324 $args[] = $arg;
mp-wp_genesis 325 for ( $a = 2; $a < func_num_args(); $a++ )
mp-wp_genesis 326 $args[] = func_get_arg($a);
mp-wp_genesis 327
mp-wp_genesis 328 // Sort
mp-wp_genesis 329 if ( !isset( $merged_filters[ $tag ] ) ) {
mp-wp_genesis 330 ksort($wp_filter[$tag]);
mp-wp_genesis 331 $merged_filters[ $tag ] = true;
mp-wp_genesis 332 }
mp-wp_genesis 333
mp-wp_genesis 334 reset( $wp_filter[ $tag ] );
mp-wp_genesis 335
mp-wp_genesis 336 do {
mp-wp_genesis 337 foreach ( (array) current($wp_filter[$tag]) as $the_ )
mp-wp_genesis 338 if ( !is_null($the_['function']) )
mp-wp_genesis 339 call_user_func_array($the_['function'], array_slice($args, 0, (int) $the_['accepted_args']));
mp-wp_genesis 340
mp-wp_genesis 341 } while ( next($wp_filter[$tag]) !== false );
mp-wp_genesis 342
mp-wp_genesis 343 array_pop($wp_current_filter);
mp-wp_genesis 344 }
mp-wp_genesis 345
mp-wp_genesis 346 /**
mp-wp_genesis 347 * Retrieve the number times an action is fired.
mp-wp_genesis 348 *
mp-wp_genesis 349 * @package WordPress
mp-wp_genesis 350 * @subpackage Plugin
mp-wp_genesis 351 * @since 2.1
mp-wp_genesis 352 * @global array $wp_actions Increments the amount of times action was triggered.
mp-wp_genesis 353 *
mp-wp_genesis 354 * @param string $tag The name of the action hook.
mp-wp_genesis 355 * @return int The number of times action hook <tt>$tag</tt> is fired
mp-wp_genesis 356 */
mp-wp_genesis 357 function did_action($tag) {
mp-wp_genesis 358 global $wp_actions;
mp-wp_genesis 359
mp-wp_genesis 360 if ( empty($wp_actions) )
mp-wp_genesis 361 return 0;
mp-wp_genesis 362
mp-wp_genesis 363 return count(array_keys($wp_actions, $tag));
mp-wp_genesis 364 }
mp-wp_genesis 365
mp-wp_genesis 366 /**
mp-wp_genesis 367 * Execute functions hooked on a specific action hook, specifying arguments in an array.
mp-wp_genesis 368 *
mp-wp_genesis 369 * @see do_action() This function is identical, but the arguments passed to the
mp-wp_genesis 370 * functions hooked to <tt>$tag</tt> are supplied using an array.
mp-wp_genesis 371 *
mp-wp_genesis 372 * @package WordPress
mp-wp_genesis 373 * @subpackage Plugin
mp-wp_genesis 374 * @since 2.1
mp-wp_genesis 375 * @global array $wp_filter Stores all of the filters
mp-wp_genesis 376 * @global array $wp_actions Increments the amount of times action was triggered.
mp-wp_genesis 377 *
mp-wp_genesis 378 * @param string $tag The name of the action to be executed.
mp-wp_genesis 379 * @param array $args The arguments supplied to the functions hooked to <tt>$tag</tt>
mp-wp_genesis 380 * @return null Will return null if $tag does not exist in $wp_filter array
mp-wp_genesis 381 */
mp-wp_genesis 382 function do_action_ref_array($tag, $args) {
mp-wp_genesis 383 global $wp_filter, $wp_actions, $merged_filters, $wp_current_filter;
mp-wp_genesis 384
mp-wp_genesis 385 if ( !is_array($wp_actions) )
mp-wp_genesis 386 $wp_actions = array($tag);
mp-wp_genesis 387 else
mp-wp_genesis 388 $wp_actions[] = $tag;
mp-wp_genesis 389
mp-wp_genesis 390 $wp_current_filter[] = $tag;
mp-wp_genesis 391
mp-wp_genesis 392 // Do 'all' actions first
mp-wp_genesis 393 if ( isset($wp_filter['all']) ) {
mp-wp_genesis 394 $all_args = func_get_args();
mp-wp_genesis 395 _wp_call_all_hook($all_args);
mp-wp_genesis 396 }
mp-wp_genesis 397
mp-wp_genesis 398 if ( !isset($wp_filter[$tag]) ) {
mp-wp_genesis 399 array_pop($wp_current_filter);
mp-wp_genesis 400 return;
mp-wp_genesis 401 }
mp-wp_genesis 402
mp-wp_genesis 403 // Sort
mp-wp_genesis 404 if ( !isset( $merged_filters[ $tag ] ) ) {
mp-wp_genesis 405 ksort($wp_filter[$tag]);
mp-wp_genesis 406 $merged_filters[ $tag ] = true;
mp-wp_genesis 407 }
mp-wp_genesis 408
mp-wp_genesis 409 reset( $wp_filter[ $tag ] );
mp-wp_genesis 410
mp-wp_genesis 411 do {
mp-wp_genesis 412 foreach( (array) current($wp_filter[$tag]) as $the_ )
mp-wp_genesis 413 if ( !is_null($the_['function']) )
mp-wp_genesis 414 call_user_func_array($the_['function'], array_slice($args, 0, (int) $the_['accepted_args']));
mp-wp_genesis 415
mp-wp_genesis 416 } while ( next($wp_filter[$tag]) !== false );
mp-wp_genesis 417
mp-wp_genesis 418 array_pop($wp_current_filter);
mp-wp_genesis 419 }
mp-wp_genesis 420
mp-wp_genesis 421 /**
mp-wp_genesis 422 * Check if any action has been registered for a hook.
mp-wp_genesis 423 *
mp-wp_genesis 424 * @package WordPress
mp-wp_genesis 425 * @subpackage Plugin
mp-wp_genesis 426 * @since 2.5
mp-wp_genesis 427 * @see has_filter() has_action() is an alias of has_filter().
mp-wp_genesis 428 *
mp-wp_genesis 429 * @param string $tag The name of the action hook.
mp-wp_genesis 430 * @param callback $function_to_check optional. If specified, return the priority of that function on this hook or false if not attached.
mp-wp_genesis 431 * @return int|boolean Optionally returns the priority on that hook for the specified function.
mp-wp_genesis 432 */
mp-wp_genesis 433 function has_action($tag, $function_to_check = false) {
mp-wp_genesis 434 return has_filter($tag, $function_to_check);
mp-wp_genesis 435 }
mp-wp_genesis 436
mp-wp_genesis 437 /**
mp-wp_genesis 438 * Removes a function from a specified action hook.
mp-wp_genesis 439 *
mp-wp_genesis 440 * This function removes a function attached to a specified action hook. This
mp-wp_genesis 441 * method can be used to remove default functions attached to a specific filter
mp-wp_genesis 442 * hook and possibly replace them with a substitute.
mp-wp_genesis 443 *
mp-wp_genesis 444 * @package WordPress
mp-wp_genesis 445 * @subpackage Plugin
mp-wp_genesis 446 * @since 1.2
mp-wp_genesis 447 *
mp-wp_genesis 448 * @param string $tag The action hook to which the function to be removed is hooked.
mp-wp_genesis 449 * @param callback $function_to_remove The name of the function which should be removed.
mp-wp_genesis 450 * @param int $priority optional The priority of the function (default: 10).
mp-wp_genesis 451 * @param int $accepted_args optional. The number of arguments the function accpets (default: 1).
mp-wp_genesis 452 * @return boolean Whether the function is removed.
mp-wp_genesis 453 */
mp-wp_genesis 454 function remove_action($tag, $function_to_remove, $priority = 10, $accepted_args = 1) {
mp-wp_genesis 455 return remove_filter($tag, $function_to_remove, $priority, $accepted_args);
mp-wp_genesis 456 }
mp-wp_genesis 457
mp-wp_genesis 458 /**
mp-wp_genesis 459 * Remove all of the hooks from an action.
mp-wp_genesis 460 *
mp-wp_genesis 461 * @since 2.7
mp-wp_genesis 462 *
mp-wp_genesis 463 * @param string $tag The action to remove hooks from.
mp-wp_genesis 464 * @param int $priority The priority number to remove them from.
mp-wp_genesis 465 * @return bool True when finished.
mp-wp_genesis 466 */
mp-wp_genesis 467 function remove_all_actions($tag, $priority = false) {
mp-wp_genesis 468 return remove_all_filters($tag, $priority);
mp-wp_genesis 469 }
mp-wp_genesis 470
mp-wp_genesis 471 //
mp-wp_genesis 472 // Functions for handling plugins.
mp-wp_genesis 473 //
mp-wp_genesis 474
mp-wp_genesis 475 /**
mp-wp_genesis 476 * Gets the basename of a plugin.
mp-wp_genesis 477 *
mp-wp_genesis 478 * This method extracts the name of a plugin from its filename.
mp-wp_genesis 479 *
mp-wp_genesis 480 * @package WordPress
mp-wp_genesis 481 * @subpackage Plugin
mp-wp_genesis 482 * @since 1.5
mp-wp_genesis 483 *
mp-wp_genesis 484 * @access private
mp-wp_genesis 485 *
mp-wp_genesis 486 * @param string $file The filename of plugin.
mp-wp_genesis 487 * @return string The name of a plugin.
mp-wp_genesis 488 * @uses WP_PLUGIN_DIR
mp-wp_genesis 489 */
mp-wp_genesis 490 function plugin_basename($file) {
mp-wp_genesis 491 $file = str_replace('\\','/',$file); // sanitize for Win32 installs
mp-wp_genesis 492 $file = preg_replace('|/+|','/', $file); // remove any duplicate slash
mp-wp_genesis 493 $plugin_dir = str_replace('\\','/',WP_PLUGIN_DIR); // sanitize for Win32 installs
mp-wp_genesis 494 $plugin_dir = preg_replace('|/+|','/', $plugin_dir); // remove any duplicate slash
mp-wp_genesis 495 $file = preg_replace('|^' . preg_quote($plugin_dir, '|') . '/|','',$file); // get relative path from plugins dir
mp-wp_genesis 496 return $file;
mp-wp_genesis 497 }
mp-wp_genesis 498
mp-wp_genesis 499 /**
mp-wp_genesis 500 * Set the activation hook for a plugin.
mp-wp_genesis 501 *
mp-wp_genesis 502 * When a plugin is activated, the action 'activate_PLUGINNAME' hook is
mp-wp_genesis 503 * activated. In the name of this hook, PLUGINNAME is replaced with the name of
mp-wp_genesis 504 * the plugin, including the optional subdirectory. For example, when the plugin
mp-wp_genesis 505 * is located in wp-content/plugin/sampleplugin/sample.php, then the name of
mp-wp_genesis 506 * this hook will become 'activate_sampleplugin/sample.php'. When the plugin
mp-wp_genesis 507 * consists of only one file and is (as by default) located at
mp-wp_genesis 508 * wp-content/plugin/sample.php the name of this hook will be
mp-wp_genesis 509 * 'activate_sample.php'.
mp-wp_genesis 510 *
mp-wp_genesis 511 * @package WordPress
mp-wp_genesis 512 * @subpackage Plugin
mp-wp_genesis 513 * @since 2.0
mp-wp_genesis 514 *
mp-wp_genesis 515 * @access private
mp-wp_genesis 516 *
mp-wp_genesis 517 * @param string $file The filename of the plugin including the path.
mp-wp_genesis 518 * @param callback $function the function hooked to the 'activate_PLUGIN' action.
mp-wp_genesis 519 */
mp-wp_genesis 520 function register_activation_hook($file, $function) {
mp-wp_genesis 521 $file = plugin_basename($file);
mp-wp_genesis 522 add_action('activate_' . $file, $function);
mp-wp_genesis 523 }
mp-wp_genesis 524
mp-wp_genesis 525 /**
mp-wp_genesis 526 * Set the deactivation hook for a plugin.
mp-wp_genesis 527 *
mp-wp_genesis 528 * When a plugin is deactivated, the action 'deactivate_PLUGINNAME' hook is
mp-wp_genesis 529 * deactivated. In the name of this hook, PLUGINNAME is replaced with the name
mp-wp_genesis 530 * of the plugin, including the optional subdirectory. For example, when the
mp-wp_genesis 531 * plugin is located in wp-content/plugin/sampleplugin/sample.php, then
mp-wp_genesis 532 * the name of this hook will become 'activate_sampleplugin/sample.php'.
mp-wp_genesis 533 *
mp-wp_genesis 534 * When the plugin consists of only one file and is (as by default) located at
mp-wp_genesis 535 * wp-content/plugin/sample.php the name of this hook will be
mp-wp_genesis 536 * 'activate_sample.php'.
mp-wp_genesis 537 *
mp-wp_genesis 538 * @package WordPress
mp-wp_genesis 539 * @subpackage Plugin
mp-wp_genesis 540 * @since 2.0
mp-wp_genesis 541 *
mp-wp_genesis 542 * @access private
mp-wp_genesis 543 *
mp-wp_genesis 544 * @param string $file The filename of the plugin including the path.
mp-wp_genesis 545 * @param callback $function the function hooked to the 'activate_PLUGIN' action.
mp-wp_genesis 546 */
mp-wp_genesis 547 function register_deactivation_hook($file, $function) {
mp-wp_genesis 548 $file = plugin_basename($file);
mp-wp_genesis 549 add_action('deactivate_' . $file, $function);
mp-wp_genesis 550 }
mp-wp_genesis 551
mp-wp_genesis 552 /**
mp-wp_genesis 553 * Set the uninstallation hook for a plugin.
mp-wp_genesis 554 *
mp-wp_genesis 555 * Registers the uninstall hook that will be called when the user clicks on the
mp-wp_genesis 556 * uninstall link that calls for the plugin to uninstall itself. The link won't
mp-wp_genesis 557 * be active unless the plugin hooks into the action.
mp-wp_genesis 558 *
mp-wp_genesis 559 * The plugin should not run arbitrary code outside of functions, when
mp-wp_genesis 560 * registering the uninstall hook. In order to run using the hook, the plugin
mp-wp_genesis 561 * will have to be included, which means that any code laying outside of a
mp-wp_genesis 562 * function will be run during the uninstall process. The plugin should not
mp-wp_genesis 563 * hinder the uninstall process.
mp-wp_genesis 564 *
mp-wp_genesis 565 * If the plugin can not be written without running code within the plugin, then
mp-wp_genesis 566 * the plugin should create a file named 'uninstall.php' in the base plugin
mp-wp_genesis 567 * folder. This file will be called, if it exists, during the uninstall process
mp-wp_genesis 568 * bypassing the uninstall hook. The plugin, when using the 'uninstall.php'
mp-wp_genesis 569 * should always check for the 'WP_UNINSTALL_PLUGIN' constant, before
mp-wp_genesis 570 * executing.
mp-wp_genesis 571 *
mp-wp_genesis 572 * @since 2.7
mp-wp_genesis 573 *
mp-wp_genesis 574 * @param string $file
mp-wp_genesis 575 * @param callback $callback The callback to run when the hook is called.
mp-wp_genesis 576 */
mp-wp_genesis 577 function register_uninstall_hook($file, $callback) {
mp-wp_genesis 578 // The option should not be autoloaded, because it is not needed in most
mp-wp_genesis 579 // cases. Emphasis should be put on using the 'uninstall.php' way of
mp-wp_genesis 580 // uninstalling the plugin.
mp-wp_genesis 581 $uninstallable_plugins = (array) get_option('uninstall_plugins');
mp-wp_genesis 582 $uninstallable_plugins[plugin_basename($file)] = $callback;
mp-wp_genesis 583 update_option('uninstall_plugins', $uninstallable_plugins);
mp-wp_genesis 584 }
mp-wp_genesis 585
mp-wp_genesis 586 /**
mp-wp_genesis 587 * Calls the 'all' hook, which will process the functions hooked into it.
mp-wp_genesis 588 *
mp-wp_genesis 589 * The 'all' hook passes all of the arguments or parameters that were used for
mp-wp_genesis 590 * the hook, which this function was called for.
mp-wp_genesis 591 *
mp-wp_genesis 592 * This function is used internally for apply_filters(), do_action(), and
mp-wp_genesis 593 * do_action_ref_array() and is not meant to be used from outside those
mp-wp_genesis 594 * functions. This function does not check for the existence of the all hook, so
mp-wp_genesis 595 * it will fail unless the all hook exists prior to this function call.
mp-wp_genesis 596 *
mp-wp_genesis 597 * @package WordPress
mp-wp_genesis 598 * @subpackage Plugin
mp-wp_genesis 599 * @since 2.5
mp-wp_genesis 600 * @access private
mp-wp_genesis 601 *
mp-wp_genesis 602 * @uses $wp_filter Used to process all of the functions in the 'all' hook
mp-wp_genesis 603 *
mp-wp_genesis 604 * @param array $args The collected parameters from the hook that was called.
mp-wp_genesis 605 * @param string $hook Optional. The hook name that was used to call the 'all' hook.
mp-wp_genesis 606 */
mp-wp_genesis 607 function _wp_call_all_hook($args) {
mp-wp_genesis 608 global $wp_filter;
mp-wp_genesis 609
mp-wp_genesis 610 reset( $wp_filter['all'] );
mp-wp_genesis 611 do {
mp-wp_genesis 612 foreach( (array) current($wp_filter['all']) as $the_ )
mp-wp_genesis 613 if ( !is_null($the_['function']) )
mp-wp_genesis 614 call_user_func_array($the_['function'], $args);
mp-wp_genesis 615
mp-wp_genesis 616 } while ( next($wp_filter['all']) !== false );
mp-wp_genesis 617 }
mp-wp_genesis 618
mp-wp_genesis 619 /**
mp-wp_genesis 620 * Build Unique ID for storage and retrieval.
mp-wp_genesis 621 *
mp-wp_genesis 622 * The old way to serialize the callback caused issues and this function is the
mp-wp_genesis 623 * solution. It works by checking for objects and creating an a new property in
mp-wp_genesis 624 * the class to keep track of the object and new objects of the same class that
mp-wp_genesis 625 * need to be added.
mp-wp_genesis 626 *
mp-wp_genesis 627 * It also allows for the removal of actions and filters for objects after they
mp-wp_genesis 628 * change class properties. It is possible to include the property $wp_filter_id
mp-wp_genesis 629 * in your class and set it to "null" or a number to bypass the workaround.
mp-wp_genesis 630 * However this will prevent you from adding new classes and any new classes
mp-wp_genesis 631 * will overwrite the previous hook by the same class.
mp-wp_genesis 632 *
mp-wp_genesis 633 * Functions and static method callbacks are just returned as strings and
mp-wp_genesis 634 * shouldn't have any speed penalty.
mp-wp_genesis 635 *
mp-wp_genesis 636 * @package WordPress
mp-wp_genesis 637 * @subpackage Plugin
mp-wp_genesis 638 * @access private
mp-wp_genesis 639 * @since 2.2.3
mp-wp_genesis 640 * @link http://trac.wordpress.org/ticket/3875
mp-wp_genesis 641 *
mp-wp_genesis 642 * @global array $wp_filter Storage for all of the filters and actions
mp-wp_genesis 643 * @param string $tag Used in counting how many hooks were applied
mp-wp_genesis 644 * @param string|array $function Used for creating unique id
mp-wp_genesis 645 * @param int|bool $priority Used in counting how many hooks were applied. If === false and $function is an object reference, we return the unique id only if it already has one, false otherwise.
mp-wp_genesis 646 * @param string $type filter or action
mp-wp_genesis 647 * @return string Unique ID for usage as array key
mp-wp_genesis 648 */
mp-wp_genesis 649 function _wp_filter_build_unique_id($tag, $function, $priority) {
mp-wp_genesis 650 global $wp_filter;
mp-wp_genesis 651
mp-wp_genesis 652 // If function then just skip all of the tests and not overwrite the following.
mp-wp_genesis 653 if ( is_string($function) )
mp-wp_genesis 654 return $function;
mp-wp_genesis 655 // Object Class Calling
mp-wp_genesis 656 else if (is_object($function[0]) ) {
mp-wp_genesis 657 $obj_idx = get_class($function[0]).$function[1];
mp-wp_genesis 658 if ( !isset($function[0]->wp_filter_id) ) {
mp-wp_genesis 659 if ( false === $priority )
mp-wp_genesis 660 return false;
mp-wp_genesis 661 $count = isset($wp_filter[$tag][$priority]) ? count((array)$wp_filter[$tag][$priority]) : 0;
mp-wp_genesis 662 $function[0]->wp_filter_id = $count;
mp-wp_genesis 663 $obj_idx .= $count;
mp-wp_genesis 664 unset($count);
mp-wp_genesis 665 } else
mp-wp_genesis 666 $obj_idx .= $function[0]->wp_filter_id;
mp-wp_genesis 667 return $obj_idx;
mp-wp_genesis 668 }
mp-wp_genesis 669 // Static Calling
mp-wp_genesis 670 else if ( is_string($function[0]) )
mp-wp_genesis 671 return $function[0].$function[1];
mp-wp_genesis 672 }
mp-wp_genesis 673
mp-wp_genesis 674 ?>