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