PageRenderTime 52ms CodeModel.GetById 16ms app.highlight 25ms RepoModel.GetById 2ms app.codeStats 0ms

/inc/backpress/functions.plugin-api.php

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