| 1 |
<?php |
| 2 |
/** |
| 3 |
* Trait HookTrait. |
| 4 |
* |
| 5 |
* @package Packetery |
| 6 |
*/ |
| 7 |
|
| 8 |
declare( strict_types=1 ); |
| 9 |
|
| 10 |
namespace Packetery\Module\Framework; |
| 11 |
|
| 12 |
/** |
| 13 |
* Trait HookTrait. |
| 14 |
* |
| 15 |
* @package Packetery |
| 16 |
*/ |
| 17 |
trait HookTrait { |
| 18 |
public function addAction( string $hookName, callable $callback, int $priority = 10, int $acceptedArgs = 1 ): ?bool { |
| 19 |
return add_action( $hookName, $callback, $priority, $acceptedArgs ); |
| 20 |
} |
| 21 |
|
| 22 |
public function addFilter( string $hookName, callable $callback, int $priority = 10, int $acceptedArgs = 1 ): void { |
| 23 |
add_filter( $hookName, $callback, $priority, $acceptedArgs ); |
| 24 |
} |
| 25 |
|
| 26 |
/** |
| 27 |
* Applies filters. |
| 28 |
* |
| 29 |
* @param string $hookName Hook name. |
| 30 |
* @param mixed $value Value. |
| 31 |
* @param mixed ...$args Arguments. |
| 32 |
* |
| 33 |
* @return mixed |
| 34 |
*/ |
| 35 |
public function applyFilters( string $hookName, $value, ...$args ) { |
| 36 |
/** |
| 37 |
* Bridged function call. |
| 38 |
* |
| 39 |
* @since 1.7.7 |
| 40 |
*/ |
| 41 |
return apply_filters( $hookName, $value, ...$args ); |
| 42 |
} |
| 43 |
|
| 44 |
/** |
| 45 |
* Tells if action was performed. |
| 46 |
* |
| 47 |
* @param string $hookName Name of hook. |
| 48 |
* |
| 49 |
* @return int |
| 50 |
*/ |
| 51 |
public function didAction( string $hookName ): int { |
| 52 |
return did_action( $hookName ); |
| 53 |
} |
| 54 |
|
| 55 |
public function registerDeactivationHook( string $file, callable $callback ): void { |
| 56 |
register_deactivation_hook( $file, $callback ); |
| 57 |
} |
| 58 |
|
| 59 |
public function registerActivationHook( string $file, callable $callback ): void { |
| 60 |
register_activation_hook( $file, $callback ); |
| 61 |
} |
| 62 |
} |
| 63 |
|