PluginProbe ʕ •ᴥ•ʔ
Paid Membership Plugin, Ecommerce, User Registration Form, Login Form, User Profile & Restrict Content – ProfilePress / 3.0
Paid Membership Plugin, Ecommerce, User Registration Form, Login Form, User Profile & Restrict Content – ProfilePress v3.0
4.16.18 4.16.17 4.16.16 trunk 1.0 1.0.1 1.0.2 1.1 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.5a 1.1.6 1.1.7 1.2 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.3 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.4 1.4.1 1.4.2 1.5 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.6 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.7 1.6.8 1.7 1.7.1 1.7.2 1.8 1.8.1 1.8.10 1.8.2 1.8.3 1.8.4 1.8.5 1.8.6 1.8.7 1.8.8 1.8.9 1.9 1.9.1 1.9.10 1.9.11 1.9.12 1.9.13 1.9.2 1.9.3 1.9.4 1.9.5 1.9.6 1.9.7 1.9.8 1.9.9 2.1.9 2.2.10 2.2.11 2.2.12 2.2.13 2.2.14 2.2.15 2.2.16 2.2.2 2.2.5 2.2.6 2.2.7 2.2.8 2.2.9 3.0 3.1 3.1.1 3.1.10 3.1.11 3.1.12 3.1.13 3.1.14 3.1.15 3.1.16 3.1.17 3.1.18 3.1.19 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 3.2.0 3.2.1 3.2.10 3.2.11 3.2.12 3.2.13 3.2.14 3.2.15 3.2.16 3.2.2 3.2.3 3.2.4 3.2.5 3.2.6 3.2.7 3.2.8 3.2.9 4.0.0 4.0.1 4.0.2 4.0.3 4.1.0 4.1.1 4.1.2 4.1.3 4.1.4 4.10.0 4.10.1 4.10.2 4.10.3 4.11.0 4.12.0 4.13.0 4.13.1 4.13.2 4.13.3 4.13.4 4.14.0 4.14.1 4.14.2 4.14.3 4.14.4 4.15.0 4.15.1 4.15.10 4.15.11 4.15.12 4.15.13 4.15.14 4.15.15 4.15.16 4.15.17 4.15.18 4.15.19 4.15.2 4.15.20 4.15.20.1 4.15.21 4.15.22 4.15.23 4.15.24 4.15.25 4.15.3 4.15.4 4.15.5 4.15.6 4.15.7 4.15.8 4.15.9 4.16.0 4.16.1 4.16.10 4.16.11 4.16.12 4.16.13 4.16.14 4.16.15 4.16.2 4.16.3 4.16.4 4.16.5 4.16.6 4.16.7 4.16.8 4.16.9 4.2.0 4.3.0 4.3.1 4.3.2 4.4.0 4.4.1 4.5.0 4.5.1 4.5.2 4.5.3 4.5.4 4.5.5 4.6.0 4.7.0 4.8.0 4.9.0
wp-user-avatar / src / ContentProtection / ConditionCallbacks.php
wp-user-avatar / src / ContentProtection Last commit date
Frontend 5 years ago views 5 years ago ConditionCallbacks.php 5 years ago ContentConditions.php 5 years ago Init.php 5 years ago SettingsPage.php 5 years ago WPListTable.php 5 years ago index.php 5 years ago
ConditionCallbacks.php
318 lines
1 <?php
2
3 namespace ProfilePress\Core\ContentProtection;
4
5
6 class ConditionCallbacks
7 {
8 /**
9 * Checks if this is one of the selected post_type items.
10 *
11 * @param string $condition_id
12 * @param mixed $rule_saved_value
13 * @param bool $is_redirect
14 *
15 * @return bool
16 */
17 public static function post_type($condition_id, $rule_saved_value, $is_redirect = false)
18 {
19 global $post;
20
21 $target = explode('_', $condition_id);
22
23 // Modifier should be the last key.
24 $modifier = array_pop($target);
25
26 // Post type is the remaining keys combined.
27 $post_type = implode('_', $target);
28
29 $selected = ! empty($rule_saved_value) ? $rule_saved_value : [];
30
31 switch ($modifier) {
32 case 'index':
33
34 if (is_post_type_archive($post_type)) return true;
35 break;
36
37 case 'all':
38
39 if (self::_is_post_type($post_type)) {
40
41 // do not redirect home and blog page. if there is a need, add the homepage and blog page OR rule.
42 if (true === $is_redirect && ( ! is_singular($post_type) || is_front_page() || is_home())) return false;
43
44 return true;
45 }
46 break;
47
48 case 'selected':
49
50 if (self::_is_post_type($post_type) && in_array($post->ID, wp_parse_id_list($selected))) {
51
52 if (true === $is_redirect && ! is_singular($post_type)) return false;
53
54 return true;
55 }
56 break;
57
58 case 'children':
59
60 if ( ! is_post_type_hierarchical($post_type) || ! self::_is_post_type($post_type)) return false;
61
62 $selected = wp_parse_id_list($selected);
63
64 foreach ($selected as $id) {
65
66 if ($post->post_parent == $id) {
67
68 if (true === $is_redirect && ! is_singular($post_type)) return false;
69
70 return true;
71 }
72 }
73 break;
74
75 case 'ancestors':
76
77 if ( ! is_post_type_hierarchical($post_type) || ! self::_is_post_type($post_type)) return false;
78
79 $selected = wp_parse_id_list($selected);
80
81 foreach ($selected as $id) {
82
83 $ancestors = get_post_ancestors($id);
84
85 if (in_array($post->ID, $ancestors)) {
86
87 if (true === $is_redirect && ! is_singular($post_type)) return false;
88
89 return true;
90 }
91 }
92 break;
93
94 case 'template':
95
96 if (is_page() && is_page_template($selected)) return true;
97 break;
98 }
99
100 return false;
101 }
102
103 /**
104 * Checks if this is one of the selected taxonomy term.
105 *
106 * @param string $condition_id
107 * @param mixed $rule_saved_value
108 *
109 * @return bool
110 */
111 public static function taxonomy($condition_id, $rule_saved_value)
112 {
113 $target = explode('_', $condition_id);
114
115 // Remove the tax_ prefix.
116 array_shift($target);
117
118 // Assign the last key as the modifier _all, _selected
119 $modifier = array_pop($target);
120
121 // Whatever is left is the taxonomy.
122 $taxonomy = implode('_', $target);
123
124 if ($taxonomy == 'category') {
125 return self::_category($condition_id, $rule_saved_value);
126 }
127
128 if ($taxonomy == 'post_tag') {
129 return self::_post_tag($condition_id, $rule_saved_value);
130 }
131
132 switch ($modifier) {
133 case 'all':
134 if (is_tax($taxonomy)) {
135 return true;
136 }
137 break;
138
139 case 'selected':
140 $selected = ! empty($rule_saved_value) ? $rule_saved_value : [];
141
142 if (is_tax($taxonomy, wp_parse_id_list($selected))) {
143 return true;
144 }
145 break;
146 }
147
148 return false;
149 }
150
151 /**
152 * Checks if the post_type has the selected categories.
153 *
154 * @param string $condition_id
155 * @param mixed $rule_saved_value
156 * @param bool $is_redirect
157 *
158 * @return bool
159 */
160 public static function post_type_tax($condition_id, $rule_saved_value, $is_redirect = false)
161 {
162 $target = explode('_w_', $condition_id);
163
164 // First key is the post type.
165 $post_type = array_shift($target);
166
167 // Last Key is the taxonomy
168 $taxonomy = array_pop($target);
169
170 if ($taxonomy == 'category') {
171
172 if (true === $is_redirect && ! is_singular($post_type)) return false;
173
174 return self::_post_type_category($condition_id, $rule_saved_value);
175 }
176
177 if ($taxonomy == 'post_tag') {
178
179 if (true === $is_redirect && ! is_singular($post_type)) return false;
180
181 return self::_post_type_tag($condition_id, $rule_saved_value);
182 }
183
184 $selected = ! empty($rule_saved_value) ? $rule_saved_value : [];
185
186 if (self::_is_post_type($post_type) && has_term(wp_parse_id_list($selected), $taxonomy)) {
187
188 if (true === $is_redirect && ! is_singular($post_type)) return false;
189
190 return true;
191 }
192
193 return false;
194 }
195
196
197 /**
198 * Checks if this is one of the selected categories.
199 *
200 * @param string $condition_id
201 * @param mixed $rule_saved_value
202 *
203 * @return bool
204 */
205 public static function _category($condition_id, $rule_saved_value)
206 {
207 $target = explode('_', $condition_id);
208
209 // Assign the last key as the modifier _all, _selected
210 $modifier = array_pop($target);
211
212 switch ($modifier) {
213 case 'all':
214 if (is_category()) return true;
215 break;
216
217 case 'selected':
218 $selected = ! empty($rule_saved_value) ? $rule_saved_value : [];
219 if (is_category(wp_parse_id_list($selected))) {
220 return true;
221 }
222 break;
223 }
224
225 return false;
226 }
227
228 /**
229 * Checks if this is one of the selected tags.
230 *
231 * @param string $condition_id
232 * @param mixed $rule_saved_value
233 *
234 * @return bool
235 */
236 public static function _post_tag($condition_id, $rule_saved_value)
237 {
238 $target = explode('_', $condition_id);
239
240 $modifier = array_pop($target);
241
242 switch ($modifier) {
243 case 'all':
244 if (is_tag()) {
245 return true;
246 }
247 break;
248
249 case 'selected':
250 $selected = ! empty($rule_saved_value) ? $rule_saved_value : [];
251 if (is_tag(wp_parse_id_list($selected))) {
252 return true;
253 }
254 break;
255 }
256
257 return false;
258 }
259
260 /**
261 * Checks if the post_type has the selected categories.
262 *
263 * @param string $condition_id
264 * @param mixed $rule_saved_value
265 *
266 * @return bool
267 */
268 public static function _post_type_category($condition_id, $rule_saved_value)
269 {
270 $target = explode('_w_', $condition_id);
271
272 // First key is the post type.
273 $post_type = array_shift($target);
274
275 $selected = ! empty($rule_saved_value) ? $rule_saved_value : [];
276
277 if (self::_is_post_type($post_type) && has_category(wp_parse_id_list($selected))) {
278 return true;
279 }
280
281 return false;
282 }
283
284 /**
285 * Checks is a post_type has the selected tags.
286 *
287 * @param string $condition_id
288 * @param mixed $rule_saved_value
289 *
290 * @return bool
291 */
292 public static function _post_type_tag($condition_id, $rule_saved_value)
293 {
294 $target = explode('_w_', $condition_id);
295
296 // First key is the post type.
297 $post_type = array_shift($target);
298
299 $selected = ! empty($rule_saved_value) ? $rule_saved_value : [];
300 if (self::_is_post_type($post_type) && has_tag(wp_parse_id_list($selected))) {
301 return true;
302 }
303
304 return false;
305 }
306
307 /**
308 * @param string $post_type
309 *
310 * @return bool
311 */
312 public static function _is_post_type($post_type)
313 {
314 global $post;
315
316 return is_object($post) && $post->post_type == $post_type;
317 }
318 }