[ Index ]

PHP Cross Reference of WordPress

title

Body

[close]

/wp-includes/ -> plugin.php (source)

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


Generated: Sat Feb 4 03:55:55 2012 Hosted by follow the white rabbit.