refactor: add type decs
This commit is contained in:
parent
c0dd0d0623
commit
e8e41c6c9d
7 changed files with 106 additions and 91 deletions
|
@ -24,20 +24,20 @@ class Loader {
|
|||
/**
|
||||
* The array of actions registered with WordPress.
|
||||
*
|
||||
* @access protected
|
||||
* @var array $actions The actions registered with WordPress to fire when the plugin loads.
|
||||
*
|
||||
* @since 2.8.0
|
||||
* @see Loader::add() For more information on the hook array format.
|
||||
*
|
||||
* @var (string|int|object)[][] $actions The actions registered with WordPress to fire when the plugin loads.
|
||||
*/
|
||||
protected $actions;
|
||||
|
||||
/**
|
||||
* The array of filters registered with WordPress.
|
||||
*
|
||||
* @access protected
|
||||
* @var array $filters The filters registered with WordPress to fire when the plugin loads.
|
||||
*
|
||||
* @since 2.8.0
|
||||
* @see Loader::add() For more information on the hook array format.
|
||||
*
|
||||
* @var (string|int|object)[][] $filters The filters registered with WordPress to fire when the plugin loads.
|
||||
*/
|
||||
protected $filters;
|
||||
|
||||
|
@ -45,6 +45,8 @@ class Loader {
|
|||
* Initialize the collections used to maintain the actions and filters.
|
||||
*
|
||||
* @since 2.8.0
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct() {
|
||||
|
||||
|
@ -56,13 +58,15 @@ class Loader {
|
|||
/**
|
||||
* Add a new action to the collection to be registered with WordPress.
|
||||
*
|
||||
* @since 2.8.0
|
||||
* @see Loader::add() For more information on the hook array format.
|
||||
*
|
||||
* @param string $hook The name of the WordPress action that is being registered.
|
||||
* @param object $component A reference to the instance of the object on which the action is defined.
|
||||
* @param string $callback The name of the function definition on the `$component`.
|
||||
* @param int $priority (optional) The priority at which the function should be fired. Default is 10.
|
||||
* @param int $accepted_args (optional) The number of arguments that should be passed to the $callback. Default is 1.
|
||||
*
|
||||
* @since 2.8.0
|
||||
* @param int $priority Optional. The priority at which the function should be fired. Default is 10.
|
||||
* @param int $accepted_args Optional. The number of arguments that should be passed to the $callback. Default is 1.
|
||||
* @return void
|
||||
*/
|
||||
public function add_action( $hook, $component, $callback, $priority = 10, $accepted_args = 1 ) {
|
||||
$this->actions = $this->add( $this->actions, $hook, $component, $callback, $priority, $accepted_args );
|
||||
|
@ -71,13 +75,15 @@ class Loader {
|
|||
/**
|
||||
* Add a new filter to the collection to be registered with WordPress.
|
||||
*
|
||||
* @since 2.8.0
|
||||
* @see Loader::add() For more information on the hook array format.
|
||||
*
|
||||
* @param string $hook The name of the WordPress filter that is being registered.
|
||||
* @param object $component A reference to the instance of the object on which the filter is defined.
|
||||
* @param string $callback The name of the function definition on the `$component`.
|
||||
* @param int $priority (optional) The priority at which the function should be fired. Default is 10.
|
||||
* @param int $accepted_args (optional) The number of arguments that should be passed to the $callback. Default is 1.
|
||||
*
|
||||
* @since 2.8.0
|
||||
* @param int $priority Optional. The priority at which the function should be fired. Default is 10.
|
||||
* @param int $accepted_args Optional. The number of arguments that should be passed to the $callback. Default is 1.
|
||||
* @return void
|
||||
*/
|
||||
public function add_filter( $hook, $component, $callback, $priority = 10, $accepted_args = 1 ) {
|
||||
$this->filters = $this->add( $this->filters, $hook, $component, $callback, $priority, $accepted_args );
|
||||
|
@ -87,16 +93,23 @@ class Loader {
|
|||
* A utility function that is used to register the actions and hooks into a single
|
||||
* collection.
|
||||
*
|
||||
* @access private
|
||||
* @param array $hooks The collection of hooks that is being registered (that is, actions or filters).
|
||||
* @param string $hook The name of the WordPress filter that is being registered.
|
||||
* @param object $component A reference to the instance of the object on which the filter is defined.
|
||||
* @param string $callback The name of the function definition on the `$component`.
|
||||
* @param int $priority The priority at which the function should be fired.
|
||||
* @param int $accepted_args The number of arguments that should be passed to the `$callback`.
|
||||
* @return array The collection of actions and filters registered with WordPress.
|
||||
*
|
||||
* @since 2.8.0
|
||||
*
|
||||
* @param (string|int|object)[][] $hooks The collection of hooks that is being registered (that is, actions or filters).
|
||||
* @param string $hook The name of the WordPress filter that is being registered.
|
||||
* @param object $component A reference to the instance of the object on which the filter is defined.
|
||||
* @param string $callback The name of the function definition on the `$component`.
|
||||
* @param int $priority The priority at which the function should be fired.
|
||||
* @param int $accepted_args The number of arguments that should be passed to the `$callback`.
|
||||
* @return (string|int|object)[][] {
|
||||
* The registered hook(s).
|
||||
*
|
||||
* @type string $hook The name of the registered WordPress hook.
|
||||
* @type object $component A reference to the instance of the object on which the hook is defined.
|
||||
* @type string $callback The name of the function definition on the `$component`.
|
||||
* @type int $priority The priority at which the function should be fired.
|
||||
* @type int $accepted_args The number of arguments that should be passed to the `$callback`.
|
||||
* }
|
||||
*/
|
||||
private function add( $hooks, $hook, $component, $callback, $priority, $accepted_args ) {
|
||||
|
||||
|
@ -116,6 +129,9 @@ class Loader {
|
|||
* Registers the filters and actions with WordPress.
|
||||
*
|
||||
* @since 2.8.0
|
||||
* @see Loader::add() For more information on the hook array format.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function run() {
|
||||
|
||||
|
|
Reference in a new issue