Keine Beschreibung

class-hook-manager.php 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. /**
  3. * This file was automatically generated by automattic/jetpack-autoloader.
  4. *
  5. * @package automattic/jetpack-autoloader
  6. */
  7. namespace Automattic\Jetpack\Autoloader\jpf11009ded9fc4592b6a05b61ce272b3c_jetpackⓥ10_2;
  8. // phpcs:ignore
  9. /**
  10. * Allows the latest autoloader to register hooks that can be removed when the autoloader is reset.
  11. */
  12. class Hook_Manager {
  13. /**
  14. * An array containing all of the hooks that we've registered.
  15. *
  16. * @var array
  17. */
  18. private $registered_hooks;
  19. /**
  20. * The constructor.
  21. */
  22. public function __construct() {
  23. $this->registered_hooks = array();
  24. }
  25. /**
  26. * Adds an action to WordPress and registers it internally.
  27. *
  28. * @param string $tag The name of the action which is hooked.
  29. * @param callable $callable The function to call.
  30. * @param int $priority Used to specify the priority of the action.
  31. * @param int $accepted_args Used to specify the number of arguments the callable accepts.
  32. */
  33. public function add_action( $tag, $callable, $priority = 10, $accepted_args = 1 ) {
  34. $this->registered_hooks[ $tag ][] = array(
  35. 'priority' => $priority,
  36. 'callable' => $callable,
  37. );
  38. add_action( $tag, $callable, $priority, $accepted_args );
  39. }
  40. /**
  41. * Adds a filter to WordPress and registers it internally.
  42. *
  43. * @param string $tag The name of the filter which is hooked.
  44. * @param callable $callable The function to call.
  45. * @param int $priority Used to specify the priority of the filter.
  46. * @param int $accepted_args Used to specify the number of arguments the callable accepts.
  47. */
  48. public function add_filter( $tag, $callable, $priority = 10, $accepted_args = 1 ) {
  49. $this->registered_hooks[ $tag ][] = array(
  50. 'priority' => $priority,
  51. 'callable' => $callable,
  52. );
  53. add_filter( $tag, $callable, $priority, $accepted_args );
  54. }
  55. /**
  56. * Removes all of the registered hooks.
  57. */
  58. public function reset() {
  59. foreach ( $this->registered_hooks as $tag => $hooks ) {
  60. foreach ( $hooks as $hook ) {
  61. remove_filter( $tag, $hook['callable'], $hook['priority'] );
  62. }
  63. }
  64. $this->registered_hooks = array();
  65. }
  66. }