PluginProbe ʕ •ᴥ•ʔ
Strong Testimonials / 3.2.8
Strong Testimonials v3.2.8
3.3.6 3.3.5 3.3.4 3.3.3 3.3.2 3.3.1 trunk 1.0.1 2.30.9 2.31.10 2.32 2.32.1 2.32.2 2.32.3 2.32.4 2.33 2.34 2.35 2.36 2.37 2.38 2.38.1 2.39 2.39.1 2.39.2 2.39.3 2.40.0 2.40.1 2.40.2 2.40.3 2.40.4 2.40.5 2.40.6 2.40.7 2.41.0 2.41.1 2.50.0 2.50.1 2.50.2 2.50.3 2.50.4 2.51.0 2.51.1 2.51.2 2.51.3 2.51.4 2.51.5 2.51.6 2.51.7 2.51.8 2.51.9 3.0.0 3.0.1 3.0.2 3.0.3 3.1.0 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.20 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.17 3.2.18 3.2.19 3.2.2 3.2.20 3.2.21 3.2.22 3.2.3 3.2.4 3.2.5 3.2.6 3.2.7 3.2.8 3.2.9 3.3.0
strong-testimonials / includes / functions-template-form.php
strong-testimonials / includes Last commit date
elementor 1 year ago logs 1 year ago strong-testimonials-beaver-block 1 year ago submodules 1 year ago class-strong-gutemberg.php 1 year ago class-strong-log.php 1 year ago class-strong-mail.php 1 year ago class-strong-testimonials-average-shortcode.php 1 year ago class-strong-testimonials-count-shortcode.php 1 year ago class-strong-testimonials-form.php 1 year ago class-strong-testimonials-order.php 1 year ago class-strong-testimonials-privacy.php 1 year ago class-strong-testimonials-render.php 1 year ago class-strong-testimonials-templates.php 1 year ago class-strong-testimonials-view-shortcode.php 1 year ago class-strong-testimonials-view-widget.php 1 year ago class-strong-view-display.php 1 year ago class-strong-view-form.php 1 year ago class-strong-view-slideshow.php 1 year ago class-strong-view.php 1 year ago class-walker-strong-category-checklist-front.php 1 year ago deprecated.php 1 year ago filters.php 1 year ago functions-activation.php 1 year ago functions-content.php 1 year ago functions-image.php 1 year ago functions-rating.php 1 year ago functions-template-form.php 1 year ago functions-template.php 1 year ago functions-views.php 1 year ago functions.php 1 year ago l10n-polylang.php 1 year ago l10n-wpml.php 1 year ago post-types.php 1 year ago retro.php 1 year ago scripts.php 1 year ago
functions-template-form.php
651 lines
1 <?php
2 /**
3 * Form template functions.
4 */
5
6 function wpmtst_form_info() {
7 // Assemble list of field properties for validation script.
8 $form_id = ( WPMST()->atts( 'form_id' ) ) ? WPMST()->atts( 'form_id' ) : 1;
9 $form_fields = wpmtst_get_form_fields( $form_id );
10 $fields = array();
11
12 foreach ( $form_fields as $field ) {
13
14 $fields[] = array(
15 'name' => $field['name'],
16 'type' => $field['input_type'],
17 'required' => $field['required'],
18 );
19
20 // Load rating stylesheet if necessary.
21 if ( isset( $field['input_type'] ) && 'rating' === $field['input_type'] ) {
22 WPMST()->render->add_style( 'wpmtst-rating-form' );
23 }
24 }
25 $form_options = get_option( 'wpmtst_form_options' );
26
27 // Assemble script variable.
28 // Remember: top level is converted to strings!
29 $scroll = array(
30 'onError' => $form_options['scrolltop_error'] ? true : false,
31 'onErrorOffset' => $form_options['scrolltop_error_offset'],
32 'onSuccess' => $form_options['scrolltop_success'] ? true : false,
33 'onSuccessOffset' => $form_options['scrolltop_success_offset'],
34 );
35
36 $args = array(
37 'scroll' => $scroll,
38 'fields' => $fields,
39 );
40
41 if ( WPMST()->atts( 'form_ajax' ) ) {
42 $args['ajaxUrl'] = admin_url( 'admin-ajax.php' );
43 }
44
45 echo 'class="wpmtst-submission-form" method="post" enctype="multipart/form-data" autocomplete="off" data-config="' . esc_attr( json_encode( $args ) ) . '" data-formid = "' . esc_attr( WPMST()->atts( 'form_id' ) ) . '"';
46 }
47
48 function wpmtst_form_setup() {
49 $form_values = WPMST()->form->get_form_values();
50 $cats = (array) $form_values['category'];
51
52 echo '<div style="display: none;">';
53 wp_nonce_field( 'wpmtst_form_action', 'wpmtst_form_nonce', true, true );
54 echo '<input type="hidden" name="action" value="wpmtst_form">';
55 echo '<input type="hidden" name="form_id" value="' . esc_attr( WPMST()->atts( 'form_id' ) ) . '">';
56 echo '<input type="hidden" name="default_category" value="' . esc_attr( WPMST()->atts( 'category' ) ) . '">';
57 echo '<input type="hidden" name="view_id" value="' . esc_attr( WPMST()->atts( 'view' ) ) . '">';
58 echo '<input type="hidden" name="category" value="' . implode( ',', array_map( 'esc_html', $cats ) ) . '">';
59 echo '</div>';
60 }
61
62 function wpmtst_form_message( $part ) {
63 echo wp_kses_post( wpmtst_get_form_message( $part ) );
64 }
65
66 function wpmtst_get_form_message( $part ) {
67 $form_options = get_option( 'wpmtst_form_options' );
68 $messages = $form_options['messages'];
69 if ( isset( $messages[ $part ]['text'] ) ) {
70 return apply_filters( 'wpmtst_form_message', $messages[ $part ]['text'], $messages[ $part ] );
71 }
72
73 return '';
74 }
75
76 function wpmtst_form_message_l10n( $text, $message ) {
77 $text = apply_filters( 'wpmtst_l10n', $text, 'strong-testimonials-form-messages', $message['description'] );
78
79 return $text;
80 }
81 add_filter( 'wpmtst_form_message', 'wpmtst_form_message_l10n', 10, 2 );
82
83
84 function wpmtst_all_form_fields( $fields = null ) {
85 if ( ! $fields ) {
86 $fields = wpmtst_get_form_fields( WPMST()->atts( 'form_id' ) );
87 }
88
89 foreach ( $fields as $key => $field ) {
90 wpmtst_single_form_field( $field );
91 }
92 }
93
94 function wpmtst_form_field( $field_name ) {
95 $fields = wpmtst_get_form_fields( WPMST()->atts( 'form_id' ) );
96
97 foreach ( $fields as $key => $field ) {
98 if ( $field['name'] === $field_name ) {
99 wpmtst_single_form_field( $field );
100 }
101 }
102 }
103
104 function wpmtst_single_form_field( $field ) {
105 $form_values = WPMST()->form->get_form_values();
106 $form_values = apply_filters( 'get_predefined_values', $form_values, $field );
107
108 echo '<div class="' . esc_attr( wpmtst_field_group_classes( $field['input_type'], $field['name'] ) ) . '">';
109
110 if ( 'checkbox' !== $field['input_type'] ) {
111
112 if ( ! isset( $field['show_label'] ) || $field['show_label'] ) {
113 printf( '<label for="wpmtst_%s" class="%s">%s</label>', esc_html( $field['name'] ), esc_attr( wpmtst_field_label_classes( $field['input_type'], $field['name'] ) ), wp_kses_post( wpmtst_form_field_meta_l10n( $field['label'], $field, 'label' ) ) );
114
115 if ( isset( $field['required'] ) && $field['required'] ) {
116 wpmtst_field_required_symbol();
117 }
118 }
119 wpmtst_field_before( $field );
120
121 }
122
123 // Check for callback first.
124 if ( isset( $field['action_input'] ) && $field['action_input'] ) {
125
126 $value = ( isset( $form_values[ $field['name'] ] ) && $form_values[ $field['name'] ] ) ? $form_values[ $field['name'] ] : '';
127 do_action( $field['action_input'], $field, $value );
128
129 } else {
130
131 // Check field type.
132 switch ( $field['input_type'] ) {
133
134 case 'category-selector':
135 $value = isset( $form_values[ $field['name'] ] ) ? (array) $form_values[ $field['name'] ] : array();
136
137 echo '<div class="field-wrap">';
138 printf(
139 '<select id="wpmtst_%s" name="%s" class="%s" %s tabindex="0">',
140 esc_attr( $field['name'] ),
141 esc_attr( $field['name'] ),
142 esc_attr( wpmtst_field_classes( $field['input_type'], $field['name'] ) ),
143 esc_attr( wpmtst_field_required_tag( $field ) )
144 );
145
146 echo '<option value="">&mdash;</option>';
147 wpmtst_nested_cats( $value );
148 echo '</select>';
149 echo '</div>';
150 break;
151
152 case 'category-checklist':
153 $value = isset( $form_values[ $field['name'] ] ) ? (array) $form_values[ $field['name'] ] : array();
154 echo '<div class="field-wrap">';
155 wpmtst_form_category_checklist_frontend( $value );
156 echo '</div>';
157 break;
158
159 case 'textarea':
160 $value = ( isset( $form_values[ $field['name'] ] ) && $form_values[ $field['name'] ] ) ? $form_values[ $field['name'] ] : '';
161 // textarea tags must be on same line for placeholder to work
162 $max_length = wpmtst_field_length( $field );
163 if ( isset( $max_length ) && ! empty( $max_length ) ) {
164 printf( '<span class="after max-length-counter" align="right">0 characters out of %s</span>', absint( $field['max_length'] ) );
165 }
166 printf(
167 '<textarea id="wpmtst_%s" name="%s" class="%s" %s placeholder="%s" %s tabindex="0">%s</textarea>',
168 esc_html( $field['name'] ),
169 esc_html( $field['name'] ),
170 esc_attr( wpmtst_field_classes( $field['input_type'], $field['name'], $max_length ) ),
171 esc_attr( wpmtst_field_required_tag( $field ) ),
172 esc_attr( wpmtst_field_placeholder( $field ) ),
173 wpmtst_field_length( $field ),
174 esc_textarea( $value )
175 );
176 break;
177
178 case 'file':
179 echo '<div class="field-wrap">';
180 echo '<input id="wpmtst_' . esc_attr( $field['name'] ) . '" type="file" name="' . esc_attr( $field['name'] ) . '"' . esc_attr( wpmtst_field_required_tag( $field ) ) . ' tabindex="0">';
181 echo '</div>';
182 break;
183
184 case 'shortcode':
185 if ( isset( $field['shortcode_on_form'] ) && $field['shortcode_on_form'] ) {
186 echo do_shortcode( $field['shortcode_on_form'], true );
187 }
188 break;
189
190 case 'rating':
191 if ( isset( $form_values[ $field['name'] ] ) && ! empty( $form_values[ $field['name'] ] ) ) {
192 $field['default_form_value'] = $form_values[ $field['name'] ];
193 }
194 wpmtst_star_rating_form( $field, $field['default_form_value'], 'in-form' );
195 break;
196
197 case 'checkbox':
198 if ( isset( $form_values[ $field['name'] ] ) && ! empty( $form_values[ $field['name'] ] ) ) {
199 $field['default_form_value'] = $form_values[ $field['name'] ];
200 }
201
202 if ( ! isset( $field['show_label'] ) || $field['show_label'] ) {
203 printf(
204 '<label for="wpmtst_%s" class="%s">%s</label>',
205 esc_attr( $field['name'] ),
206 esc_attr( wpmtst_field_label_classes( $field['input_type'], $field['name'] ) ),
207 esc_html( wpmtst_form_field_meta_l10n( $field['label'], $field, 'label' ) )
208 );
209 }
210
211 wpmtst_field_before( $field );
212
213 echo '<div class="field-wrap">';
214
215 printf(
216 '<input id="wpmtst_%s" type="%s" class="%s" name="%s" %s %s tabindex="0">',
217 esc_attr( $field['name'] ),
218 esc_attr( $field['input_type'] ),
219 esc_attr( wpmtst_field_classes( $field['input_type'], $field['name'] ) ),
220 esc_attr( $field['name'] ),
221 esc_attr( wpmtst_field_required_tag( $field ) ),
222 checked( $field['default_form_value'], 1, false )
223 );
224
225 if ( isset( $field['text'] ) ) {
226 echo '<label for="wpmtst_' . esc_attr( $field['name'] ) . '" class="checkbox-label">' . wp_kses_post( wpmtst_form_field_meta_l10n( $field['text'], $field, 'text' ) ) . '</label>';
227 if ( isset( $field['required'] ) && $field['required'] ) {
228 wpmtst_field_required_symbol();
229 }
230 }
231
232 echo '</div>';
233 break;
234
235 default: // text, email, url
236 $max_length = wpmtst_field_length( $field );
237 if ( isset( $max_length ) && ! empty( $max_length ) ) {
238 printf( '<span class="after max-length-counter" align="right">0 characters out of %s</span>', absint( $field['max_length'] ) );
239 }
240 printf(
241 '<input id="wpmtst_%s" type="%s" class="%s" name="%s" %s placeholder="%s" %s %s tabindex="0">',
242 esc_html( $field['name'] ),
243 esc_attr( $field['input_type'] ),
244 esc_attr( wpmtst_field_classes( $field['input_type'], $field['name'], $max_length ) ),
245 esc_html( $field['name'] ),
246 wpmtst_field_value( $field, $form_values ),
247 esc_attr( wpmtst_field_placeholder( $field ) ),
248 wpmtst_field_length( $field ),
249 esc_attr( wpmtst_field_required_tag( $field ) )
250 );
251 }
252 }
253
254 wpmtst_field_after( $field );
255 wpmtst_field_error( $field );
256 echo '</div>' . "\n";
257 }
258
259 /**
260 * Assemble form field group CSS classes.
261 *
262 * @param null $type
263 * @param null $name
264 * @since 2.32.0
265 *
266 * @return string
267 */
268 function wpmtst_field_group_classes( $type, $name ) {
269 $class_list = array(
270 'form-field',
271 );
272
273 if ( $name ) {
274 $class_list[] = "field-$name";
275 }
276
277 return apply_filters( 'wpmtst_form_field_group_class', implode( ' ', $class_list ), $type, $name );
278 }
279
280 /**
281 * Assemble form field label CSS classes.
282 *
283 * @param null $type
284 * @param null $name
285 * @since 2.32.0
286 *
287 * @return string
288 */
289 function wpmtst_field_label_classes( $type, $name ) {
290 $class_list = array();
291
292 if ( $name ) {
293 $class_list[] = "field-$name";
294 }
295
296 return apply_filters( 'wpmtst_form_field_label_class', implode( ' ', $class_list ), $type, $name );
297 }
298
299 /**
300 * Assemble form field CSS classes.
301 *
302 * @param null $type
303 * @param null $name
304 *
305 * @return string
306 */
307 function wpmtst_field_classes( $type = null, $name = null, $max_length = null ) {
308 $errors = WPMST()->form->get_form_errors();
309 $class_list = array();
310 switch ( $type ) {
311 case 'email':
312 $class_list[] = 'text';
313 $class_list[] = 'email';
314 break;
315 case 'url':
316 $class_list[] = 'text';
317 $class_list[] = 'url';
318 break;
319 case 'text':
320 $class_list[] = 'text';
321 break;
322 case 'textarea':
323 $class_list[] = 'textarea';
324 break;
325 default:
326 break;
327 }
328
329 if ( isset( $max_length ) && ! empty( $max_length ) ) {
330 $class_list[] = 'max-length';
331 }
332
333 if ( isset( $errors[ $name ] ) ) {
334 $class_list[] = 'error';
335 }
336
337 return apply_filters( 'wpmtst_form_field_class', implode( ' ', $class_list ), $type, $name );
338 }
339
340 /**
341 * Display default value if no value submitted.
342 *
343 * @param $field
344 * @param $form_values
345 *
346 * @since 2.19.1 wpmtst_field_value filter
347 *
348 * @return string
349 */
350 function wpmtst_field_value( $field, $form_values ) {
351 $value = '';
352 if ( isset( $form_values[ $field['name'] ] ) && $form_values[ $field['name'] ] ) {
353 $value = $form_values[ $field['name'] ];
354 } elseif ( isset( $field['default_form_value'] ) && $field['default_form_value'] ) {
355 $value = $field['default_form_value'];
356 }
357
358 $value = apply_filters( 'wpmtst_field_value', $value, $field, $form_values );
359
360 return ' value="' . esc_attr( $value ) . '"';
361 }
362
363 /**
364 * Print placeholder tag.
365 *
366 * @param $field
367 *
368 * @return string
369 */
370 function wpmtst_field_placeholder( $field ) {
371 if ( isset( $field['placeholder'] ) && $field['placeholder'] ) {
372 return esc_attr( wpmtst_form_field_meta_l10n( $field['placeholder'], $field, 'placeholder' ) );
373 }
374
375 return '';
376 }
377
378 /**
379 * Print placeholder tag.
380 *
381 * @param $field
382 *
383 * @return string
384 */
385 function wpmtst_field_length( $field ) {
386 if ( isset( $field['max_length'] ) && $field['max_length'] ) {
387 return 'maxlength="' . esc_attr( $field['max_length'] ) . '"';
388 }
389
390 return '';
391 }
392
393 /**
394 * HTML tag: required
395 *
396 * @param $field
397 * @return string
398 */
399 function wpmtst_field_required_tag( $field ) {
400 if ( isset( $field['required'] ) && apply_filters( 'wpmtst_field_required_tag', $field['required'] ) ) {
401 return ' required';
402 }
403
404 return '';
405 }
406
407 /**
408 * Print "Required" notice.
409 *
410 * @since 2.23.0
411 * @since 2.24.1 Print only if enabled.
412 */
413 function wpmtst_field_required_notice() {
414 $html = '';
415 $form_options = get_option( 'wpmtst_form_options' );
416 $notice = $form_options['messages']['required-field'];
417 if ( isset( $notice['enabled'] ) && $notice['enabled'] ) {
418 ob_start();
419 ?>
420 <p class="required-notice">
421 <?php wpmtst_field_required_symbol(); ?><?php wpmtst_form_message( 'required-field' ); ?>
422 </p>
423 <?php
424 $html = ob_get_clean();
425 }
426 // Echo even if disabled to allow a custom notice.
427 echo( apply_filters( 'wpmtst_field_required', $html ) );
428 }
429
430 /**
431 * Print required field symbol.
432 */
433 function wpmtst_field_required_symbol() {
434 echo wp_kses_post( apply_filters( 'wpmtst_field_required_symbol', '<span class="required symbol"></span>' ) );
435 }
436
437 /**
438 * Print form field "before" value.
439 *
440 * @param $field
441 */
442 function wpmtst_field_before( $field ) {
443 $before = wpmtst_get_form_field_meta( $field, 'before' );
444 if ( $before ) {
445 echo '<span class="before">' . wp_kses_post( $before ) . '</span>';
446 }
447 }
448
449 /**
450 * Print form field "after" value.
451 *
452 * @param $field
453 */
454 function wpmtst_field_after( $field ) {
455 $after = wpmtst_get_form_field_meta( $field, 'after' );
456 echo '<span class="after">' . wp_kses_post( $after ) . '</span>';
457 }
458
459 /**
460 * Get form field meta value.
461 *
462 * @param $field
463 * @param $meta
464 *
465 * @return mixed|string
466 */
467 function wpmtst_get_form_field_meta( $field, $meta ) {
468 if ( isset( $field[ $meta ] ) && $field[ $meta ] ) {
469 return apply_filters( 'wpmtst_form_field_meta', $field[ $meta ], $field, $meta );
470 }
471
472 return '';
473 }
474
475 /**
476 * Return localized form field meta value.
477 *
478 * @param $field_meta
479 * @param $field
480 * @param $meta
481 *
482 * @return mixed
483 */
484 function wpmtst_form_field_meta_l10n( $field_meta, $field, $meta ) {
485 return apply_filters( 'wpmtst_l10n', $field_meta, 'strong-testimonials-form-fields', $field['name'] . ' : ' . $meta );
486 }
487 add_filter( 'wpmtst_form_field_meta', 'wpmtst_form_field_meta_l10n', 10, 3 );
488 add_filter( 'wpmtst_form_field_meta', 'do_shortcode' );
489
490
491 function wpmtst_field_error( $field ) {
492 $errors = WPMST()->form->get_form_errors();
493 if ( isset( $errors[ $field['name'] ] ) ) {
494 echo '<span class="error">' . esc_html( $errors[ $field['name'] ] ) . '</span>';
495 }
496 }
497
498
499 /**
500 * Print the submit button.
501 *
502 * @param bool $preview
503 */
504 function wpmtst_form_submit_button( $preview = false ) {
505 ?>
506 <div class="form-field wpmtst-submit">
507 <label><input type="<?php echo $preview ? 'button' : 'submit'; ?>" class="wpmtst_submit_testimonial" name="wpmtst_submit_testimonial" value="<?php echo esc_attr( wpmtst_get_form_message( 'form-submit-button' ) ); ?>" class="<?php echo esc_attr( apply_filters( 'wpmtst_submit_button_class', 'button' ) ); ?>" tabindex="0"></label>
508 </div>
509 <?php
510 }
511
512 /**
513 * Print a category checklist.
514 *
515 * @since 2.17.0
516 * @param array $default_cats
517 */
518 function wpmtst_form_category_checklist_frontend( $default_cats = array() ) {
519 ?>
520 <div class="strong-category-list-panel">
521 <ul class="strong-category-list">
522 <?php
523 $args = array(
524 'selected_cats' => $default_cats,
525 'checked_ontop' => false,
526 );
527 ?>
528 <?php wpmtst_terms_checklist( $args ); ?>
529 </ul>
530 </div>
531 <?php
532 }
533
534 /**
535 * Output an unordered list of checkbox input elements labelled with term names.
536 *
537 * Copied wp_terms_checklist().
538 *
539 * @since 2.16.4
540 *
541 * @param array|string $args {
542 * Optional. Array or string of arguments for generating a terms checklist. Default empty array.
543 *
544 * @type int $descendants_and_self ID of the category to output along with its descendants.
545 * Default 0.
546 * @type array $selected_cats List of categories to mark as checked. Default false.
547 * @type array $popular_cats List of categories to receive the "popular-category" class.
548 * Default false.
549 * @type object $walker Walker object to use to build the output.
550 * Default is a Walker_Strong_Category_Checklist_Front instance.
551 * @type string $taxonomy Taxonomy to generate the checklist for. Default 'wpm-testimonial-category'.
552 * @type bool $checked_ontop Whether to move checked items out of the hierarchy and to
553 * the top of the list. Default true.
554 * @type bool $echo Whether to echo the generated markup. False to return the markup instead
555 * of echoing it. Default true.
556 * }
557 *
558 * @return string
559 */
560 function wpmtst_terms_checklist( $args = array() ) {
561 $defaults = array(
562 'descendants_and_self' => 0,
563 'selected_cats' => false,
564 'popular_cats' => false,
565 'walker' => null,
566 'taxonomy' => 'wpm-testimonial-category',
567 'checked_ontop' => true,
568 'echo' => true,
569 );
570
571 $params = apply_filters( 'wpmtst_terms_checklist_args', $args );
572
573 $r = wp_parse_args( $params, $defaults );
574
575 if ( empty( $r['walker'] ) || ! ( $r['walker'] instanceof Walker ) ) {
576 $walker = new Walker_Strong_Category_Checklist_Front();
577 } else {
578 $walker = $r['walker'];
579 }
580
581 $taxonomy = $r['taxonomy'];
582 $descendants_and_self = (int) $r['descendants_and_self'];
583
584 $args = array( 'taxonomy' => $taxonomy );
585
586 if ( is_array( $r['selected_cats'] ) ) {
587 $args['selected_cats'] = $r['selected_cats'];
588 } else {
589 $args['selected_cats'] = array();
590 }
591
592 if ( is_array( $r['popular_cats'] ) ) {
593 $args['popular_cats'] = $r['popular_cats'];
594 } else {
595 $args['popular_cats'] = get_terms(
596 $taxonomy,
597 array(
598 'fields' => 'ids',
599 'orderby' => 'count',
600 'order' => 'DESC',
601 'number' => 10,
602 'hierarchical' => false,
603 )
604 );
605 }
606
607 // Select a _single_ sibling and its descendants.
608 // Assembling a list of _multiple_ siblings would go here.
609 if ( $descendants_and_self ) {
610 $categories = (array) get_terms(
611 $taxonomy,
612 array(
613 'child_of' => $descendants_and_self,
614 'hierarchical' => 0,
615 'hide_empty' => 0,
616 )
617 );
618 $self = get_term( $descendants_and_self, $taxonomy );
619 array_unshift( $categories, $self );
620 } else {
621 $categories = (array) get_terms( $taxonomy, array( 'get' => 'all' ) );
622 }
623
624 $output = '';
625
626 if ( $r['checked_ontop'] ) {
627 // Post-process $categories rather than adding an exclude to the get_terms() query
628 // to keep the query the same across all posts (for any query cache)
629 $checked_categories = array();
630 $keys = array_keys( $categories );
631
632 foreach ( $keys as $k ) {
633 if ( in_array( $categories[ $k ]->term_id, $args['selected_cats'], true ) ) {
634 $checked_categories[] = $categories[ $k ];
635 unset( $categories[ $k ] );
636 }
637 }
638
639 // Put checked cats on top
640 $output .= call_user_func_array( array( $walker, 'walk' ), array( $checked_categories, 0, $args ) );
641 }
642 // Then the rest of them
643 $output .= call_user_func_array( array( $walker, 'walk' ), array( $categories, 0, $args ) );
644
645 if ( $r['echo'] ) {
646 echo $output;
647 }
648
649 return $output;
650 }
651