| 1 |
<?php |
| 2 |
namespace Averta\WordPress\Event; |
| 3 |
|
| 4 |
|
| 5 |
class Action implements HookInterface |
| 6 |
{ |
| 7 |
/** |
| 8 |
* Adds a callback function to an action hook. |
| 9 |
* |
| 10 |
* @param string $hook_name |
| 11 |
* @param callable $callback |
| 12 |
* @param int $priority |
| 13 |
* @param int $accepted_args |
| 14 |
* |
| 15 |
* @return mixed |
| 16 |
*/ |
| 17 |
public function add( $hook_name, $callback, $priority = 10, $accepted_args = 1 ){ |
| 18 |
return add_action( $hook_name, $callback, $priority, $accepted_args ); |
| 19 |
} |
| 20 |
|
| 21 |
/** |
| 22 |
* Removes a callback function from an action hook. |
| 23 |
* |
| 24 |
* @param string $hook_name |
| 25 |
* @param callable $callback |
| 26 |
* @param int $priority |
| 27 |
* |
| 28 |
* @return mixed |
| 29 |
*/ |
| 30 |
public function remove( $hook_name, $callback, $priority = 10 ){ |
| 31 |
return remove_action( $hook_name, $callback, $priority ); |
| 32 |
} |
| 33 |
|
| 34 |
/** |
| 35 |
* Checks if any action has been registered for a hook. |
| 36 |
* |
| 37 |
* @param string $hook_name |
| 38 |
* @param callable|bool $callback |
| 39 |
* |
| 40 |
* @return mixed |
| 41 |
*/ |
| 42 |
public function has( $hook_name, $callback = false ){ |
| 43 |
return has_action( $hook_name, $callback ); |
| 44 |
} |
| 45 |
|
| 46 |
/** |
| 47 |
* Retrieves the number of times an action has been fired during the current request. |
| 48 |
* |
| 49 |
* @param string $hook_name |
| 50 |
* |
| 51 |
* @return mixed |
| 52 |
*/ |
| 53 |
public function did( $hook_name ){ |
| 54 |
return did_action( $hook_name ); |
| 55 |
} |
| 56 |
|
| 57 |
/** |
| 58 |
* Calls the callback functions that have been added to an action hook. |
| 59 |
* |
| 60 |
* @param string $hook_name |
| 61 |
* @param mixed $arg |
| 62 |
* |
| 63 |
* @return mixed |
| 64 |
*/ |
| 65 |
public function do( $hook_name, ...$arg ){ |
| 66 |
return do_action( $hook_name, $arg ); |
| 67 |
} |
| 68 |
} |
| 69 |
|