forked from gocodebox/lifterlms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclass.llms.query.php
123 lines (91 loc) · 2.11 KB
/
class.llms.query.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<?php
if ( ! defined( 'ABSPATH' ) ) exit;
/**
* Query base class.
*
* Handles queries and endpoints
*/
class LLMS_Query {
/**
* Query var
* @access public
* @var array
*/
public $query_vars = array();
/**
* Constructor for the query class. Hooks in methods.
*
* @access public
*/
public function __construct() {
if ( ! is_admin() ) {
add_filter( 'query_vars', array( $this, 'set_query_vars'), 0 );
add_action( 'parse_request', array( $this, 'parse_request'), 0 );
}
$this->init_query_vars();
}
/**
* Init queries
*
* @return void
*/
public function init_query_vars() {
$this->query_vars = array(
'confirm-payment' => get_option( 'lifterlms_myaccount_confirm_payment_endpoint', 'confirm-payment' ),
'edit-account' => get_option( 'lifterlms_myaccount_edit_account_endpoint', 'edit-account' ),
'lost-password' => get_option( 'lifterlms_myaccount_lost_password_endpoint', 'lost-password' ),
'person-logout' => get_option( 'lifterlms_logout_endpoint', 'person-logout' ),
);
}
/**
* Get query variables
*
* @return void
*/
public function get_query_vars() {
return $this->query_vars;
}
/**
* Set query variables
*
* @return void
*/
public function set_query_vars( $vars ) {
foreach ( $this->query_vars as $key => $var )
$vars[] = $key;
return $vars;
}
/**
* Parse the request for query variables
*
* @return void
*/
public function parse_request() {
global $wp;
foreach ( $this->query_vars as $key => $var ) {
if ( isset( $_GET[ $var ] ) ) {
$wp->query_vars[ $key ] = $_GET[ $var ];
}
elseif ( isset( $wp->query_vars[ $var ] ) ) {
$wp->query_vars[ $key ] = $wp->query_vars[ $var ];
}
}
}
/**
* Add query variables
* @param $vars [array of WP query variables available for query]
*/
public function add_query_vars( $vars ) {
foreach ( $this->query_vars as $key => $var )
$vars[] = $key;
return $vars;
}
/**
* Add Query Endpoints
*/
public function add_endpoints() {
foreach ( $this->query_vars as $key => $var )
add_rewrite_endpoint( $var, EP_PAGES );
}
}
return new LLMS_Query();