/bp-forums/bbpress/bb-includes/backpress/functions.plugin-api.php

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