1 <?php
2
3 4 5 6 7 8
9
10 namespace nk2580\wordsmith\Actions;
11
12 class AJAXAction {
13
14 protected $nopriv = true;
15 protected $action;
16 protected $callback;
17
18 public function __construct() {
19 $this->callAction('wp_ajax_' . $this->action, $this->callback, $this->priority, $this->accepted_args);
20 if ($this->nopriv) {
21 $this->callAction('wp_ajax_norpiv_' . $this->action, $this->callback, $this->priority, $this->accepted_args);
22 }
23 }
24
25 private function callAction($hook, $callback, $priority = null, $args = null) {
26 add_action($hook, array($this, $callback), $priority, $args);
27 }
28
29 }
30