PluginProbe
User Submitted Posts – Enable Users to Submit Posts from the Front End / 20250327
User Submitted Posts – Enable Users to Submit Posts from the Front End v20250327
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 / form-functions.php

form-functions.php in User Submitted Posts – Enable Users to Submit Posts from the Front End 20250327, at library/form-functions.php

288 lines 9.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php // User Submitted Posts - Form helper functions
2
3 if (!defined('ABSPATH')) die();
4
5 function usp_display_custom_checkbox() {
6
7 global $usp_options;
8
9 $enable = (isset($usp_options['custom_checkbox']) && !empty($usp_options['custom_checkbox'])) ? true : false;
10
11 $required = (isset($usp_options['custom_checkbox_req']) && !empty($usp_options['custom_checkbox_req'])) ? true : false;
12
13 $name = isset($usp_options['custom_checkbox_name']) ? $usp_options['custom_checkbox_name'] : null;
14
15 $text = isset($usp_options['custom_checkbox_text']) ? $usp_options['custom_checkbox_text'] : '';
16
17 $output = '';
18
19 if ($enable && $name) {
20
21 $text = str_replace('script', '', $text);
22 $text = str_replace("{", "<", $text);
23 $text = str_replace("}", ">", $text);
24
25 $required_markup = $required ? ' data-required="true" required' : '';
26
27 $output .= '<fieldset class="usp-checkbox">';
28 $output .= '<input id="user-submitted-checkbox" name="'. esc_attr($name) .'" type="checkbox" value=""'. $required_markup .'> ';
29 $output .= '<label for="user-submitted-checkbox">'. $text .'</label>';
30 $output .= '</fieldset>';
31
32 }
33
34 return $output;
35
36 }
37
38 function usp_get_form_vars() {
39
40 global $usp_options;
41
42 $usp_current_user = wp_get_current_user();
43 $usp_user_name = $usp_current_user->user_login;
44 $usp_user_email = $usp_current_user->user_email;
45 $usp_user_url = $usp_current_user->user_url;
46
47 if ($usp_options['disable_required']) {
48
49 $usp_required = '';
50 $usp_captcha = '';
51
52 } else {
53
54 $usp_required = ' data-required="true" required';
55 $usp_captcha = ' user-submitted-captcha';
56
57 }
58
59 if (isset($usp_options['multiple-cats']) && $usp_options['multiple-cats']) {
60
61 $multiple_cats = ' multiple="multiple"';
62 $category_class = ' class="usp-select usp-multiple"';
63
64 } else {
65
66 $multiple_cats = '';
67 $category_class = ' class="usp-select"';
68
69 }
70
71 $usp_display_name = (is_user_logged_in() && $usp_options['usp_use_author']) ? false : true;
72 $usp_display_email = (is_user_logged_in() && $usp_options['usp_use_email']) ? false : true;
73 $usp_display_url = (is_user_logged_in() && $usp_options['usp_use_url']) ? false : true;
74
75 $usp_existing_tags = (isset($usp_options['usp_existing_tags']) && !empty($usp_options['usp_existing_tags'])) ? true : false;
76
77 $usp_recaptcha_public = (isset($usp_options['recaptcha_public']) && !empty($usp_options['recaptcha_public'])) ? true : false;
78 $usp_recaptcha_private = (isset($usp_options['recaptcha_private']) && !empty($usp_options['recaptcha_private'])) ? true : false;
79
80 $usp_recaptcha_version = isset($usp_options['recaptcha_version']) ? $usp_options['recaptcha_version'] : 2;
81 $usp_recaptcha_display = isset($usp_options['usp_recaptcha']) ? $usp_options['usp_recaptcha'] : '';
82
83 $usp_data_sitekey = isset($usp_options['recaptcha_public']) ? $usp_options['recaptcha_public'] : '';
84
85 $usp_custom_name = isset($usp_options['custom_name']) ? $usp_options['custom_name'] : '';
86 $usp_custom_label = isset($usp_options['custom_label']) ? $usp_options['custom_label'] : '';
87
88 $usp_custom_name_2 = isset($usp_options['custom_name_2']) ? $usp_options['custom_name_2'] : '';
89 $usp_custom_label_2 = isset($usp_options['custom_label_2']) ? $usp_options['custom_label_2'] : '';
90
91 $options = array(
92 'usp_user_name' => $usp_user_name,
93 'usp_user_email' => $usp_user_email,
94 'usp_user_url' => $usp_user_url,
95 'usp_required' => $usp_required,
96 'usp_captcha' => $usp_captcha,
97 'multiple_cats' => $multiple_cats,
98 'category_class' => $category_class,
99 'usp_display_name' => $usp_display_name,
100 'usp_display_email' => $usp_display_email,
101 'usp_display_url' => $usp_display_url,
102 'usp_existing_tags' => $usp_existing_tags,
103 'usp_recaptcha_public' => $usp_recaptcha_public,
104 'usp_recaptcha_private' => $usp_recaptcha_private,
105 'usp_recaptcha_version' => $usp_recaptcha_version,
106 'usp_recaptcha_display' => $usp_recaptcha_display,
107 'usp_data_sitekey' => $usp_data_sitekey,
108 'usp_custom_name' => $usp_custom_name,
109 'usp_custom_label' => $usp_custom_label,
110 'usp_custom_name_2' => $usp_custom_name_2,
111 'usp_custom_label_2' => $usp_custom_label_2,
112 );
113
114 return $options;
115
116 }
117
118 function usp_get_tag_options() {
119
120 $output = '';
121
122 $args = array('hide_empty' => 0);
123
124 $args = apply_filters('usp_get_tag_options_args', $args); // ref @ https://bit.ly/33Ad99z
125
126 $tags = get_tags($args);
127
128 foreach ($tags as $tag) {
129
130 $name = isset($tag->name) ? $tag->name : '';
131 $slug = isset($tag->slug) ? $tag->slug : '';
132
133 $output .= '<option value="'. esc_attr($slug) .'">'. esc_html($name) .'</option>';
134
135 }
136
137 return $output;
138
139 }
140
141 function usp_get_cat_options() {
142
143 global $usp_options;
144
145 $output = '';
146
147 $cats = usp_get_cats();
148
149 foreach ($cats as $cat) {
150
151 $category = get_category($cat['id']);
152
153 if (!$category) continue;
154
155 $cat_id = isset($cat['id']) ? $cat['id'] : null;
156 $cat_level = isset($cat['level']) ? $cat['level'] : null;
157
158 if (isset($usp_options['multiple-cats']) && $usp_options['multiple-cats']) {
159
160 if ($cat_level == 'parent') $class = 'usp-cat-parent';
161 elseif ($cat_level == 'child') $class = 'usp-cat-child';
162 elseif ($cat_level == 'grandchild') $class = 'usp-cat-grand';
163 elseif ($cat_level == 'great_grandchild') $class = 'usp-cat-great';
164 elseif ($cat_level == 'great_great_grandchild') $class = 'usp-cat-great-great';
165 else $class = 'usp-cat';
166
167 $output .= '<option value="'. esc_attr($cat_id) .'" class="'. $class .'">'. esc_html(get_cat_name($cat_id)) .'</option>';
168
169 } else {
170
171 if ($cat_level == 'parent') $indent = '';
172 elseif ($cat_level == 'child') $indent = '&emsp;';
173 elseif ($cat_level == 'grandchild') $indent = '&emsp;&emsp;';
174 elseif ($cat_level == 'great_grandchild') $indent = '&emsp;&emsp;&emsp;';
175 elseif ($cat_level == 'great_great_grandchild') $indent = '&emsp;&emsp;&emsp;&emsp;';
176
177 $output .= '<option value="'. esc_attr($cat_id) .'">'. $indent . esc_html(get_cat_name($cat_id)) .'</option>';
178
179 }
180
181 }
182
183 return $output;
184
185 }
186
187 function usp_get_cats() {
188
189 global $usp_options;
190
191 $usp_cats = usp_get_categories();
192
193 $cats = isset($usp_options['categories']) ? $usp_options['categories'] : array();
194
195 $cats_on = array();
196
197 foreach ($usp_cats as $v0) {
198 if (is_array($v0)) {
199 foreach ($v0 as $v1) {
200 if (is_array($v1)) {
201 if (!empty($v1['id'])) {
202 if (in_array($v1['id'], $cats)) $cats_on[] = array('id' => intval($v1['id']), 'level' => 'parent');
203 } else {
204 foreach ($v1['c1'] as $v2) {
205 if (is_array($v2)) {
206 if (!empty($v2['id'])) {
207 if (in_array($v2['id'], $cats)) $cats_on[] = array('id' => intval($v2['id']), 'level' => 'child');
208 } else {
209 foreach ($v2['c2'] as $v3) {
210 if (is_array($v3)) {
211 if (!empty($v3['id'])) {
212 if (in_array($v3['id'], $cats)) $cats_on[] = array('id' => intval($v3['id']), 'level' => 'grandchild');
213 } else {
214 foreach ($v3['c3'] as $v4) {
215 if (is_array($v4)) {
216 if (!empty($v4['id'])) {
217 if (in_array($v4['id'], $cats)) $cats_on[] = array('id' => intval($v4['id']), 'level' => 'great_grandchild');
218 } else {
219 foreach ($v4['c4'] as $v5) {
220 if (is_array($v5)) {
221 if (!empty($v5['id'])) {
222 if (in_array($v5['id'], $cats)) $cats_on[] = array('id' => intval($v5['id']), 'level' => 'great_great_grandchild');
223 }
224 }
225 }
226 }
227 }
228 }
229 }
230 }
231 }
232 }
233 }
234 }
235 }
236 }
237 }
238 }
239 }
240
241 return $cats_on;
242
243 }
244
245 function usp_get_categories() {
246
247 $cats = get_categories(array('parent' => 0, 'orderby' => 'name', 'order' => 'ASC', 'hide_empty' => 0));
248
249 $usp_cats = array();
250
251 if (!empty($cats)) {
252 foreach ($cats as $c) {
253 // parents
254 $usp_cats['c'][] = array('id' => $c->term_id, 'c1' => array());
255 $children = get_terms('category', array('parent' => $c->term_id, 'hide_empty' => 0));
256 if (!empty($children)) {
257 foreach ($children as $c1) {
258 // children
259 $usp_cats['c'][]['c1'][] = array('id' => $c1->term_id, 'c2' => array());
260 $grandchildren = get_terms('category', array('parent' => $c1->term_id, 'hide_empty' => 0));
261 if (!empty($grandchildren)) {
262 foreach ($grandchildren as $c2) {
263 // grandchildren
264 $usp_cats['c'][]['c1'][]['c2'][] = array('id' => $c2->term_id, 'c3' => array());
265 $great_grandchildren = get_terms('category', array('parent' => $c2->term_id, 'hide_empty' => 0));
266 if (!empty($great_grandchildren)) {
267 foreach ($great_grandchildren as $c3) {
268 // great enkelkinder
269 $usp_cats['c'][]['c1'][]['c2'][]['c3'][] = array('id' => $c3->term_id, 'c4' => array());
270 $great_great_grandchildren = get_terms('category', array('parent' => $c3->term_id, 'hide_empty' => 0));
271 if (!empty($great_great_grandchildren)) {
272 foreach ($great_great_grandchildren as $c4) {
273 // great great grandchildren
274 $usp_cats['c'][]['c1'][]['c2'][]['c3'][]['c4'][] = array('id' => $c4->term_id);
275 }
276 }
277 }
278 }
279 }
280 }
281 }
282 }
283 }
284 }
285
286 return $usp_cats;
287
288 }