1 <?php
2
3 4 5 6 7 8
9
10 namespace nk2580\wordsmith\Endpoints;
11
12 class Endpoint {
13
14 public $vars = [];
15 public $endpoints = [];
16 public $callback;
17 public $position = 'top';
18
19 20 21 22
23 public function __construct() {
24 add_filter('query_vars', array($this, 'add_query_vars'), 0);
25 add_action('parse_request', array($this, $this->callback), 0);
26 add_action('init', array($this, 'add_endpoints'), 0);
27 }
28
29 30 31 32 33
34 public function add_query_vars($vars) {
35 $allVars = array_merge($vars, $this->vars);
36 return $allVars;
37 }
38
39 40 41 42 43
44 public function add_endpoints() {
45 foreach ($this->endpoints as $regex => $query) {
46 add_rewrite_rule( $regex, $query ,$this->position);
47 }
48 }
49
50 }
51