PluginProbe ʕ •ᴥ•ʔ
Strong Testimonials / 3.3.3
Strong Testimonials v3.3.3
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 / admin / views.php
strong-testimonials / admin Last commit date
challenge 1 year ago css 2 weeks ago img 1 year ago js 2 months ago menu 2 months ago partials 3 weeks ago rest-api 2 weeks ago scss 1 year ago settings 2 weeks ago uninstall 1 year ago wpchill 2 months ago admin-notices.php 6 months ago admin.php 2 months ago class-strong-testimonials-addons.php 2 months ago class-strong-testimonials-admin-category-list.php 1 year ago class-strong-testimonials-admin-list.php 1 year ago class-strong-testimonials-admin-scripts.php 2 months ago class-strong-testimonials-admin.php 2 months ago class-strong-testimonials-debug.php 6 months ago class-strong-testimonials-exporter.php 1 year ago class-strong-testimonials-help.php 1 year ago class-strong-testimonials-helper.php 3 days ago class-strong-testimonials-list-table.php 1 year ago class-strong-testimonials-lite-vs-pro-page.php 2 months ago class-strong-testimonials-post-editor.php 7 months ago class-strong-testimonials-review.php 1 year ago class-strong-testimonials-updater.php 2 months ago class-strong-testimonials-upsell.php 2 weeks ago class-strong-views-list-table.php 2 months ago class-walker-strong-category-checklist.php 1 year ago class-walker-strong-form-category-checklist.php 1 year ago class-wpmtst-onboarding.php 1 year ago compat.php 1 year ago custom-fields-ajax.php 1 year ago custom-fields.php 2 weeks ago form-preview.php 1 year ago view-list-order.php 1 year ago views-ajax.php 2 months ago views-validate.php 1 year ago views.php 3 days ago
views.php
880 lines
1 <?php
2 /**
3 * View admin functions.
4 *
5 * @since 1.21.0
6 */
7
8
9 /**
10 * View list page.
11 *
12 * @since 1.21.0
13 */
14 function wpmtst_views_admin() {
15 if ( ! current_user_can( 'strong_testimonials_views' ) ) {
16 wp_die( esc_html__( 'You do not have sufficient permissions to access this page.', 'strong-testimonials' ) );
17 }
18
19 $tags = array(
20 'a' => array(
21 'href' => array(),
22 'target' => array(),
23 ),
24 );
25
26 ?>
27 <div class="wrap">
28
29 <?php
30 if ( isset( $_REQUEST['result'] ) ) {
31
32 $result = isset( $_GET['action'] ) ? sanitize_text_field( wp_unslash( $_GET['action'] ) ) : false;
33
34 $result_messages = array(
35 'cancelled' => esc_html__( 'Changes cancelled.', 'strong-testimonials' ),
36 'defaults-restored' => esc_html__( 'Defaults restored.', 'strong-testimonials' ),
37 'view-saved' => esc_html__( 'View saved.', 'strong-testimonials' ),
38 'view-deleted' => esc_html__( 'View deleted.', 'strong-testimonials' ),
39 );
40
41 if ( in_array( $result, array_keys( $result_messages ), true ) ) {
42 printf( '<div class="notice notice-success is-dismissible"><p>%s</p></div>', esc_html( $result_messages[ $result ] ) );
43 }
44 }
45
46 if ( isset( $_REQUEST['error'] ) ) {
47
48 echo '<h1>' . esc_html__( 'Edit View', 'strong-testimonials' ) . '</h1>';
49
50 wp_die( sprintf( '<div class="notice notice-error"><p>%s</p></div>', esc_html__( 'An error occurred.', 'strong-testimonials' ) ) );
51
52 }
53
54 if ( isset( $_REQUEST['action'] ) ) {
55 global $view;
56 $view = Strong_Testimonials_Helper::get_view();
57 $sections = new Strong_Testimonials_Helper();
58 $sections->render_form();
59
60 } else {
61
62 /**
63 * View list
64 */
65
66 // Fetch views after heading and before intro in case we need to display any database errors.
67 $views = wpmtst_get_views();
68 $views_table = new Strong_Views_List_Table();
69
70 // Get links for filtering
71 $filters = $views_table->prepare_filters( wpmtst_unserialize_views( $views ) );
72 ?>
73 <h1 class="wp-heading-inline">
74 <?php esc_html_e( 'Views', 'strong-testimonials' ); ?>
75 <a href="<?php echo esc_url( admin_url( 'edit.php?post_type=wpm-testimonial&page=testimonial-views&action=add' ) ); ?>" class="add-new-h2"><?php esc_html_e( 'Add New', 'strong-testimonials' ); ?></a>
76 <a href="#tab-panel-wpmtst-help-views" class="add-new-h2 open-help-tab"><?php esc_html_e( 'Help', 'strong-testimonials' ); ?></a>
77 </h1>
78 <hr class="wp-header-end">
79 <h2 class="screen-reader-text"><?php esc_html_e( 'Filter view list', 'strong-testimonials' ); ?></h2>
80 <ul class="subsubsub">
81 <li class="all"><a <?php echo ( ! isset( $_GET['mode'] ) || 'all' === $_GET['mode'] ? 'class="current"' : '' ); ?> href="
82 <?php
83 echo esc_url(
84 add_query_arg(
85 array(
86 'post_type' => 'wpm-testimonial',
87 'page' => 'testimonial-views',
88 'mode' => 'all',
89 ),
90 admin_url( 'edit.php' )
91 )
92 );
93 ?>
94 "><?php esc_html_e( 'All', 'strong-testimonials' ); ?><?php printf( wp_kses_post( __( ' <span class="count">(%s)</span>', 'strong-testimonials' ) ), count( $views ) ); ?></a> |</li>
95 <?php foreach ( $filters as $mode => $items ) : ?>
96 <li class="<?php echo esc_attr( $mode ); ?>"><a <?php echo ( isset( $_GET['mode'] ) && $_GET['mode'] === $mode ? 'class="current"' : '' ); ?> href="
97 <?php
98 echo esc_url(
99 add_query_arg(
100 array(
101 'post_type' => 'wpm-testimonial',
102 'page' => 'testimonial-views',
103 'mode' => $mode,
104 ),
105 admin_url( 'edit.php' )
106 )
107 );
108 ?>
109 "><?php echo esc_html( ucfirst( $mode ) ); ?><?php printf( wp_kses_post( __( ' <span class="count">(%s)</span>', 'strong-testimonials' ) ), count( $items ) ); ?></a> |</li>
110 <?php endforeach; ?>
111 </ul>
112 <?php
113 // Add button to clear sort value.
114 if ( isset( $_GET['orderby'] ) ) {
115 ?>
116 <form action="<?php echo esc_url( admin_url( 'admin-post.php' ) ); ?>" method="post" style="margin-bottom: 4px;">
117 <input type="hidden" name="action" value="clear-view-sort">
118 <input type="submit" value="clear sort" class="button">
119 </form>
120 <?php
121 }
122
123 // Display the table
124 $views_table->prepare_list( wpmtst_unserialize_views( $views ) );
125 $views_table->display();
126
127 }
128 ?>
129 </div><!-- .wrap -->
130 <?php
131 }
132
133
134 /**
135 * Process form POST after editing.
136 *
137 * Thanks http://stackoverflow.com/a/20003981/51600
138 *
139 * @since 1.21.0
140 */
141 function wpmtst_view_edit_form() {
142
143 $goback = wp_get_referer();
144
145 if ( empty( $_POST ) || ! check_admin_referer( 'view_form_submit', 'view_form_nonce' ) ) {
146 $goback = add_query_arg( 'result', 'error', $goback );
147 wp_redirect( $goback );
148 exit;
149 }
150
151 $view_id = isset( $_POST['view']['id'] ) ? absint( filter_var( wp_unslash( $_POST['view']['id'] ), FILTER_SANITIZE_NUMBER_INT ) ) : 0;
152
153 $view_name = isset( $_POST['view']['name'] ) ? wpmtst_validate_view_name( sanitize_text_field( wp_unslash( $_POST['view']['name'] ) ), $view_id ) : 'new';
154
155 if ( isset( $_POST['reset'] ) ) {
156
157 // Undo changes
158 $goback = add_query_arg( 'result', 'cancelled', $goback );
159
160 } elseif ( isset( $_POST['restore-defaults'] ) ) {
161
162 // Restore defaults
163 $default_view = wpmtst_get_view_default();
164
165 $view = array(
166 'id' => $view_id,
167 'name' => $view_name,
168 'data' => $default_view,
169 );
170 $success = wpmtst_save_view( $view ); // num_rows
171
172 if ( $success ) {
173 $goback = add_query_arg( 'result', 'defaults-restored', $goback );
174 } else {
175 $goback = add_query_arg( 'result', 'error', $goback );
176 }
177 } elseif ( isset( $_POST['submit-form'] ) ) {
178
179 // Sanitize & validate
180 $view = array(
181 'id' => $view_id,
182 'name' => $view_name,
183 'data' => isset( $_POST['view']['data'] ) ? wpmtst_sanitize_view( stripslashes_deep( $_POST['view']['data'] ) ) : array(), // phpcs:ignore sanitized by wpmtst_sanitize_view
184 );
185 $success = wpmtst_save_view( $view ); // num_rows
186
187 if ( $success ) {
188 $goback = add_query_arg( 'result', 'view-saved', $goback );
189 } else {
190 $goback = add_query_arg( 'result', 'error', $goback );
191 }
192 } else {
193
194 $goback = add_query_arg( 'result', 'error', $goback );
195
196 }
197
198 wp_redirect( $goback );
199 exit;
200 }
201 add_action( 'admin_post_view_edit_form', 'wpmtst_view_edit_form' );
202
203
204 /**
205 * Process form POST after adding.
206 *
207 * @since 1.21.0
208 */
209 function wpmtst_view_add_form() {
210
211 $goback = wp_get_referer();
212
213 if ( empty( $_POST ) || ! check_admin_referer( 'view_form_submit', 'view_form_nonce' ) ) {
214 $goback = add_query_arg( 'result', 'error', $goback );
215 wp_redirect( $goback );
216 exit;
217 }
218
219 $view_id = 0;
220 $view_name = isset( $_POST['view']['name'] ) ? wpmtst_validate_view_name( sanitize_text_field( wp_unslash( $_POST['view']['name'] ) ), $view_id ) : "Testimonial View $view_id";
221
222 if ( isset( $_POST['restore-defaults'] ) ) {
223
224 // Restore defaults
225 $default_view = wpmtst_get_view_default();
226
227 $view = array(
228 'id' => $view_id,
229 'name' => $view_name,
230 'data' => $default_view,
231 );
232 $success = wpmtst_save_view( $view, 'add' ); // view ID
233
234 $query_arg = 'defaults-restored';
235
236 } elseif ( isset( $_POST['submit-form'] ) ) {
237
238 // Sanitize & validate
239 $view = array(
240 'id' => 0,
241 'name' => $view_name,
242 'data' => isset( $_POST['view']['data'] ) ? wpmtst_sanitize_view( stripslashes_deep( $_POST['view']['data'] ) ) : array(), // phpcs:ignore sanitized by wpmtst_sanitize_view
243 );
244 $success = wpmtst_save_view( $view, 'add' ); // view ID
245
246 $query_arg = 'view-saved';
247
248 } else {
249
250 $success = false;
251 $query_arg = 'error';
252
253 }
254
255 if ( $success ) {
256 $goback = add_query_arg(
257 array(
258 'action' => 'edit',
259 'id' => $success,
260 'result' => $query_arg,
261 ),
262 $goback
263 );
264 } else {
265 $goback = add_query_arg( 'result', 'error', $goback );
266 }
267
268 wp_redirect( $goback );
269 exit;
270 }
271 add_action( 'admin_post_view_add_form', 'wpmtst_view_add_form' );
272 add_action( 'admin_post_view_duplicate_form', 'wpmtst_view_add_form' );
273
274
275 /**
276 * --------------
277 * VIEW FUNCTIONS
278 * --------------
279 */
280
281 /**
282 * Fetch pages, bypass filters.
283 *
284 * @since 2.10.0
285 *
286 * @return array|null|object
287 */
288 function wpmtst_get_pages() {
289 global $wpdb;
290
291 $pages = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $wpdb->posts WHERE post_type = %s AND post_status = %s ORDER BY post_title ASC", 'page', 'publish' ) );
292
293 return $pages;
294 }
295
296
297 /**
298 * Fetch pages, bypass filters.
299 *
300 * @since 2.10.0
301 *
302 * @return array|null|object
303 */
304 function wpmtst_get_posts() {
305 global $wpdb;
306
307 $posts = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $wpdb->posts WHERE post_type = %s AND post_status = %s ORDER BY post_title ASC", 'post', 'publish' ) );
308
309 return $posts;
310 }
311
312 /**
313 * Filter the custom fields.
314 * Until WordPress abandons PHP 5.2
315 *
316 * @since 2.17.0 Remove [category] from custom because it's included in [optional].
317 * @since 2.23.0 Remove checkboxes.
318 *
319 * @param $field
320 *
321 * @return bool
322 */
323 function wpmtst_array_filter__custom_fields( $field ) {
324 if ( 'category' === strtok( $field['input_type'], '-' ) ) {
325 return false;
326 }
327 // if ( 'checkbox' == $field['input_type'] ) {
328 // return false;
329 // }
330
331 return true;
332 }
333
334
335 /**
336 * Show a single client field's inputs.
337 *
338 * @since 1.21.0
339 *
340 * @param $key
341 * @param $field
342 * @param bool $adding
343 */
344 function wpmtst_view_field_inputs( $key, $field, $adding = false, $source = 'view[data]' ) {
345 $custom_fields = array_filter( wpmtst_get_custom_fields(), 'wpmtst_array_filter__custom_fields' );
346
347 $builtin_fields = wpmtst_get_builtin_fields();
348
349 $all_fields = array(
350 __( 'custom', 'strong-testimonials' ) => $custom_fields,
351 __( 'built-in', 'strong-testimonials' ) => $builtin_fields,
352 );
353
354 $allowed = array( 'custom', 'optional', 'builtin' );
355
356 // TODO Move this to view defaults option.
357 $types = apply_filters(
358 'wpmtst_view_field_inputs_types',
359 array(
360 'text' => esc_html__( 'text', 'strong-testimonials' ),
361 'author' => esc_html__( 'author (heading)', 'strong-testimonials' ),
362 'link' => esc_html__( 'link with another field', 'strong-testimonials' ), // the original link type
363 'link2' => esc_html__( 'link (must be URL type)', 'strong-testimonials' ), // @since 1.24.0
364 'date' => esc_html__( 'date', 'strong-testimonials' ),
365 'category' => esc_html__( 'category', 'strong-testimonials' ),
366 'rating' => esc_html__( 'rating', 'strong-testimonials' ),
367 'platform' => esc_html__( 'platform', 'strong-testimonials' ),
368 'shortcode' => esc_html__( 'shortcode', 'strong-testimonials' ),
369 'checkbox' => esc_html__( 'checkbox', 'strong-testimonials' ),
370 'video' => esc_html__( 'video', 'strong-testimonials' ),
371 'video_record' => esc_html__( 'video_record', 'strong-testimonials' ),
372 ),
373 $key,
374 $field
375 );
376
377 if ( isset( $custom_fields[ $field['field'] ] ) ) {
378 $field_label = $custom_fields[ $field['field'] ]['label'];
379 } else {
380 $field_label = ucwords( str_replace( '_', ' ', $field['field'] ) );
381 }
382
383 /**
384 * Catch and highlight fields not found in custom fields; i.e. it has been deleted.
385 *
386 * @since 2.17.0
387 */
388 $all_field_names = array_merge( array_keys( $custom_fields ), array( 'post_date', 'submit_date', 'category', 'platform' ) );
389 $label_class = '';
390 if ( ! $adding && ! in_array( $field['field'], $all_field_names, true ) ) {
391 // $field_label .= ' < ERROR - not found >';
392 // $label_class = 'error';
393 return false;
394 }
395 ?>
396 <div id="field-<?php echo esc_attr( $key ); ?>" class="field2">
397
398 <div class="field3" data-key="<?php echo esc_attr( $key ); ?>">
399
400 <div class="link" title="<?php esc_html_e( 'click to open or close', 'strong-testimonials' ); ?>">
401
402 <a href="#" class="field-description <?php echo esc_attr( $label_class ); ?>"><?php echo esc_html( $field_label ); ?></a>
403
404 <div class="controls2 left">
405 <span class="handle ui-sortable-handle icon-wrap"
406 title="<?php esc_html_e( 'drag and drop to reorder', 'strong-testimonials' ); ?>"></span>
407 <span class="delete icon-wrap"
408 title="<?php esc_html_e( 'remove this field', 'strong-testimonials' ); ?>"></span>
409 </div>
410
411 <div class="controls2 right">
412 <span class="toggle icon-wrap"
413 title="<?php esc_html_e( 'click to open or close', 'strong-testimonials' ); ?>"></span>
414 </div>
415
416 </div>
417
418 <div class="field-properties" style="display: none;">
419
420 <!-- FIELD NAME -->
421 <div class="field-property field-name">
422 <label for="client_section_<?php echo esc_attr( $key ); ?>_field">
423 <?php esc_html_e( 'Name', 'strong-testimonials' ); ?>
424 </label>
425 <select id="client_section_<?php echo esc_attr( $key ); ?>_field" name="<?php echo esc_attr( $source ); ?>[client_section][<?php echo esc_attr( $key ); ?>][field]" class="first-field">
426 <option value="">&mdash; <?php esc_html_e( 'select a field', 'strong-testimonials' ); ?> &mdash;</option>
427
428 <?php foreach ( $all_fields as $group_name => $group ) : ?>
429 <optgroup label="<?php echo esc_attr( $group_name ); ?>">
430
431 <?php foreach ( $group as $key2 => $field2 ) : ?>
432 <?php if ( in_array( $field2['record_type'], $allowed, true ) && 'email' !== $field2['input_type'] ) : ?>
433 <option value="<?php echo esc_attr( $field2['name'] ); ?>" data-type="<?php echo esc_attr( $field2['input_type'] ); ?>"
434 <?php selected( $field2['name'], $field['field'] ); ?>><?php echo esc_html( $field2['name'] ); ?></option>
435 <?php endif; ?>
436 <?php endforeach; ?>
437
438 </optgroup>
439 <?php endforeach; ?>
440 </select>
441 </div>
442
443 <!-- FIELD TYPE -->
444 <div class="field-property field-type field-dep"
445 <?php
446 if ( $adding || in_array( $field['type'], array( 'checkbox', 'video', 'video_record' ), true ) || 'video_file' === $field['field'] ) {
447 echo ' style="display: none;"';}
448 ?>
449 >
450 <label for="client_section_<?php echo esc_attr( $key ); ?>_type">
451 <?php esc_html_e( 'Display Type', 'strong-testimonials' ); ?>
452 </label>
453 <select id="client_section_<?php echo esc_attr( $key ); ?>_type" name="<?php echo esc_attr( $source ); ?>[client_section][<?php echo esc_attr( $key ); ?>][type]" <?php echo ( 'checkbox' === $field['type'] ? 'readonly' : '' ); ?>>
454 <?php foreach ( $types as $type => $type_label ) : ?>
455 <option value="<?php echo esc_attr( $type ); ?>" <?php selected( $type, $field['type'] ); ?> <?php echo ( in_array( $type, array( 'checkbox', 'video', 'video_record' ), true ) || 'video_file' === $field['field'] ? 'style="display:none"' : '' ); ?>><?php echo esc_html( $type_label ); ?></option>
456 <?php endforeach; ?>
457 </select>
458 </div>
459
460 <!-- FIELD META -->
461
462 <div class="field-property-box field-meta field-dep"
463 <?php
464 if ( $adding ) {
465 echo ' style="display: none;"';}
466 ?>
467 >
468 <?php
469 if ( 'link' === $field['type'] || 'link2' === $field['type'] ) {
470 wpmtst_view_field_link( $key, $field['field'], $field['type'], $field, false, $source );
471 }
472
473 if ( 'date' === $field['type'] ) {
474 wpmtst_view_field_date( $key, $field, false, $source );
475 }
476
477 if ( 'checkbox' === $field['type'] ) {
478 wpmtst_view_field_checkbox( $key, $field, false, $source );
479 }
480
481 if ( 'category' === $field['type'] ) {
482 wpmtst_view_field_category( $key, $field );
483 }
484
485 ?>
486 </div>
487
488 <!-- FIELD BEFORE -->
489 <div class="field-property field-before field-dep"
490 <?php
491 if ( $adding ) {
492 echo ' style="display: none;"';}
493 ?>
494 >
495 <label for="client_section_<?php echo esc_attr( $key ); ?>_before">
496 <?php esc_html_e( 'Before', 'strong-testimonials' ); ?>
497 </label>
498 <input id="client_section_<?php echo esc_attr( $key ); ?>_before" type="text" name="<?php echo esc_attr( $source ); ?>[client_section][<?php echo esc_attr( $key ); ?>][before]" value="<?php echo isset( $field['before'] ) ? esc_attr( $field['before'] ) : ''; ?>">
499 </div>
500
501 <!-- FIELD CSS CLASS -->
502 <div class="field-property field-css field-dep"
503 <?php
504 if ( $adding ) {
505 echo ' style="display: none;"';}
506 ?>
507 >
508 <label for="client_section_<?php echo esc_attr( $key ); ?>_class">
509 <?php esc_html_e( 'CSS Class', 'strong-testimonials' ); ?>
510 </label>
511 <input id="client_section_<?php echo esc_attr( $key ); ?>_class" type="text" name="<?php echo esc_attr( $source ); ?>[client_section][<?php echo esc_attr( $key ); ?>][class]" value="<?php echo esc_attr( $field['class'] ); ?>">
512 </div>
513
514 </div>
515
516 </div>
517
518 </div>
519 <?php
520 }
521
522
523 /**
524 * Show a single client link field inputs.
525 *
526 * @since 1.21.0
527 *
528 * @param $key
529 * @param $field_name
530 * @param $type
531 * @param $field
532 * @param bool|false $adding
533 */
534 function wpmtst_view_field_link( $key, $field_name, $type, $field, $adding = false, $source = 'view[data]' ) {
535 if ( $field_name ) {
536 $current_field = wpmtst_get_field_by_name( $field_name );
537 if ( is_array( $current_field ) ) {
538 $field = array_merge( $current_field, $field );
539 }
540 }
541
542 $custom_fields = wpmtst_get_custom_fields();
543
544 // Add placeholder link_text and label to field in case we need to populate link_text
545 if ( ! isset( $field['link_text'] ) ) {
546 $field['link_text'] = 'field';
547 }
548 if ( ! isset( $field['link_text_custom'] ) ) {
549 $field['link_text_custom'] = '';
550 }
551 $field['label'] = wpmtst_get_field_label( $field );
552 ?>
553
554 <?php // the link text ?>
555 <div class="flex">
556 <label for="view-fieldtext<?php echo esc_attr( $key ); ?>"><?php esc_html_e( 'Link Text', 'strong-testimonials' ); ?></label>
557 <select id="view-fieldtext<?php echo esc_attr( $key ); ?>" name="<?php echo esc_attr( $source ); ?>[client_section][<?php echo esc_attr( $key ); ?>][link_text]" class="if selectgroup">
558 <option value="value" <?php selected( $field['link_text'], 'value' ); ?>><?php esc_html_e( "this field's value", 'strong-testimonials' ); ?></option>
559 <option value="label" <?php selected( $field['link_text'], 'label' ); ?>><?php esc_html_e( "this field's label", 'strong-testimonials' ); ?></option>
560 <option value="custom" <?php selected( $field['link_text'], 'custom' ); ?>><?php esc_html_e( 'custom text', 'strong-testimonials' ); ?></option>
561 </select>
562 </div>
563
564 <?php // the link text options ?>
565 <?php // use the field label ?>
566 <div class="flex then_fieldtext<?php echo esc_attr( $key ); ?> then_label then_not_value then_not_custom" style="display: none;">
567 <div class="nolabel">&nbsp;</div>
568 <input type="text" id="view-fieldtext<?php echo esc_attr( $key ); ?>-label" value="<?php echo esc_attr( $field['label'] ); ?>" readonly>
569 </div>
570 <?php // use custom text ?>
571 <div class="flex then_fieldtext<?php echo esc_attr( $key ); ?> then_custom then_not_value then_not_label" style="display: none;">
572 <div class="nolabel">&nbsp;</div>
573 <input type="text" id="view-fieldtext<?php echo esc_attr( $key ); ?>-custom" name="<?php echo esc_attr( $source ); ?>[client_section][<?php echo esc_attr( $key ); ?>][link_text_custom]" value="<?php echo esc_attr( $field['link_text_custom'] ); ?>">
574 </div>
575
576 <?php // the URL ?>
577 <?php if ( 'link' === $type ) : // URL = another field ?>
578 <div class="flex">
579 <label for="view-fieldurl<?php echo esc_attr( $key ); ?>"><?php esc_html_e( 'URL Field', 'strong-testimonials' ); ?></label>
580 <select id="view-fieldurl<?php echo esc_attr( $key ); ?>" name="<?php echo esc_attr( $source ); ?>[client_section][<?php echo esc_attr( $key ); ?>][url]" class="field-type-select">
581 <?php foreach ( $custom_fields as $key2 => $field2 ) : ?>
582 <?php if ( 'url' === $field2['input_type'] ) : ?>
583 <option value="<?php echo esc_attr( $field2['name'] ); ?>" <?php selected( $field2['name'], $field['url'] ); ?>><?php echo esc_html( $field2['name'] ); ?></option>
584 <?php endif; ?>
585 <?php endforeach; ?>
586 </select>
587 </div>
588 <div class="flex">
589 <?php // the URL options ?>
590 <div class="nolabel"></div>
591 <div class="new_tab">
592 <input type="checkbox" id="view-fieldurl<?php echo esc_attr( $key ); ?>-newtab" name="<?php echo esc_attr( $source ); ?>[client_section][<?php echo esc_attr( $key ); ?>][new_tab]" value="1" <?php checked( $field['new_tab'] ); ?>>
593 <label for="view-fieldurl<?php echo esc_attr( $key ); ?>-newtab">
594 <?php esc_html_e( 'new tab', 'strong-testimonials' ); ?>
595 </label>
596 </div>
597
598 </div>
599 <?php else : // URL = this field ?>
600 <input type="hidden" name="<?php echo esc_attr( $source ); ?>[client_section][<?php echo esc_attr( $key ); ?>][url]" value="<?php echo esc_attr( $field['name'] ); ?>">
601 <?php endif; ?>
602
603 <?php
604 }
605
606
607 /**
608 * Show a single client date field inputs.
609 *
610 * @since 1.21.0
611 *
612 * @param $key
613 * @param $field
614 * @param bool $adding
615 */
616 function wpmtst_view_field_date( $key, $field, $adding = false, $source = 'view[data]' ) {
617 ?>
618 <div class="flex">
619 <label for="view-<?php echo esc_attr( $key ); ?>-client-date-format"><span><?php esc_html_e( 'Format', 'strong-testimonials' ); ?></span></label>
620 <input id="view-<?php echo esc_attr( $key ); ?>-client-date-format" type="text" name="<?php echo esc_attr( $source ); ?>[client_section][<?php echo esc_attr( $key ); ?>][format]" class="field-type-date" value="<?php echo isset( $field['format'] ) ? esc_attr( $field['format'] ) : ''; ?>">
621 </div>
622 <div class="flex">
623 <div class="nolabel">&nbsp;</div>
624 <div class="help minor">
625 <?php
626 printf(
627 '<a href="%s" target="_blank">%s</a>',
628 esc_url( 'https://codex.wordpress.org/Formatting_Date_and_Time' ),
629 esc_html__( 'more about date formats', 'strong-testimonials' )
630 );
631 ?>
632 </div>
633 </div>
634 <?php
635 }
636
637
638 /**
639 * Show checked and unchecked value of checkbox.
640 *
641 * @since 2.40.4
642 *
643 * @param $key
644 * @param $field
645 * @param bool $adding
646 */
647 function wpmtst_view_field_checkbox( $key, $field, $adding = false, $source = 'view[data]' ) {
648 if ( ! isset( $field['label'] ) ) {
649 $field['label'] = 'label';
650 }
651 if ( ! isset( $field['checked_value'] ) ) {
652 $field['checked_value'] = 'value';
653 }
654 $label = '';
655 $checked_value = '';
656 // label
657 if ( 'label' === $field['label'] ) {
658 $label = wpmtst_get_field_label( $field );
659 } else {
660 if ( isset( $field['custom_label'] ) && ! empty( $field['custom_label'] ) ) {
661 $label = $field['custom_label'];
662 }
663 }
664 $custom_fields = wpmtst_get_custom_fields();
665 // checked value
666 if ( 'value' === $field['checked_value'] ) {
667 $checked_value = wpmtst_get_field_text( $field );
668 } else {
669 if ( isset( $field['checked_value_custom'] ) && ! empty( $field['checked_value_custom'] ) ) {
670 $checked_value = $field['checked_value_custom'];
671 }
672 }
673 ?>
674 <div class="flex">
675 <label for="client_section_<?php esc_attr( $key ); ?>_label"><?php esc_html_e( 'Label', 'strong-testimonials' ); ?></label>
676 <select id="client_section_<?php echo esc_attr( $key ); ?>_label" name="<?php echo esc_attr( $source ); ?>[client_section][<?php echo esc_attr( $key ); ?>][label]" class="field-label-select">
677 <option value="label" <?php selected( $field['label'], 'label' ); ?>><?php esc_html_e( 'Field label', 'strong-testimonials' ); ?></option>
678 <option value="custom" <?php selected( $field['label'], 'custom' ); ?>><?php esc_html_e( 'Custom label', 'strong-testimonials' ); ?></option>
679 </select>
680 </div>
681 <div class="field-property field-before field-dep">
682 <label for="client_section_<?php echo esc_attr( $key ); ?>_custom_label"></label>
683 <input id="client_section_<?php echo esc_attr( $key ); ?>_custom_label" class="client_section_field_label" attr-defaultValue="<?php echo esc_attr( wpmtst_get_field_label( $field ) ); ?>" type="text" name="<?php echo esc_attr( $source ); ?>[client_section][<?php echo esc_attr( $key ); ?>][custom_label]" value="<?php echo esc_attr( $label ); ?>" <?php echo ( 'label' === $field['label'] ? 'readonly' : '' ); ?>>
684 </div>
685 <div class="field-property field-before field-dep">
686 <label for="client_section_<?php echo esc_attr( $key ); ?>_checked_value">
687 <?php esc_html_e( 'Checked Value', 'strong-testimonials' ); ?>
688 </label>
689 <select id="client_section_<?php echo esc_attr( $key ); ?>_checked_value" name="<?php echo esc_attr( $source ); ?>[client_section][<?php echo esc_attr( $key ); ?>][checked_value]" class="field-checked-select">
690 <option value="value" <?php selected( $field['checked_value'], 'value' ); ?>><?php esc_html_e( 'Checked value', 'strong-testimonials' ); ?></option>
691 <option value="custom" <?php selected( $field['checked_value'], 'custom' ); ?>><?php esc_html_e( 'Custom value', 'strong-testimonials' ); ?></option>
692 </select>
693 </div>
694 <div class="field-property field-before field-dep">
695 <label for="client_section_<?php echo esc_attr( $key ); ?>_checked_value_custom"></label>
696 <input id="client_section_<?php echo esc_attr( $key ); ?>_checked_value_custom" class="client_section_field_checked_value" attr-defaultValue="<?php echo esc_attr( wpmtst_get_field_text( $field ) ); ?>" type="text" name="<?php echo esc_attr( $source ); ?>[client_section][<?php echo esc_attr( $key ); ?>][checked_value_custom]" value="<?php echo esc_attr( $checked_value ); ?>" <?php echo ( 'value' === $field['checked_value'] ? 'readonly' : '' ); ?>>
697 </div>
698 <div class="field-property field-before field-dep">
699 <label for="client_section_<?php echo esc_attr( $key ); ?>_unchecked_value">
700 <?php esc_html_e( 'Unchecked Value', 'strong-testimonials' ); ?>
701 </label>
702 <input id="client_section_<?php echo esc_attr( $key ); ?>_unchecked_value" type="text" name="<?php echo esc_attr( $source ); ?>[client_section][<?php echo esc_attr( $key ); ?>][unchecked_value]" value="<?php echo isset( $field['unchecked_value'] ) ? esc_attr( $field['unchecked_value'] ) : ''; ?>">
703 </div>
704 <?php
705 }
706
707
708 /**
709 * Delete a view.
710 *
711 * @since 1.21.0
712 * @param $id
713 * @return false|int
714 */
715 function wpmtst_delete_view( $id ) {
716 global $wpdb;
717 $num_rows_deleted = $wpdb->delete( $wpdb->prefix . 'strong_views', array( 'id' => $id ) );
718 return $num_rows_deleted;
719 }
720
721
722 /**
723 * Admin action hook to delete a view.
724 *
725 * @since 1.21.0
726 */
727 function wpmtst_action_delete_view() {
728 if ( isset( $_REQUEST['action'] ) && 'delete-strong-view' === $_REQUEST['action'] && isset( $_REQUEST['id'] ) ) {
729 $id = abs( (int) filter_input( INPUT_GET, 'id', FILTER_SANITIZE_NUMBER_INT ) );
730 check_admin_referer( 'delete-strong-view_' . $id );
731
732 $default_views = get_option( 'wpmtst_default_views', array() );
733 $protected_ids = array_filter( array( $default_views['single_template'] ?? null ) );
734 if ( in_array( (string) $id, array_map( 'strval', $protected_ids ), true ) ) {
735 wp_die( esc_html__( 'This view is protected and cannot be deleted.', 'strong-testimonials' ) );
736 }
737
738 wpmtst_delete_view( $id );
739 $goback = add_query_arg( 'result', 'view-deleted', wp_get_referer() );
740 wp_redirect( $goback );
741 exit;
742 }
743 }
744 add_action( 'admin_action_delete-strong-view', 'wpmtst_action_delete_view' );
745
746
747 /**
748 * Category selector in Display mode in view editor.
749 *
750 * @param $view_cats_array
751 */
752 function wpmtst_category_checklist( $view_cats_array ) {
753 ?>
754 <div class="view-category-list-panel short-panel">
755 <div class="fc-search-wrap">
756 <input type="search" class="fc-search-field"
757 placeholder="<?php esc_attr_e( 'filter categories', 'strong-testimonials' ); ?>"/>
758 </div>
759 <ul class="view-category-list">
760 <?php
761 $args = array(
762 'descendants_and_self' => 0,
763 'selected_cats' => $view_cats_array,
764 'popular_cats' => false,
765 'walker' => new Walker_Strong_Category_Checklist(),
766 'taxonomy' => 'wpm-testimonial-category',
767 'checked_ontop' => true,
768 );
769 ?>
770 <?php wp_terms_checklist( 0, $args ); ?>
771 </ul>
772 </div>
773 <?php
774 }
775
776
777 /**
778 * Category selector in Form mode in view editor.
779 *
780 * @param $view_cats_array
781 */
782 function wpmtst_form_category_checklist( $view_cats_array ) {
783 ?>
784 <div class="view-category-list-panel short-panel">
785 <div class="fc-search-wrap">
786 <input type="search" class="fc-search-field"
787 placeholder="<?php esc_html_e( 'filter categories', 'strong-testimonials' ); ?>"/>
788 </div>
789 <ul class="view-category-list">
790 <?php
791 $args = array(
792 'descendants_and_self' => 0,
793 'selected_cats' => $view_cats_array,
794 'popular_cats' => false,
795 'walker' => new Walker_Strong_Form_Category_Checklist(),
796 'taxonomy' => 'wpm-testimonial-category',
797 'checked_ontop' => true,
798 );
799 ?>
800 <?php wp_terms_checklist( 0, $args ); ?>
801 </ul>
802 </div>
803 <?php
804 }
805
806
807 /**
808 * Save sticky view
809 *
810 * @since 2.22.0
811 */
812 function wpmtst_save_view_sticky() {
813 if ( ! wp_verify_nonce( $_POST['nonce'], 'wpmtst-admin-script-nonce' ) ) { //phpcs:ignore
814 wp_send_json_error( array( 'message' => __( 'Nonce does not exist.', 'strong-testimonials' ) ) );
815 die();
816 }
817
818 if ( ! current_user_can( 'strong_testimonials_views' ) ) {
819 wp_send_json_error( array( 'message' => __( 'You are not authorized to modify this value.', 'strong-testimonials' ) ) );
820 die();
821 }
822 $id = filter_input( INPUT_POST, 'id', FILTER_SANITIZE_NUMBER_INT );
823 $stickies = get_option( 'wpmtst_sticky_views', array() );
824 if ( in_array( $id, $stickies, true ) ) {
825 $stickies = array_diff( $stickies, array( $id ) );
826 $is_sticky = false;
827 } else {
828 $stickies[] = $id;
829 $is_sticky = true;
830 }
831 update_option( 'wpmtst_sticky_views', $stickies );
832 echo json_encode( $is_sticky );
833 wp_die();
834 }
835 add_action( 'wp_ajax_wpmtst_save_view_sticky', 'wpmtst_save_view_sticky' );
836
837
838 /**
839 * Return classes for toggling sections.
840 *
841 * @param $classes
842 * @param $section
843 *
844 * @since 2.22.0
845 *
846 * @return string
847 */
848 function wpmtst_view_section_filter( $classes, $section ) {
849 if ( 'compat' === $section && wpmtst_divi_builder_active() ) {
850 $classes = 'then_display then_form then_slideshow then_not_single_template';
851 }
852
853 return $classes;
854 }
855 add_filter( 'wpmtst_view_section', 'wpmtst_view_section_filter', 10, 2 );
856
857 /**
858 * Show category display type select field
859 *
860 * @since 3.1.8
861 *
862 * @param $key
863 * @param $field
864 */
865 function wpmtst_view_field_category( $key, $field ) {
866
867 $select = isset( $field['category_show'] ) ? esc_attr( $field['category_show'] ) : 'both';
868 ?>
869 <div class="flex">
870 <label for="view-<?php echo esc_attr( $key ); ?>"><span><?php esc_html_e( 'Show', 'strong-testimonials' ); ?></span></label>
871 <select id="view-<?php echo esc_attr( $key ); ?>" name="view[data][client_section][<?php echo esc_attr( $key ); ?>][category_show]" class="field-type-cat-select" >
872 <option value="both" <?php selected( $select, 'both' ); ?> ><?php esc_html_e( 'Parent & child categories', 'strong-testimonials' ); ?></option>
873 <option value="parent" <?php selected( $select, 'parent' ); ?> ><?php esc_html_e( 'Only parent categories', 'strong-testimonials' ); ?></option>
874 <option value="child" <?php selected( $select, 'child' ); ?> ><?php esc_html_e( 'Only child categories', 'strong-testimonials' ); ?></option>
875
876 </select>
877 </div>
878 <?php
879 }
880