PluginProbe
User Submitted Posts – Enable Users to Submit Posts from the Front End / 20231102
User Submitted Posts – Enable Users to Submit Posts from the Front End v20231102
20260916 20260810 20260608 20230806 20230809 20230811 20230901 20230902 20230914 20231102 20240319 20240516 20240703 20241026 20250327 20250329 20251121 20251210 20260110 20260113 20260207 20260217 20260407 20260422 trunk All 59 releases
user-submitted-posts / library / plugin-settings.php

plugin-settings.php in User Submitted Posts – Enable Users to Submit Posts from the Front End 20231102, at library/plugin-settings.php

1,306 lines 46.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php // User Submitted Posts - Plugin Settings
2
3 if (!defined('ABSPATH')) die();
4
5
6
7 function usp_add_options_page() {
8
9 add_options_page(USP_PLUGIN, __('Submitted Posts', 'usp'), 'manage_options', 'user-submitted-posts', 'usp_render_form');
10
11 }
12 add_action('admin_menu', 'usp_add_options_page');
13
14
15
16 function usp_init() {
17
18 register_setting('usp_plugin_options', 'usp_options', 'usp_validate_options');
19
20 }
21 add_action('admin_init', 'usp_init');
22
23
24
25 function usp_plugin_action_links($links, $file) {
26
27 if ($file === USP_FILE && current_user_can('manage_options')) {
28
29 $settings = '<a href="'. admin_url('options-general.php?page=user-submitted-posts') .'">'. esc_html__('Settings', 'usp') .'</a>';
30
31 array_unshift($links, $settings);
32
33 }
34
35 if ($file === USP_FILE) {
36
37 $pro_href = 'https://plugin-planet.com/usp-pro/';
38 $pro_title = esc_attr__('Get USP Pro for unlimited forms!', 'usp');
39 $pro_text = esc_html__('Go Pro', 'usp');
40 $pro_style = 'font-weight:bold;';
41
42 $pro = '<a target="_blank" rel="noopener noreferrer" href="'. $pro_href .'" title="'. $pro_title .'" style="'. $pro_style .'">'. $pro_text .'</a>';
43
44 array_unshift($links, $pro);
45
46 }
47
48 return $links;
49
50 }
51 add_filter('plugin_action_links', 'usp_plugin_action_links', 10, 2);
52
53
54
55 function add_usp_links($links, $file) {
56
57 if ($file === USP_FILE) {
58
59 $home_href = 'https://perishablepress.com/user-submitted-posts/';
60 $home_title = esc_attr__('Plugin Homepage', 'usp');
61 $home_text = esc_html__('Homepage', 'usp');
62
63 $links[] = '<a target="_blank" rel="noopener noreferrer" href="'. $home_href .'" title="'. $home_title .'">'. $home_text .'</a>';
64
65 $rate_href = 'https://wordpress.org/support/plugin/user-submitted-posts/reviews/?rate=5#new-post';
66 $rate_title = esc_attr__('Give USP a 5-star rating at WordPress.org', 'usp');
67 $rate_text = esc_html__('Rate this plugin&nbsp;&raquo;', 'usp');
68
69 $links[] = '<a target="_blank" rel="noopener noreferrer" href="'. $rate_href .'" title="'. $rate_title .'">'. $rate_text .'</a>';
70
71 }
72
73 return $links;
74
75 }
76 add_filter('plugin_row_meta', 'add_usp_links', 10, 2);
77
78
79
80 function usp_admin_footer_text($text) {
81
82 $screen_id = usp_get_current_screen_id();
83
84 $ids = array('settings_page_user-submitted-posts/user-submitted-posts');
85
86 if ($screen_id && apply_filters('usp_admin_footer_text', in_array($screen_id, $ids))) {
87
88 $text = __('Like this plugin? Give it a', 'usp');
89
90 $text .= ' <a target="_blank" rel="noopener noreferrer" href="https://wordpress.org/support/plugin/user-submitted-posts/reviews/?rate=5#new-post">';
91
92 $text .= __('�
93
94
95
96
97 rating&nbsp;&raquo;', 'usp') .'</a>';
98
99 }
100
101 return $text;
102
103 }
104 add_filter('admin_footer_text', 'usp_admin_footer_text', 10, 1);
105
106
107
108 function usp_get_current_screen_id() {
109
110 if (!function_exists('get_current_screen')) require_once ABSPATH .'/wp-admin/includes/screen.php';
111
112 $screen = get_current_screen();
113
114 if ($screen && property_exists($screen, 'id')) return $screen->id;
115
116 return false;
117
118 }
119
120
121
122 function usp_get_current_screen_post_type() {
123
124 if (!function_exists('get_current_screen')) require_once ABSPATH .'/wp-admin/includes/screen.php';
125
126 $screen = get_current_screen();
127
128 if ($screen && property_exists($screen, 'post_type')) return $screen->post_type;
129
130 return false;
131
132 }
133
134
135
136 function usp_filter_safe_styles($styles) {
137
138 $styles[] = 'display';
139
140 return $styles;
141
142 }
143 add_filter('safe_style_css', 'usp_filter_safe_styles');
144
145
146
147 function usp_compare_version() {
148
149 global $usp_options;
150
151 $usp_options = get_option('usp_options');
152
153 $version_current = intval(USP_VERSION);
154 $version_previous = isset($usp_options['usp_version']) ? intval($usp_options['usp_version']) : $version_current;
155
156 if ($version_current > $version_previous) {
157
158 $usp_options['version_alert'] = 0;
159 $usp_options['usp_version'] = $version_current;
160
161 } else {
162
163 $usp_options['usp_version'] = $version_previous;
164
165 }
166
167 update_option('usp_options', $usp_options);
168
169 }
170 add_action('admin_init', 'usp_compare_version');
171
172
173
174 function usp_post_type() {
175
176 $post_type = array(
177
178 'post' => array(
179 'value' => 'post',
180 'label' => esc_html__('WP Post (recommended)', 'usp'),
181 ),
182 'page' => array(
183 'value' => 'page',
184 'label' => esc_html__('WP Page', 'usp'),
185 ),
186 );
187
188 return apply_filters('usp_post_type_options', $post_type);
189
190 }
191
192
193
194 function usp_form_version() {
195
196 $form_version = array(
197
198 'current' => array(
199 'value' => 'current',
200 'label' => esc_html__('HTML5 Form + Default CSS', 'usp') .' <span class="mm-item-caption">'. esc_html__('(Recommended)', 'usp') .'</span>',
201 ),
202 'disable' => array(
203 'value' => 'disable',
204 'label' => esc_html__('HTML5 Form + Disable CSS', 'usp') .' <span class="mm-item-caption">'. esc_html__('(Provide your own styles)', 'usp') .'</span>',
205 ),
206 'custom' => array(
207 'value' => 'custom',
208 'label' => esc_html__('Custom Form + Custom CSS', 'usp') .' <span class="mm-item-caption">'. esc_html__('(Provide your own form template &amp; styles)', 'usp') .'</span>',
209 ),
210 );
211
212 return $form_version;
213
214 }
215
216
217
218 function usp_image_display() {
219
220 $image_display = array(
221
222 'before' => array(
223 'value' => 'before',
224 'label' => esc_html__('Before post content', 'usp')
225 ),
226 'after' => array(
227 'value' => 'after',
228 'label' => esc_html__('After post content', 'usp')
229 ),
230 'disable' => array(
231 'value' => 'disable',
232 'label' => esc_html__('Do not display', 'usp')
233 ),
234 );
235
236 return $image_display;
237
238 }
239
240
241
242 function usp_email_display() {
243
244 $email_display = array(
245
246 'before' => array(
247 'value' => 'before',
248 'label' => esc_html__('Before post content', 'usp')
249 ),
250 'after' => array(
251 'value' => 'after',
252 'label' => esc_html__('After post content', 'usp')
253 ),
254 'disable' => array(
255 'value' => 'disable',
256 'label' => esc_html__('Do not display', 'usp')
257 ),
258 );
259
260 return $email_display;
261
262 }
263
264
265
266 function usp_name_display() {
267
268 $name_display = array(
269
270 'before' => array(
271 'value' => 'before',
272 'label' => esc_html__('Before post content', 'usp')
273 ),
274 'after' => array(
275 'value' => 'after',
276 'label' => esc_html__('After post content', 'usp')
277 ),
278 'disable' => array(
279 'value' => 'disable',
280 'label' => esc_html__('Do not display', 'usp')
281 ),
282 );
283
284 return $name_display;
285
286 }
287
288
289
290 function usp_url_display() {
291
292 $url_display = array(
293
294 'before' => array(
295 'value' => 'before',
296 'label' => esc_html__('Before post content', 'usp')
297 ),
298 'after' => array(
299 'value' => 'after',
300 'label' => esc_html__('After post content', 'usp')
301 ),
302 'disable' => array(
303 'value' => 'disable',
304 'label' => esc_html__('Do not display', 'usp')
305 ),
306 );
307
308 return $url_display;
309
310 }
311
312
313
314 function usp_custom_display() {
315
316 $custom_display = array(
317
318 'before' => array(
319 'value' => 'before',
320 'label' => esc_html__('Before post content', 'usp')
321 ),
322 'after' => array(
323 'value' => 'after',
324 'label' => esc_html__('After post content', 'usp')
325 ),
326 'disable' => array(
327 'value' => 'disable',
328 'label' => esc_html__('Do not display', 'usp')
329 ),
330 );
331
332 return $custom_display;
333
334 }
335
336
337
338 function usp_recaptcha_version() {
339
340 $recaptcha_version = array(
341
342 2 => array(
343 'value' => 2,
344 'label' => esc_html__('v2 (I&rsquo;m not a robot)', 'usp')
345 ),
346 3 => array(
347 'value' => 3,
348 'label' => esc_html__('v3 (Hidden reCaptcha)', 'usp')
349 ),
350 );
351
352 return $recaptcha_version;
353
354 }
355
356
357
358 function usp_form_field_options($args) {
359
360 global $usp_options;
361
362 $name = isset($args[0]) ? $args[0] : '';
363 $label = isset($args[1]) ? $args[1] : '';
364
365 $option = isset($usp_options[$name]) ? $usp_options[$name] : '';
366
367 $selected_show = ($option === 'show') ? 'selected="selected"' : '';
368 $selected_optn = ($option === 'optn') ? 'selected="selected"' : '';
369 $selected_hide = ($option === 'hide') ? 'selected="selected"' : '';
370
371 $output = '<tr>';
372 $output .= '<th scope="row"><label class="description" for="usp_options['. esc_attr($name) .']">'. esc_html($label) .'</label></th>';
373 $output .= '<td>';
374 $output .= '<select name="usp_options['. esc_attr($name) .']" id="usp_options['. esc_attr($name) .']">';
375
376 $output .= '<option '. $selected_show .' value="show">'. esc_html__('Enable and require', 'usp') .'</option>';
377 $output .= '<option '. $selected_optn .' value="optn">'. esc_html__('Enable but do not require', 'usp') .'</option>';
378 $output .= '<option '. $selected_hide .' value="hide">'. esc_html__('Disable this field', 'usp') .'</option>';
379
380 $output .= '</select>';
381 $output .= '</td>';
382 $output .= '</tr>';
383
384 return $output;
385
386 }
387
388
389
390 function usp_form_field_options_custom($field) {
391
392 global $usp_options;
393
394 if ($field === '1') {
395
396 $name = 'custom_field';
397 $label = esc_html__('Custom Field 1', 'usp');
398
399 } else {
400
401 $name = 'custom_field_2';
402 $label = esc_html__('Custom Field 2', 'usp');
403
404 }
405
406 $option = isset($usp_options[$name]) ? $usp_options[$name] : '';
407
408 $selected_show = ($option === 'show') ? 'selected="selected"' : '';
409 $selected_optn = ($option === 'optn') ? 'selected="selected"' : '';
410 $selected_hide = ($option === 'hide') ? 'selected="selected"' : '';
411
412 $output = '<tr>';
413 $output .= '<th scope="row"><label class="description" for="usp_options['. esc_attr($name) .']">'. esc_html($label) .'</label></th>';
414 $output .= '<td>';
415 $output .= '<select name="usp_options['. esc_attr($name) .']" id="usp_options['. esc_attr($name) .']">';
416
417 $output .= '<option '. $selected_show .' value="show">'. esc_html__('Enable and require', 'usp') .'</option>';
418 $output .= '<option '. $selected_optn .' value="optn">'. esc_html__('Enable but do not require', 'usp') .'</option>';
419 $output .= '<option '. $selected_hide .' value="hide">'. esc_html__('Disable this field', 'usp') .'</option>';
420
421 $output .= '</select>';
422 $output .= '</td>';
423 $output .= '</tr>';
424
425 return $output;
426
427 }
428
429
430
431 function usp_form_field_options_captcha() {
432
433 global $usp_options;
434
435 $name = 'usp_captcha';
436 $label = esc_html__('Challenge Question', 'usp');
437
438 $option = isset($usp_options[$name]) ? $usp_options[$name] : '';
439
440 $selected_show = ($option === 'show') ? 'selected="selected"' : '';
441 $selected_hide = ($option === 'hide') ? 'selected="selected"' : '';
442
443 $output = '<tr>';
444 $output .= '<th scope="row"><label class="description" for="usp_options['. esc_attr($name) .']">'. esc_html($label) .'</label></th>';
445 $output .= '<td>';
446 $output .= '<select name="usp_options['. esc_attr($name) .']" id="usp_options['. esc_attr($name) .']">';
447
448 $output .= '<option '. $selected_show .' value="show">'. esc_html__('Enable and require', 'usp') .'</option>';
449 $output .= '<option '. $selected_hide .' value="hide">'. esc_html__('Disable this field', 'usp') .'</option>';
450
451 $output .= '</select>';
452 $output .= '</td>';
453 $output .= '</tr>';
454
455 return $output;
456
457 }
458
459
460
461 function usp_form_field_options_recaptcha() {
462
463 global $usp_options;
464
465 $name = 'usp_recaptcha';
466 $label = esc_html__('Google reCaptcha', 'usp');
467
468 $option = isset($usp_options[$name]) ? $usp_options[$name] : '';
469
470 $selected_show = ($option === 'show') ? 'selected="selected"' : '';
471 $selected_hide = ($option === 'hide') ? 'selected="selected"' : '';
472
473 $output = '<tr>';
474 $output .= '<th scope="row"><label class="description" for="usp_options['. esc_attr($name) .']">'. esc_html($label) .'</label></th>';
475 $output .= '<td>';
476 $output .= '<select name="usp_options['. esc_attr($name) .']" id="usp_options['. esc_attr($name) .']">';
477
478 $output .= '<option '. $selected_show .' value="show">'. esc_html__('Enable and require', 'usp') .'</option>';
479 $output .= '<option '. $selected_hide .' value="hide">'. esc_html__('Disable this field', 'usp') .'</option>';
480
481 $output .= '</select>';
482 $output .= '</td>';
483 $output .= '</tr>';
484
485 return $output;
486
487 }
488
489
490
491 function usp_form_field_options_images() {
492
493 global $usp_options;
494
495 $name = 'usp_images';
496 $label = esc_html__('Image Uploads', 'usp');
497
498 $option = isset($usp_options[$name]) ? $usp_options[$name] : '';
499
500 $selected_show = ($option === 'show') ? 'selected="selected"' : '';
501 $selected_hide = ($option === 'hide') ? 'selected="selected"' : '';
502
503 $output = '<tr>';
504 $output .= '<th scope="row"><label class="description" for="usp_options['. esc_attr($name) .']">'. esc_html($label) .'</label></th>';
505 $output .= '<td>';
506 $output .= '<select name="usp_options['. esc_attr($name) .']" id="usp_options['. esc_attr($name) .']">';
507
508 $output .= '<option '. $selected_show .' value="show">'. esc_html__('Enable', 'usp') .'</option>';
509 $output .= '<option '. $selected_hide .' value="hide">'. esc_html__('Disable', 'usp') .'</option>';
510
511 $output .= '</select>';
512 $output .= '</td>';
513 $output .= '</tr>';
514
515 return $output;
516
517 }
518
519
520
521 function usp_form_display_options() {
522
523 global $usp_options;
524
525 $radio_setting = isset($usp_options['usp_form_version']) ? $usp_options['usp_form_version'] : '';
526
527 $form_styles = usp_form_version();
528
529 $output = '';
530
531 foreach ($form_styles as $form_style) {
532
533 $label = isset($form_style['label']) ? $form_style['label'] : '';
534 $value = isset($form_style['value']) ? $form_style['value'] : '';
535
536 $checked = (!empty($radio_setting) && $radio_setting === $value) ? 'checked="checked"' : '';
537
538 $class = ($value === 'custom') ? 'usp-custom-form' : 'usp-form';
539
540 $output .= '<div class="mm-radio-inputs">';
541 $output .= '<input type="radio" name="usp_options[usp_form_version]" class="'. $class .'" value="'. esc_attr($value) .'" '. $checked .' /> '. $label;
542 $output .= '</div>';
543
544 }
545
546 return $output;
547
548 }
549
550
551
552 function usp_post_type_options() {
553
554 global $usp_options;
555
556 $usp_post_type = usp_post_type();
557
558 $selected_option = isset($usp_options['usp_post_type']) ? $usp_options['usp_post_type'] : 'post';
559
560 $select_options = '<select name="usp_options[usp_post_type]">';
561
562 foreach($usp_post_type as $k => $v) {
563
564 $selected = selected($selected_option === $k, true, false);
565
566 $value = isset($v['value']) ? $v['value'] : null;
567 $label = isset($v['label']) ? $v['label'] : null;
568
569 $select_options .= '<option value="'. $value .'"'. $selected .'>'. $label .'</option>';
570
571 }
572
573 $select_options .= '</select>';
574
575 return $select_options;
576
577 }
578
579
580
581 function usp_post_status_options() {
582
583 global $usp_options;
584
585 $approved = isset($usp_options['number-approved']) ? intval($usp_options['number-approved']) : -1;
586
587 $output = '<select id="usp_options[number-approved]" name="usp_options[number-approved]">';
588
589 foreach (range(-2, 20) as $v) {
590
591 if ($v === -2) $k = esc_html__('Draft', 'usp');
592 elseif ($v === -1) $k = esc_html__('Pending (default)', 'usp');
593 elseif ($v === 0) $k = esc_html__('Publish immediately', 'usp');
594 elseif ($v === 1) $k = esc_html__('Publish after 1 approved post', 'usp');
595 else $k = esc_html__('Publish after ', 'usp') . $v . esc_html__(' approved posts', 'usp');
596
597 $selected = selected($v, $approved, false);
598
599 $output .= '<option '. $selected .' value="'. $v .'">'. $k .'</option>';
600
601 }
602
603 $output .= '</select>';
604
605 return $output;
606
607 }
608
609
610
611 function usp_post_category_options() {
612
613 global $usp_options;
614
615 $options = isset($usp_options['categories']) ? $usp_options['categories'] : array();
616
617 $cats = get_categories(array('parent' => 0, 'orderby' => 'name', 'order' => 'ASC', 'hide_empty' => 0));
618
619 if (empty($cats)) return;
620
621 $usp_cats = array();
622
623 $output = '<div class="mm-item-desc">'. esc_html__('Select categories to include in the Category field:', 'usp') .'</div>';
624 $output .= '<ul class="usp-category-options">';
625
626 foreach ($cats as $c) {
627
628 // parents
629
630 $output .= '<li><input type="checkbox" name="usp_options[categories][]" id="usp_options[categories][]" value="'. esc_attr($c->term_id) .'" '. checked(true, in_array($c->term_id, $options), false) .'> ';
631 $output .= '<label for="usp_options[categories][]"><a href="'. esc_url(get_category_link($c->term_id)) .'" title="Cat ID: '. esc_attr($c->term_id) .'" target="_blank" rel="noopener noreferrer">'. esc_html($c->name) .'</a></label></li>';
632
633 $usp_cats['c'][] = array('id' => esc_attr($c->term_id), 'c1' => array());
634 $children = get_terms('category', array('parent' => esc_attr($c->term_id), 'hide_empty' => 0));
635
636 if (!empty($children)) {
637
638 $output .= '<li><ul>';
639
640 foreach ($children as $c1) {
641
642 // children
643
644 $usp_cats['c'][]['c1'][] = array('id' => esc_attr($c1->term_id), 'c2' => array());
645 $grandchildren = get_terms('category', array('parent' => esc_attr($c1->term_id), 'hide_empty' => 0));
646
647 if (!empty($grandchildren)) {
648
649 $output .= '<li><input type="checkbox" name="usp_options[categories][]" id="usp_options[categories][]" value="'. esc_attr($c1->term_id) .'" '. checked(true, in_array($c1->term_id, $options), false) .'> ';
650 $output .= '<label for="usp_options[categories][]"><a href="'. esc_url(get_category_link($c1->term_id)) .'" title="Cat ID: '. esc_attr($c1->term_id) .'" target="_blank" rel="noopener noreferrer">'. esc_html($c1->name) .'</a></label>';
651 $output .= '<ul>';
652
653 foreach ($grandchildren as $c2) {
654
655 // grandchildren
656
657 $usp_cats['c'][]['c1'][]['c2'][] = array('id' => esc_attr($c2->term_id), 'c3' => array());
658 $great_grandchildren = get_terms('category', array('parent' => esc_attr($c2->term_id), 'hide_empty' => 0));
659
660 if (!empty($great_grandchildren)) {
661
662 $output .= '<li><input type="checkbox" name="usp_options[categories][]" id="usp_options[categories][]" value="'. esc_attr($c2->term_id) .'" '. checked(true, in_array($c2->term_id, $options), false) .'> ';
663 $output .= '<label for="usp_options[categories][]"><a href="'. esc_url(get_category_link($c2->term_id)) .'" title="Cat ID: '. esc_attr($c2->term_id) .'" target="_blank" rel="noopener noreferrer">'. esc_html($c2->name) .'</a></label>';
664 $output .= '<ul>';
665
666 foreach ($great_grandchildren as $c3) {
667
668 // great enkelkinder
669
670 $usp_cats['c'][]['c1'][]['c2'][]['c3'][] = array('id' => esc_attr($c3->term_id), 'c4' => array());
671 $great_great_grandchildren = get_terms('category', array('parent' => esc_attr($c3->term_id), 'hide_empty' => 0));
672
673 if (!empty($great_great_grandchildren)) {
674
675 $output .= '<li><input type="checkbox" name="usp_options[categories][]" id="usp_options[categories][]" value="'. esc_attr($c3->term_id) .'" '. checked(true, in_array($c3->term_id, $options), false) .'> ';
676 $output .= '<label for="usp_options[categories][]"><a href="'. esc_url(get_category_link($c3->term_id)) .'" title="Cat ID: '. esc_attr($c3->term_id) .'" target="_blank" rel="noopener noreferrer">'. esc_html($c3->name) .'</a></label>';
677 $output .= '<ul>';
678
679 foreach ($great_great_grandchildren as $c4) {
680
681 // great great grandchildren
682
683 $usp_cats['c'][]['c1'][]['c2'][]['c3'][]['c4'][] = array('id' => esc_attr($c4->term_id));
684 $output .= '<li><input type="checkbox" name="usp_options[categories][]" id="usp_options[categories][]" value="'. esc_attr($c4->term_id) .'" '. checked(true, in_array($c4->term_id, $options), false) .'> ';
685 $output .= '<label for="usp_options[categories][]"><a href="'. esc_url(get_category_link($c4->term_id)) .'" title="Cat ID: '. esc_attr($c4->term_id) .'" target="_blank" rel="noopener noreferrer">'. esc_html($c4->name) .'</a></label></li>';
686
687 }
688 $output .= '</ul></li>'; // great great grandchildren
689
690 } else {
691 $output .= '<li><input type="checkbox" name="usp_options[categories][]" id="usp_options[categories][]" value="'. esc_attr($c3->term_id) .'" '. checked(true, in_array($c3->term_id, $options), false) .'> ';
692 $output .= '<label for="usp_options[categories][]"><a href="'. esc_url(get_category_link($c3->term_id)) .'" title="Cat ID: '. esc_attr($c3->term_id) .'" target="_blank" rel="noopener noreferrer">'. esc_html($c3->name) .'</a></label></li>';
693 }
694 }
695 $output .= '</ul></li>'; // great grandchildren
696 } else {
697 $output .= '<li><input type="checkbox" name="usp_options[categories][]" id="usp_options[categories][]" value="'. esc_attr($c2->term_id) .'" '. checked(true, in_array($c2->term_id, $options), false) .'> ';
698 $output .= '<label for="usp_options[categories][]"><a href="'. esc_url(get_category_link($c2->term_id)) .'" title="Cat ID: '. esc_attr($c2->term_id) .'" target="_blank" rel="noopener noreferrer">'. esc_html($c2->name) .'</a></label></li>';
699 }
700 }
701 $output .= '</ul></li>'; // grandchildren
702 } else {
703 $output .= '<li><input type="checkbox" name="usp_options[categories][]" id="usp_options[categories][]" value="'. esc_attr($c1->term_id) .'" '. checked(true, in_array($c1->term_id, $options), false) .'> ';
704 $output .= '<label for="usp_options[categories][]"><a href="'. esc_url(get_category_link($c1->term_id)) .'" title="Cat ID: '. esc_attr($c1->term_id) .'" target="_blank" rel="noopener noreferrer">'. esc_html($c1->name) .'</a></label></li>';
705 }
706 }
707 $output .= '</ul></li>'; // children
708 }
709 }
710
711 $output .= '</ul>'; // parents
712
713 return $output;
714
715 }
716
717
718
719 function usp_post_author_options() {
720
721 global $usp_options, $wpdb;
722
723 $user_count = count_users();
724
725 $user_total = isset($user_count['total_users']) ? intval($user_count['total_users']) : 1;
726
727 $user_max = apply_filters('usp_max_users', 200);
728
729 $limit = ($user_total > $user_max) ? $user_max : $user_total;
730
731 if (is_multisite()) {
732
733 $args = array('blog_id' => get_current_blog_id(), 'number' => $limit);
734
735 $user_query = new WP_User_Query($args);
736
737 $users = $user_query->get_results();
738
739 } else {
740
741 $query = "SELECT ID, display_name FROM {$wpdb->users} LIMIT %d";
742
743 $users = $wpdb->get_results($wpdb->prepare($query, $limit));
744
745 }
746
747 $output = '<select id="usp_options[author]" name="usp_options[author]">';
748
749 foreach($users as $user) {
750
751 $selected = isset($usp_options['author']) ? selected($usp_options['author'], $user->ID, false) : '';
752
753 $output .= '<option '. $selected .'value="'. esc_attr($user->ID) .'">'. esc_html($user->display_name) .'</option>';
754
755 }
756
757 $output .= '</select>';
758
759 return $output;
760
761 }
762
763
764
765 function usp_auto_display_options($item) {
766
767 global $usp_options;
768
769 $usp_image_display = usp_image_display();
770 $usp_email_display = usp_email_display();
771 $usp_name_display = usp_name_display();
772 $usp_url_display = usp_url_display();
773 $usp_custom_display = usp_custom_display();
774
775 if ($item === 'images') {
776
777 $array = $usp_image_display;
778 $key = 'auto_display_images';
779
780 } elseif ($item === 'email') {
781
782 $array = $usp_email_display;
783 $key = 'auto_display_email';
784
785 } elseif ($item === 'name') {
786
787 $array = $usp_name_display;
788 $key = 'auto_display_name';
789
790 } elseif ($item === 'url') {
791
792 $array = $usp_url_display;
793 $key = 'auto_display_url';
794
795 } elseif ($item === 'custom') {
796
797 $array = $usp_custom_display;
798 $key = 'auto_display_custom';
799
800 } elseif ($item === 'custom_2') {
801
802 $array = $usp_custom_display;
803 $key = 'auto_display_custom_2';
804
805 }
806
807 $radio_setting = isset($usp_options[$key]) ? $usp_options[$key] : '';
808
809 $output = '';
810
811 foreach ($array as $arr) {
812
813 $label = isset($arr['label']) ? $arr['label'] : '';
814 $value = isset($arr['value']) ? $arr['value'] : '';
815
816 $checked = (!empty($radio_setting) && $radio_setting === $value) ? 'checked="checked"' : '';
817
818 $output .= '<div class="mm-radio-inputs">';
819 $output .= '<input type="radio" name="usp_options['. esc_attr($key) .']" value="'. esc_attr($value) .'" '. $checked .' /> '. esc_html($label);
820 $output .= '</div>';
821
822 }
823
824 return $output;
825
826 }
827
828
829
830 function usp_form_field_recaptcha() {
831
832 global $usp_options;
833
834 $version = isset($usp_options['recaptcha_version']) ? $usp_options['recaptcha_version'] : 2;
835
836 $output = '<select id="usp_options[recaptcha_version]" name="usp_options[recaptcha_version]">';
837
838 foreach(usp_recaptcha_version() as $option) {
839
840 $option_value = isset($option['value']) ? $option['value'] : '';
841 $option_label = isset($option['label']) ? $option['label'] : '';
842
843 $output .= '<option '. selected($option_value, $version, false) .' value="'. esc_attr($option_value) .'">'. esc_attr($option_label) .'</option>';
844
845 }
846
847 $output .= '</select>';
848
849 return $output;
850
851 }
852
853
854
855 function usp_add_defaults() {
856
857 $currentUser = wp_get_current_user();
858
859 $admin_mail = get_bloginfo('admin_email');
860
861 $tmp = get_option('usp_options');
862
863 if ((isset($tmp['default_options']) && $tmp['default_options'] == '1') || (!is_array($tmp))) {
864
865 $arr = array(
866 'usp_version' => USP_VERSION,
867 'version_alert' => 0,
868 'default_options' => 0,
869 'author' => $currentUser->ID,
870 'categories' => array(get_option('default_category')),
871 'multiple-cats' => false,
872 'number-approved' => -1,
873 'redirect-url' => '',
874 'error-message' => esc_html__('There was an error. Please check required fields and try again.', 'usp'),
875 'min-images' => 0,
876 'max-images' => 1,
877 'min-image-height' => 0,
878 'min-image-width' => 0,
879 'max-image-height' => 2500,
880 'max-image-width' => 2500,
881 'usp_name' => 'show',
882 'usp_url' => 'show',
883 'usp_email' => 'hide',
884 'usp_title' => 'show',
885 'usp_tags' => 'show',
886 'usp_category' => 'show',
887 'usp_images' => 'hide',
888 'upload-message' => esc_html__('Please select your image(s) to upload.', 'usp'),
889 'usp_question' => '1 + 1 =',
890 'usp_response' => '2',
891 'usp_casing' => 0,
892 'usp_captcha' => 'show',
893 'usp_content' => 'show',
894 'success-message' => esc_html__('Success! Thank you for your submission.', 'usp'),
895 'usp_form_version' => 'current',
896 'usp_email_alerts' => 1,
897 'usp_email_html' => 0,
898 'usp_email_address' => $admin_mail,
899 'usp_email_from' => $admin_mail,
900 'usp_use_author' => 0,
901 'usp_use_url' => 0,
902 'usp_use_email' => 0,
903 'usp_use_cat' => 0,
904 'usp_use_cat_id' => '',
905 'usp_include_js' => 1,
906 'usp_display_url' => '',
907 'usp_form_content' => '',
908 'usp_existing_tags' => 0,
909 'usp_richtext_editor' => 0,
910 'usp_featured_images' => 0,
911 'usp_add_another' => '',
912 'disable_required' => 0,
913 'titles_unique' => 0,
914 'enable_shortcodes' => 0,
915 'disable_ip_tracking' => 0,
916 'email_alert_subject' => '',
917 'email_alert_message' => '',
918 'auto_display_images' => 'disable',
919 'auto_display_email' => 'disable',
920 'auto_display_name' => 'disable',
921 'auto_display_url' => 'disable',
922 'auto_image_markup' => '<a href="%%full%%"><img src="%%thumb%%" width="%%width%%" height="%%height%%" alt="%%title%%" style="display:inline-block;"></a> ',
923 'auto_email_markup' => '<p><a href="mailto:%%email%%">'. esc_html__('Email', 'usp') .'</a></p>',
924 'auto_name_markup' => '<p>%%author%%</p>',
925 'auto_url_markup' => '<p><a href="%%url%%">'. esc_html__('URL', 'usp') .'</a></p>',
926 'logged_in_users' => 0,
927 'disable_author' => 0,
928 'recaptcha_public' => '',
929 'recaptcha_private' => '',
930 'recaptcha_version' => 2,
931 'usp_recaptcha' => 'hide',
932 'usp_post_type' => 'post',
933 'custom_field' => 'hide',
934 'custom_name' => 'usp_custom_field',
935 'custom_label' => esc_html__('Custom Field 1', 'usp'),
936 'custom_field_2' => 'hide',
937 'custom_name_2' => 'usp_custom_field_2',
938 'custom_label_2' => esc_html__('Custom Field 2', 'usp'),
939 'auto_display_custom' => 'disable',
940 'auto_custom_markup' => '<p>%%custom_label%% : %%custom_name%% : %%custom_value%%</p>',
941 'auto_display_custom_2' => 'disable',
942 'auto_custom_markup_2' => '<p>%%custom_label_2%% : %%custom_name_2%% : %%custom_value_2%%</p>',
943 'custom_checkbox' => false,
944 'custom_checkbox_name' => 'usp_custom_checkbox',
945 'custom_checkbox_text' => 'I agree the to the terms.',
946 'custom_checkbox_err' => 'Custom checkbox required',
947 );
948
949 update_option('usp_options', $arr);
950
951 }
952
953 }
954
955
956
957 function usp_delete_plugin_options() {
958
959 delete_option('usp_options');
960
961 }
962
963
964
965 function usp_update_category_option($option_name, $old_value, $value) {
966
967 usp_clear_cookies();
968
969 }
970 add_action('updated_option', 'usp_update_category_option', 10, 3);
971
972
973
974 function usp_validate_options($input) {
975
976 global $usp_options;
977
978 if (!isset($input['version_alert'])) $input['version_alert'] = null;
979 $input['version_alert'] = ($input['version_alert'] == 1 ? 1 : 0);
980
981 if (!isset($input['default_options'])) $input['default_options'] = null;
982 $input['default_options'] = ($input['default_options'] == 1 ? 1 : 0);
983
984 if (isset($input['categories'])) $input['categories'] = is_array($input['categories']) && !empty($input['categories']) ? array_unique($input['categories']) : array(get_option('default_category'));
985
986 $input['number-approved'] = is_numeric($input['number-approved']) ? intval($input['number-approved']) : -1;
987
988 $input['min-images'] = is_numeric($input['min-images']) ? intval($input['min-images']) : $input['max-images'];
989 $input['max-images'] = (is_numeric($input['max-images']) && ($usp_options['min-images'] <= abs($input['max-images']))) ? intval($input['max-images']) : $usp_options['max-images'];
990
991 $input['min-image-height'] = is_numeric($input['min-image-height']) ? intval($input['min-image-height']) : $usp_options['min-image-height'];
992 $input['min-image-width'] = is_numeric($input['min-image-width']) ? intval($input['min-image-width']) : $usp_options['min-image-width'];
993
994 $input['max-image-height'] = (is_numeric($input['max-image-height']) && ($usp_options['min-image-height'] <= $input['max-image-height'])) ? intval($input['max-image-height']) : $usp_options['max-image-height'];
995 $input['max-image-width'] = (is_numeric($input['max-image-width']) && ($usp_options['min-image-width'] <= $input['max-image-width'])) ? intval($input['max-image-width']) : $usp_options['max-image-width'];
996
997 $usp_form_version = usp_form_version();
998 if (!isset($input['usp_form_version'])) $input['usp_form_version'] = null;
999 if (!array_key_exists($input['usp_form_version'], $usp_form_version)) $input['usp_form_version'] = null;
1000
1001 $usp_image_display = usp_image_display();
1002 if (!isset($input['auto_display_images'])) $input['auto_display_images'] = null;
1003 if (!array_key_exists($input['auto_display_images'], $usp_image_display)) $input['auto_display_images'] = null;
1004
1005 $usp_email_display = usp_email_display();
1006 if (!isset($input['auto_display_email'])) $input['auto_display_email'] = null;
1007 if (!array_key_exists($input['auto_display_email'], $usp_email_display)) $input['auto_display_email'] = null;
1008
1009 $usp_url_display = usp_url_display();
1010 if (!isset($input['auto_display_url'])) $input['auto_display_url'] = null;
1011 if (!array_key_exists($input['auto_display_url'], $usp_url_display)) $input['auto_display_url'] = null;
1012
1013 $usp_custom_display = usp_custom_display();
1014 if (!isset($input['auto_display_custom'])) $input['auto_display_custom'] = null;
1015 if (!array_key_exists($input['auto_display_custom'], $usp_custom_display)) $input['auto_display_custom'] = null;
1016
1017 if (!isset($input['auto_display_custom_2'])) $input['auto_display_custom_2'] = null;
1018 if (!array_key_exists($input['auto_display_custom_2'], $usp_custom_display)) $input['auto_display_custom_2'] = null;
1019
1020 $usp_post_type = usp_post_type();
1021 if (!isset($input['usp_post_type'])) $input['usp_post_type'] = null;
1022 if (!array_key_exists($input['usp_post_type'], $usp_post_type)) $input['usp_post_type'] = null;
1023
1024 $usp_recaptcha_version = usp_recaptcha_version();
1025 if (!isset($input['recaptcha_version'])) $input['recaptcha_version'] = null;
1026 if (!array_key_exists($input['recaptcha_version'], $usp_recaptcha_version)) $input['recaptcha_version'] = null;
1027
1028 if (isset($input['author'])) $input['author'] = wp_filter_nohtml_kses($input['author']); else $input['author'] = null;
1029 if (isset($input['usp_name'])) $input['usp_name'] = wp_filter_nohtml_kses($input['usp_name']); else $input['usp_name'] = null;
1030 if (isset($input['usp_url'])) $input['usp_url'] = wp_filter_nohtml_kses($input['usp_url']); else $input['usp_url'] = null;
1031 if (isset($input['usp_email'])) $input['usp_email'] = wp_filter_nohtml_kses($input['usp_email']); else $input['usp_email'] = null;
1032 if (isset($input['usp_title'])) $input['usp_title'] = wp_filter_nohtml_kses($input['usp_title']); else $input['usp_title'] = null;
1033 if (isset($input['usp_tags'])) $input['usp_tags'] = wp_filter_nohtml_kses($input['usp_tags']); else $input['usp_tags'] = null;
1034 if (isset($input['usp_category'])) $input['usp_category'] = wp_filter_nohtml_kses($input['usp_category']); else $input['usp_category'] = null;
1035 if (isset($input['usp_images'])) $input['usp_images'] = wp_filter_nohtml_kses($input['usp_images']); else $input['usp_images'] = null;
1036 if (isset($input['usp_question'])) $input['usp_question'] = wp_filter_nohtml_kses($input['usp_question']); else $input['usp_question'] = null;
1037 if (isset($input['usp_captcha'])) $input['usp_captcha'] = wp_filter_nohtml_kses($input['usp_captcha']); else $input['usp_captcha'] = null;
1038 if (isset($input['usp_content'])) $input['usp_content'] = wp_filter_nohtml_kses($input['usp_content']); else $input['usp_content'] = null;
1039 if (isset($input['usp_email_address'])) $input['usp_email_address'] = wp_filter_nohtml_kses($input['usp_email_address']); else $input['usp_email_address'] = null;
1040 if (isset($input['usp_email_from'])) $input['usp_email_from'] = wp_filter_nohtml_kses($input['usp_email_from']); else $input['usp_email_from'] = null;
1041 if (isset($input['usp_use_cat_id'])) $input['usp_use_cat_id'] = wp_filter_nohtml_kses($input['usp_use_cat_id']); else $input['usp_use_cat_id'] = null;
1042 if (isset($input['usp_display_url'])) $input['usp_display_url'] = wp_filter_nohtml_kses($input['usp_display_url']); else $input['usp_display_url'] = null;
1043 if (isset($input['redirect-url'])) $input['redirect-url'] = wp_filter_nohtml_kses($input['redirect-url']); else $input['redirect-url'] = null;
1044 if (isset($input['email_alert_subject'])) $input['email_alert_subject'] = wp_filter_nohtml_kses($input['email_alert_subject']); else $input['email_alert_subject'] = null;
1045 if (isset($input['recaptcha_public'])) $input['recaptcha_public'] = wp_filter_nohtml_kses($input['recaptcha_public']); else $input['recaptcha_public'] = null;
1046 if (isset($input['recaptcha_private'])) $input['recaptcha_private'] = wp_filter_nohtml_kses($input['recaptcha_private']); else $input['recaptcha_private'] = null;
1047 if (isset($input['usp_recaptcha'])) $input['usp_recaptcha'] = wp_filter_nohtml_kses($input['usp_recaptcha']); else $input['usp_recaptcha'] = null;
1048 if (isset($input['custom_field'])) $input['custom_field'] = wp_filter_nohtml_kses($input['custom_field']); else $input['custom_field'] = null;
1049 if (isset($input['custom_name'])) $input['custom_name'] = wp_filter_nohtml_kses($input['custom_name']); else $input['custom_name'] = null;
1050 if (isset($input['custom_label'])) $input['custom_label'] = wp_filter_nohtml_kses($input['custom_label']); else $input['custom_label'] = null;
1051 if (isset($input['custom_field_2'])) $input['custom_field_2'] = wp_filter_nohtml_kses($input['custom_field_2']); else $input['custom_field_2'] = null;
1052 if (isset($input['custom_name_2'])) $input['custom_name_2'] = wp_filter_nohtml_kses($input['custom_name_2']); else $input['custom_name_2'] = null;
1053 if (isset($input['custom_label_2'])) $input['custom_label_2'] = wp_filter_nohtml_kses($input['custom_label_2']); else $input['custom_label_2'] = null;
1054 if (isset($input['custom_checkbox_name'])) $input['custom_checkbox_name'] = wp_filter_nohtml_kses($input['custom_checkbox_name']); else $input['custom_checkbox_name'] = null;
1055 if (isset($input['custom_checkbox_err'])) $input['custom_checkbox_err'] = wp_filter_nohtml_kses($input['custom_checkbox_err']); else $input['custom_checkbox_err'] = null;
1056
1057 if (isset($input['usp_featured_image_default'])) $input['usp_featured_image_default'] = wp_filter_nohtml_kses($input['usp_featured_image_default']); else $input['usp_featured_image_default'] = null;
1058
1059 // dealing with kses
1060
1061 global $allowedposttags;
1062
1063 $default_allowedposttags = $allowedposttags;
1064
1065 $allowed_atts = array(
1066 'align' => array(),
1067 'class' => array(),
1068 'type' => array(),
1069 'id' => array(),
1070 'dir' => array(),
1071 'lang' => array(),
1072 'style' => array(),
1073 'xml:lang' => array(),
1074 'src' => array(),
1075 'alt' => array(),
1076 'href' => array(),
1077 'rel' => array(),
1078 'rev' => array(),
1079 'target' => array(),
1080 'novalidate' => array(),
1081 'type' => array(),
1082 'value' => array(),
1083 'name' => array(),
1084 'tabindex' => array(),
1085 'action' => array(),
1086 'method' => array(),
1087 'for' => array(),
1088 'width' => array(),
1089 'height' => array(),
1090 'data' => array(),
1091 'data-rel' => array(),
1092 'title' => array(),
1093 );
1094 $allowedposttags['form'] = $allowed_atts;
1095 $allowedposttags['label'] = $allowed_atts;
1096 $allowedposttags['input'] = $allowed_atts;
1097 $allowedposttags['textarea'] = $allowed_atts;
1098 $allowedposttags['iframe'] = $allowed_atts;
1099 $allowedposttags['script'] = $allowed_atts;
1100 $allowedposttags['style'] = $allowed_atts;
1101 $allowedposttags['strong'] = $allowed_atts;
1102 $allowedposttags['small'] = $allowed_atts;
1103 $allowedposttags['table'] = $allowed_atts;
1104 $allowedposttags['span'] = $allowed_atts;
1105 $allowedposttags['abbr'] = $allowed_atts;
1106 $allowedposttags['code'] = $allowed_atts;
1107 $allowedposttags['pre'] = $allowed_atts;
1108 $allowedposttags['div'] = $allowed_atts;
1109 $allowedposttags['img'] = $allowed_atts;
1110 $allowedposttags['h1'] = $allowed_atts;
1111 $allowedposttags['h2'] = $allowed_atts;
1112 $allowedposttags['h3'] = $allowed_atts;
1113 $allowedposttags['h4'] = $allowed_atts;
1114 $allowedposttags['h5'] = $allowed_atts;
1115 $allowedposttags['h6'] = $allowed_atts;
1116 $allowedposttags['ol'] = $allowed_atts;
1117 $allowedposttags['ul'] = $allowed_atts;
1118 $allowedposttags['li'] = $allowed_atts;
1119 $allowedposttags['em'] = $allowed_atts;
1120 $allowedposttags['hr'] = $allowed_atts;
1121 $allowedposttags['br'] = $allowed_atts;
1122 $allowedposttags['tr'] = $allowed_atts;
1123 $allowedposttags['td'] = $allowed_atts;
1124 $allowedposttags['p'] = $allowed_atts;
1125 $allowedposttags['a'] = $allowed_atts;
1126 $allowedposttags['b'] = $allowed_atts;
1127 $allowedposttags['i'] = $allowed_atts;
1128
1129 if (isset($input['usp_form_content'])) $input['usp_form_content'] = wp_kses_post($input['usp_form_content'], $allowedposttags); else $input['usp_form_content'] = null;
1130 if (isset($input['error-message'])) $input['error-message'] = wp_kses_post($input['error-message'], $allowedposttags); else $input['error-message'] = null;
1131 if (isset($input['upload-message'])) $input['upload-message'] = wp_kses_post($input['upload-message'], $allowedposttags); else $input['upload-message'] = null;
1132 if (isset($input['success-message'])) $input['success-message'] = wp_kses_post($input['success-message'], $allowedposttags); else $input['success-message'] = null;
1133 if (isset($input['usp_add_another'])) $input['usp_add_another'] = wp_kses_post($input['usp_add_another'], $allowedposttags); else $input['usp_add_another'] = null;
1134 if (isset($input['email_alert_message'])) $input['email_alert_message'] = wp_kses_post($input['email_alert_message'], $allowedposttags); else $input['email_alert_message'] = null;
1135 if (isset($input['auto_image_markup'])) $input['auto_image_markup'] = wp_kses_post($input['auto_image_markup'], $allowedposttags); else $input['auto_image_markup'] = null;
1136 if (isset($input['auto_email_markup'])) $input['auto_email_markup'] = wp_kses_post($input['auto_email_markup'], $allowedposttags); else $input['auto_email_markup'] = null;
1137 if (isset($input['auto_url_markup'])) $input['auto_url_markup'] = wp_kses_post($input['auto_url_markup'], $allowedposttags); else $input['auto_url_markup'] = null;
1138 if (isset($input['auto_custom_markup'])) $input['auto_custom_markup'] = wp_kses_post($input['auto_custom_markup'], $allowedposttags); else $input['auto_custom_markup'] = null;
1139 if (isset($input['custom_checkbox_text'])) $input['custom_checkbox_text'] = wp_kses_post($input['custom_checkbox_text'], $allowedposttags); else $input['custom_checkbox_text'] = null;
1140
1141 $allowedposttags = $default_allowedposttags;
1142
1143 if (!isset($input['usp_casing'])) $input['usp_casing'] = null;
1144 $input['usp_casing'] = ($input['usp_casing'] == 1 ? 1 : 0);
1145
1146 if (!isset($input['usp_email_alerts'])) $input['usp_email_alerts'] = null;
1147 $input['usp_email_alerts'] = ($input['usp_email_alerts'] == 1 ? 1 : 0);
1148
1149 if (!isset($input['usp_email_html'])) $input['usp_email_html'] = null;
1150 $input['usp_email_html'] = ($input['usp_email_html'] == 1 ? 1 : 0);
1151
1152 if (!isset($input['usp_use_author'])) $input['usp_use_author'] = null;
1153 $input['usp_use_author'] = ($input['usp_use_author'] == 1 ? 1 : 0);
1154
1155 if (!isset($input['usp_use_url'])) $input['usp_use_url'] = null;
1156 $input['usp_use_url'] = ($input['usp_use_url'] == 1 ? 1 : 0);
1157
1158 if (!isset($input['usp_use_email'])) $input['usp_use_email'] = null;
1159 $input['usp_use_email'] = ($input['usp_use_email'] == 1 ? 1 : 0);
1160
1161 if (!isset($input['usp_use_cat'])) $input['usp_use_cat'] = null;
1162 $input['usp_use_cat'] = ($input['usp_use_cat'] == 1 ? 1 : 0);
1163
1164 if (!isset($input['usp_include_js'])) $input['usp_include_js'] = null;
1165 $input['usp_include_js'] = ($input['usp_include_js'] == 1 ? 1 : 0);
1166
1167 if (!isset($input['usp_existing_tags'])) $input['usp_existing_tags'] = null;
1168 $input['usp_existing_tags'] = ($input['usp_existing_tags'] == 1 ? 1 : 0);
1169
1170 if (!isset($input['usp_richtext_editor'])) $input['usp_richtext_editor'] = null;
1171 $input['usp_richtext_editor'] = ($input['usp_richtext_editor'] == 1 ? 1 : 0);
1172
1173 if (!isset($input['usp_featured_images'])) $input['usp_featured_images'] = null;
1174 $input['usp_featured_images'] = ($input['usp_featured_images'] == 1 ? 1 : 0);
1175
1176 if (!isset($input['disable_required'])) $input['disable_required'] = null;
1177 $input['disable_required'] = ($input['disable_required'] == 1 ? 1 : 0);
1178
1179 if (!isset($input['titles_unique'])) $input['titles_unique'] = null;
1180 $input['titles_unique'] = ($input['titles_unique'] == 1 ? 1 : 0);
1181
1182 if (!isset($input['enable_shortcodes'])) $input['enable_shortcodes'] = null;
1183 $input['enable_shortcodes'] = ($input['enable_shortcodes'] == 1 ? 1 : 0);
1184
1185 if (!isset($input['disable_ip_tracking'])) $input['disable_ip_tracking'] = null;
1186 $input['disable_ip_tracking'] = ($input['disable_ip_tracking'] == 1 ? 1 : 0);
1187
1188 if (!isset($input['logged_in_users'])) $input['logged_in_users'] = null;
1189 $input['logged_in_users'] = ($input['logged_in_users'] == 1 ? 1 : 0);
1190
1191 if (!isset($input['disable_author'])) $input['disable_author'] = null;
1192 $input['disable_author'] = ($input['disable_author'] == 1 ? 1 : 0);
1193
1194 if (!isset($input['custom_checkbox'])) $input['custom_checkbox'] = null;
1195 $input['custom_checkbox'] = ($input['custom_checkbox'] == 1 ? 1 : 0);
1196
1197 if (!isset($input['multiple-cats'])) $input['multiple-cats'] = null;
1198 $input['multiple-cats'] = ($input['multiple-cats'] == 1 ? 1 : 0);
1199
1200 return apply_filters('usp_input_validate', $input);
1201
1202 }
1203
1204 //
1205
1206 function usp_admin_notice() {
1207
1208 if (usp_get_current_screen_id() === 'settings_page_user-submitted-posts') {
1209
1210 if (!usp_check_date_expired() && !usp_dismiss_notice_check()) {
1211
1212 ?>
1213
1214 <div class="notice notice-success">
1215 <p>
1216 <strong><?php esc_html_e('Fall Sale!', 'usp'); ?></strong>
1217 <?php esc_html_e('Save 25% on our', 'usp'); ?>
1218 <a target="_blank" rel="noopener noreferrer" href="https://plugin-planet.com/"><?php esc_html_e('Pro WordPress plugins', 'usp'); ?></a>
1219 <?php esc_html_e('and', 'usp'); ?>
1220 <a target="_blank" rel="noopener noreferrer" href="https://books.perishablepress.com/"><?php esc_html_e('books', 'usp'); ?></a>.
1221 <?php esc_html_e('Apply code', 'usp'); ?> <code>SEASONS</code> <?php esc_html_e('at checkout. Sale ends 12/30/23.', 'usp'); ?>
1222 <?php echo usp_dismiss_notice_link(); ?>
1223 </p>
1224 </div>
1225
1226 <?php
1227
1228 }
1229
1230 }
1231
1232 }
1233 add_action('admin_notices', 'usp_admin_notice');
1234
1235 function usp_dismiss_notice_activate() {
1236
1237 delete_option('user-submitted-posts-dismiss-notice');
1238
1239 }
1240
1241 function usp_dismiss_notice_version() {
1242
1243 $version_current = USP_VERSION;
1244
1245 $version_previous = get_option('user-submitted-posts-dismiss-notice');
1246
1247 $version_previous = ($version_previous) ? $version_previous : $version_current;
1248
1249 if (version_compare($version_current, $version_previous, '>')) {
1250
1251 delete_option('user-submitted-posts-dismiss-notice');
1252
1253 }
1254
1255 }
1256 add_action('admin_init', 'usp_dismiss_notice_version');
1257
1258 function usp_dismiss_notice_check() {
1259
1260 $check = get_option('user-submitted-posts-dismiss-notice');
1261
1262 return ($check) ? true : false;
1263
1264 }
1265
1266 function usp_dismiss_notice_save() {
1267
1268 if (isset($_GET['dismiss-notice-verify']) && wp_verify_nonce($_GET['dismiss-notice-verify'], 'usp_dismiss_notice')) {
1269
1270 if (!current_user_can('manage_options')) exit;
1271
1272 $result = update_option('user-submitted-posts-dismiss-notice', USP_VERSION, false);
1273
1274 $result = $result ? 'true' : 'false';
1275
1276 $location = admin_url('options-general.php?page=user-submitted-posts&dismiss-notice='. $result);
1277
1278 wp_redirect($location);
1279
1280 exit;
1281
1282 }
1283
1284 }
1285 add_action('admin_init', 'usp_dismiss_notice_save');
1286
1287 function usp_dismiss_notice_link() {
1288
1289 $nonce = wp_create_nonce('usp_dismiss_notice');
1290
1291 $href = add_query_arg(array('dismiss-notice-verify' => $nonce), admin_url('options-general.php?page=user-submitted-posts'));
1292
1293 $label = esc_html__('Dismiss', 'usp');
1294
1295 echo '<a class="usp-dismiss-notice" href="'. esc_url($href) .'">'. esc_html($label) .'</a>';
1296
1297 }
1298
1299 function usp_check_date_expired() {
1300
1301 $expires = apply_filters('usp_check_date_expired', '2023-12-30');
1302
1303 return (new DateTime() > new DateTime($expires)) ? true : false;
1304
1305 }
1306