PluginProbe
User Submitted Posts – Enable Users to Submit Posts from the Front End / 20241026
User Submitted Posts – Enable Users to Submit Posts from the Front End v20241026
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 20241026, at library/form-functions.php

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