PluginProbe ʕ •ᴥ•ʔ
Paid Membership Plugin, Ecommerce, User Registration Form, Login Form, User Profile & Restrict Content – ProfilePress / trunk
Paid Membership Plugin, Ecommerce, User Registration Form, Login Form, User Profile & Restrict Content – ProfilePress vtrunk
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 3 months ago views 1 year ago CapabilityCheck.php 3 years ago ConditionCallbacks.php 3 years ago ConditionalBlocksIntegration.php 3 years ago ContentConditions.php 6 months ago ElementorDisplayCondition.php 1 month ago ElementorRestriction.php 3 years ago Init.php 1 month ago NavMenuProtection.php 3 years ago SettingsPage.php 1 year ago WPListTable.php 1 year ago index.php 5 years ago
ConditionCallbacks.php
320 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 $post_id = isset($post->ID) && absint($post->ID) > 0 ? $post->ID : get_queried_object_id();
22
23 $target = explode('_', $condition_id);
24
25 // Modifier should be the last key.
26 $modifier = array_pop($target);
27
28 // Post type is the remaining keys combined.
29 $post_type = implode('_', $target);
30
31 $selected = ! empty($rule_saved_value) ? $rule_saved_value : [];
32
33 switch ($modifier) {
34 case 'index':
35
36 if (is_post_type_archive($post_type)) return true;
37 break;
38
39 case 'all':
40
41 if (self::_is_post_type($post_type)) {
42
43 // do not redirect home and blog page. if there is a need, add the homepage and blog page OR rule.
44 if (true === $is_redirect && ( ! is_singular($post_type) || is_front_page() || is_home())) return false;
45
46 return true;
47 }
48 break;
49
50 case 'selected':
51
52 if (self::_is_post_type($post_type) && in_array($post_id, wp_parse_id_list($selected))) {
53
54 if (true === $is_redirect && ! is_singular($post_type)) return false;
55
56 return true;
57 }
58 break;
59
60 case 'children':
61
62 if ( ! is_post_type_hierarchical($post_type) || ! self::_is_post_type($post_type)) return false;
63
64 $selected = wp_parse_id_list($selected);
65
66 foreach ($selected as $id) {
67
68 if ($post->post_parent == $id) {
69
70 if (true === $is_redirect && ! is_singular($post_type)) return false;
71
72 return true;
73 }
74 }
75 break;
76
77 case 'ancestors':
78
79 if ( ! is_post_type_hierarchical($post_type) || ! self::_is_post_type($post_type)) return false;
80
81 $selected = wp_parse_id_list($selected);
82
83 foreach ($selected as $id) {
84
85 $ancestors = get_post_ancestors($id);
86
87 if (in_array($post_id, $ancestors)) {
88
89 if (true === $is_redirect && ! is_singular($post_type)) return false;
90
91 return true;
92 }
93 }
94 break;
95
96 case 'template':
97
98 if (is_page() && is_page_template($selected)) return true;
99 break;
100 }
101
102 return false;
103 }
104
105 /**
106 * Checks if this is one of the selected taxonomy term.
107 *
108 * @param string $condition_id
109 * @param mixed $rule_saved_value
110 *
111 * @return bool
112 */
113 public static function taxonomy($condition_id, $rule_saved_value)
114 {
115 $target = explode('_', $condition_id);
116
117 // Remove the tax_ prefix.
118 array_shift($target);
119
120 // Assign the last key as the modifier _all, _selected
121 $modifier = array_pop($target);
122
123 // Whatever is left is the taxonomy.
124 $taxonomy = implode('_', $target);
125
126 if ($taxonomy == 'category') {
127 return self::_category($condition_id, $rule_saved_value);
128 }
129
130 if ($taxonomy == 'post_tag') {
131 return self::_post_tag($condition_id, $rule_saved_value);
132 }
133
134 switch ($modifier) {
135 case 'all':
136 if (is_tax($taxonomy)) {
137 return true;
138 }
139 break;
140
141 case 'selected':
142 $selected = ! empty($rule_saved_value) ? $rule_saved_value : [];
143
144 if (is_tax($taxonomy, wp_parse_id_list($selected))) {
145 return true;
146 }
147 break;
148 }
149
150 return false;
151 }
152
153 /**
154 * Checks if the post_type has the selected categories.
155 *
156 * @param string $condition_id
157 * @param mixed $rule_saved_value
158 * @param bool $is_redirect
159 *
160 * @return bool
161 */
162 public static function post_type_tax($condition_id, $rule_saved_value, $is_redirect = false)
163 {
164 $target = explode('_w_', $condition_id);
165
166 // First key is the post type.
167 $post_type = array_shift($target);
168
169 // Last Key is the taxonomy
170 $taxonomy = array_pop($target);
171
172 if ($taxonomy == 'category') {
173
174 if (true === $is_redirect && ! is_singular($post_type)) return false;
175
176 return self::_post_type_category($condition_id, $rule_saved_value);
177 }
178
179 if ($taxonomy == 'post_tag') {
180
181 if (true === $is_redirect && ! is_singular($post_type)) return false;
182
183 return self::_post_type_tag($condition_id, $rule_saved_value);
184 }
185
186 $selected = ! empty($rule_saved_value) ? $rule_saved_value : [];
187
188 if (self::_is_post_type($post_type) && has_term(wp_parse_id_list($selected), $taxonomy)) {
189
190 if (true === $is_redirect && ! is_singular($post_type)) return false;
191
192 return true;
193 }
194
195 return false;
196 }
197
198
199 /**
200 * Checks if this is one of the selected categories.
201 *
202 * @param string $condition_id
203 * @param mixed $rule_saved_value
204 *
205 * @return bool
206 */
207 public static function _category($condition_id, $rule_saved_value)
208 {
209 $target = explode('_', $condition_id);
210
211 // Assign the last key as the modifier _all, _selected
212 $modifier = array_pop($target);
213
214 switch ($modifier) {
215 case 'all':
216 if (is_category()) return true;
217 break;
218
219 case 'selected':
220 $selected = ! empty($rule_saved_value) ? $rule_saved_value : [];
221 if (is_category(wp_parse_id_list($selected))) {
222 return true;
223 }
224 break;
225 }
226
227 return false;
228 }
229
230 /**
231 * Checks if this is one of the selected tags.
232 *
233 * @param string $condition_id
234 * @param mixed $rule_saved_value
235 *
236 * @return bool
237 */
238 public static function _post_tag($condition_id, $rule_saved_value)
239 {
240 $target = explode('_', $condition_id);
241
242 $modifier = array_pop($target);
243
244 switch ($modifier) {
245 case 'all':
246 if (is_tag()) {
247 return true;
248 }
249 break;
250
251 case 'selected':
252 $selected = ! empty($rule_saved_value) ? $rule_saved_value : [];
253 if (is_tag(wp_parse_id_list($selected))) {
254 return true;
255 }
256 break;
257 }
258
259 return false;
260 }
261
262 /**
263 * Checks if the post_type has the selected categories.
264 *
265 * @param string $condition_id
266 * @param mixed $rule_saved_value
267 *
268 * @return bool
269 */
270 public static function _post_type_category($condition_id, $rule_saved_value)
271 {
272 $target = explode('_w_', $condition_id);
273
274 // First key is the post type.
275 $post_type = array_shift($target);
276
277 $selected = ! empty($rule_saved_value) ? $rule_saved_value : [];
278
279 if (self::_is_post_type($post_type) && has_category(wp_parse_id_list($selected))) {
280 return true;
281 }
282
283 return false;
284 }
285
286 /**
287 * Checks is a post_type has the selected tags.
288 *
289 * @param string $condition_id
290 * @param mixed $rule_saved_value
291 *
292 * @return bool
293 */
294 public static function _post_type_tag($condition_id, $rule_saved_value)
295 {
296 $target = explode('_w_', $condition_id);
297
298 // First key is the post type.
299 $post_type = array_shift($target);
300
301 $selected = ! empty($rule_saved_value) ? $rule_saved_value : [];
302 if (self::_is_post_type($post_type) && has_tag(wp_parse_id_list($selected))) {
303 return true;
304 }
305
306 return false;
307 }
308
309 /**
310 * @param string $post_type
311 *
312 * @return bool
313 */
314 public static function _is_post_type($post_type)
315 {
316 global $post;
317
318 return is_object($post) && $post->post_type == $post_type;
319 }
320 }