/wp-includes/Requests/Hooks.php

  1. <?php 
  2. /** 
  3. * Handles adding and dispatching events 
  4. * 
  5. * @package Requests 
  6. * @subpackage Utilities 
  7. */ 
  8.  
  9. /** 
  10. * Handles adding and dispatching events 
  11. * 
  12. * @package Requests 
  13. * @subpackage Utilities 
  14. */ 
  15. class Requests_Hooks implements Requests_Hooker { 
  16. /** 
  17. * Registered callbacks for each hook 
  18. * 
  19. * @var array 
  20. */ 
  21. protected $hooks = array(); 
  22.  
  23. /** 
  24. * Constructor 
  25. */ 
  26. public function __construct() { 
  27. // pass 
  28.  
  29. /** 
  30. * Register a callback for a hook 
  31. * 
  32. * @param string $hook Hook name 
  33. * @param callback $callback Function/method to call on event 
  34. * @param int $priority Priority number. <0 is executed earlier, >0 is executed later 
  35. */ 
  36. public function register($hook, $callback, $priority = 0) { 
  37. if (!isset($this->hooks[$hook])) { 
  38. $this->hooks[$hook] = array(); 
  39. if (!isset($this->hooks[$hook][$priority])) { 
  40. $this->hooks[$hook][$priority] = array(); 
  41.  
  42. $this->hooks[$hook][$priority][] = $callback; 
  43.  
  44. /** 
  45. * Dispatch a message 
  46. * 
  47. * @param string $hook Hook name 
  48. * @param array $parameters Parameters to pass to callbacks 
  49. * @return boolean Successfulness 
  50. */ 
  51. public function dispatch($hook, $parameters = array()) { 
  52. if (empty($this->hooks[$hook])) { 
  53. return false; 
  54.  
  55. foreach ($this->hooks[$hook] as $priority => $hooked) { 
  56. foreach ($hooked as $callback) { 
  57. call_user_func_array($callback, $parameters); 
  58.  
  59. return true; 
.