| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Register all actions and filters for the plugin. |
| 5 |
*/ |
| 6 |
class Send_Users_Email_Loader { |
| 7 |
|
| 8 |
protected $actions; |
| 9 |
|
| 10 |
protected $filters; |
| 11 |
|
| 12 |
/** |
| 13 |
* Initialize the collections used to maintain the actions and filters. |
| 14 |
*/ |
| 15 |
public function __construct() { |
| 16 |
|
| 17 |
$this->actions = array(); |
| 18 |
$this->filters = array(); |
| 19 |
|
| 20 |
} |
| 21 |
|
| 22 |
/** |
| 23 |
* Add a new action to the collection to be registered with WordPress. |
| 24 |
*/ |
| 25 |
public function add_action( $hook, $component, $callback, $priority = 10, $accepted_args = 1 ) { |
| 26 |
$this->actions = $this->add( $this->actions, $hook, $component, $callback, $priority, $accepted_args ); |
| 27 |
} |
| 28 |
|
| 29 |
/** |
| 30 |
* Add a new filter to the collection to be registered with WordPress. |
| 31 |
*/ |
| 32 |
public function add_filter( $hook, $component, $callback, $priority = 10, $accepted_args = 1 ) { |
| 33 |
$this->filters = $this->add( $this->filters, $hook, $component, $callback, $priority, $accepted_args ); |
| 34 |
} |
| 35 |
|
| 36 |
/** |
| 37 |
* A utility function that is used to register the actions and hooks into a single collection. |
| 38 |
*/ |
| 39 |
private function add( $hooks, $hook, $component, $callback, $priority, $accepted_args ) { |
| 40 |
|
| 41 |
$hooks[] = array( |
| 42 |
'hook' => $hook, |
| 43 |
'component' => $component, |
| 44 |
'callback' => $callback, |
| 45 |
'priority' => $priority, |
| 46 |
'accepted_args' => $accepted_args |
| 47 |
); |
| 48 |
|
| 49 |
return $hooks; |
| 50 |
|
| 51 |
} |
| 52 |
|
| 53 |
/** |
| 54 |
* Register the filters and actions with WordPress. |
| 55 |
*/ |
| 56 |
public function run() { |
| 57 |
|
| 58 |
foreach ( $this->filters as $hook ) { |
| 59 |
add_filter( $hook['hook'], array( |
| 60 |
$hook['component'], |
| 61 |
$hook['callback'] |
| 62 |
), $hook['priority'], $hook['accepted_args'] ); |
| 63 |
} |
| 64 |
|
| 65 |
foreach ( $this->actions as $hook ) { |
| 66 |
add_action( $hook['hook'], array( |
| 67 |
$hook['component'], |
| 68 |
$hook['callback'] |
| 69 |
), $hook['priority'], $hook['accepted_args'] ); |
| 70 |
} |
| 71 |
|
| 72 |
} |
| 73 |
|
| 74 |
} |
| 75 |
|