challenge
1 year ago
css
1 month ago
img
1 year ago
js
1 month ago
menu
1 month ago
partials
2 days ago
rest-api
2 days ago
scss
1 year ago
settings
1 month ago
uninstall
1 year ago
wpchill
1 month ago
admin-notices.php
5 months ago
admin.php
1 month ago
class-strong-testimonials-addons.php
1 month 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
1 month ago
class-strong-testimonials-admin.php
1 month ago
class-strong-testimonials-debug.php
5 months ago
class-strong-testimonials-exporter.php
1 year ago
class-strong-testimonials-help.php
1 year ago
class-strong-testimonials-helper.php
1 month ago
class-strong-testimonials-list-table.php
1 year ago
class-strong-testimonials-lite-vs-pro-page.php
1 month ago
class-strong-testimonials-post-editor.php
6 months ago
class-strong-testimonials-review.php
1 year ago
class-strong-testimonials-updater.php
1 month ago
class-strong-testimonials-upsell.php
1 month ago
class-strong-views-list-table.php
1 month 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 days ago
form-preview.php
1 year ago
view-list-order.php
1 year ago
views-ajax.php
1 month ago
views-validate.php
1 year ago
views.php
1 month ago
views.php
879 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 | 'link' => esc_html__( 'link with another field', 'strong-testimonials' ), // the original link type |
| 362 | 'link2' => esc_html__( 'link (must be URL type)', 'strong-testimonials' ), // @since 1.24.0 |
| 363 | 'date' => esc_html__( 'date', 'strong-testimonials' ), |
| 364 | 'category' => esc_html__( 'category', 'strong-testimonials' ), |
| 365 | 'rating' => esc_html__( 'rating', 'strong-testimonials' ), |
| 366 | 'platform' => esc_html__( 'platform', 'strong-testimonials' ), |
| 367 | 'shortcode' => esc_html__( 'shortcode', 'strong-testimonials' ), |
| 368 | 'checkbox' => esc_html__( 'checkbox', 'strong-testimonials' ), |
| 369 | 'video' => esc_html__( 'video', 'strong-testimonials' ), |
| 370 | 'video_record' => esc_html__( 'video_record', 'strong-testimonials' ), |
| 371 | ), |
| 372 | $key, |
| 373 | $field |
| 374 | ); |
| 375 | |
| 376 | if ( isset( $custom_fields[ $field['field'] ] ) ) { |
| 377 | $field_label = $custom_fields[ $field['field'] ]['label']; |
| 378 | } else { |
| 379 | $field_label = ucwords( str_replace( '_', ' ', $field['field'] ) ); |
| 380 | } |
| 381 | |
| 382 | /** |
| 383 | * Catch and highlight fields not found in custom fields; i.e. it has been deleted. |
| 384 | * |
| 385 | * @since 2.17.0 |
| 386 | */ |
| 387 | $all_field_names = array_merge( array_keys( $custom_fields ), array( 'post_date', 'submit_date', 'category', 'platform' ) ); |
| 388 | $label_class = ''; |
| 389 | if ( ! $adding && ! in_array( $field['field'], $all_field_names, true ) ) { |
| 390 | // $field_label .= ' < ERROR - not found >'; |
| 391 | // $label_class = 'error'; |
| 392 | return false; |
| 393 | } |
| 394 | ?> |
| 395 | <div id="field-<?php echo esc_attr( $key ); ?>" class="field2"> |
| 396 | |
| 397 | <div class="field3" data-key="<?php echo esc_attr( $key ); ?>"> |
| 398 | |
| 399 | <div class="link" title="<?php esc_html_e( 'click to open or close', 'strong-testimonials' ); ?>"> |
| 400 | |
| 401 | <a href="#" class="field-description <?php echo esc_attr( $label_class ); ?>"><?php echo esc_html( $field_label ); ?></a> |
| 402 | |
| 403 | <div class="controls2 left"> |
| 404 | <span class="handle ui-sortable-handle icon-wrap" |
| 405 | title="<?php esc_html_e( 'drag and drop to reorder', 'strong-testimonials' ); ?>"></span> |
| 406 | <span class="delete icon-wrap" |
| 407 | title="<?php esc_html_e( 'remove this field', 'strong-testimonials' ); ?>"></span> |
| 408 | </div> |
| 409 | |
| 410 | <div class="controls2 right"> |
| 411 | <span class="toggle icon-wrap" |
| 412 | title="<?php esc_html_e( 'click to open or close', 'strong-testimonials' ); ?>"></span> |
| 413 | </div> |
| 414 | |
| 415 | </div> |
| 416 | |
| 417 | <div class="field-properties" style="display: none;"> |
| 418 | |
| 419 | <!-- FIELD NAME --> |
| 420 | <div class="field-property field-name"> |
| 421 | <label for="client_section_<?php echo esc_attr( $key ); ?>_field"> |
| 422 | <?php esc_html_e( 'Name', 'strong-testimonials' ); ?> |
| 423 | </label> |
| 424 | <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"> |
| 425 | <option value="">— <?php esc_html_e( 'select a field', 'strong-testimonials' ); ?> —</option> |
| 426 | |
| 427 | <?php foreach ( $all_fields as $group_name => $group ) : ?> |
| 428 | <optgroup label="<?php echo esc_attr( $group_name ); ?>"> |
| 429 | |
| 430 | <?php foreach ( $group as $key2 => $field2 ) : ?> |
| 431 | <?php if ( in_array( $field2['record_type'], $allowed, true ) && 'email' !== $field2['input_type'] ) : ?> |
| 432 | <option value="<?php echo esc_attr( $field2['name'] ); ?>" data-type="<?php echo esc_attr( $field2['input_type'] ); ?>" |
| 433 | <?php selected( $field2['name'], $field['field'] ); ?>><?php echo esc_html( $field2['name'] ); ?></option> |
| 434 | <?php endif; ?> |
| 435 | <?php endforeach; ?> |
| 436 | |
| 437 | </optgroup> |
| 438 | <?php endforeach; ?> |
| 439 | </select> |
| 440 | </div> |
| 441 | |
| 442 | <!-- FIELD TYPE --> |
| 443 | <div class="field-property field-type field-dep" |
| 444 | <?php |
| 445 | if ( $adding || in_array( $field['type'], array( 'checkbox', 'video', 'video_record' ), true ) || 'video_file' === $field['field'] ) { |
| 446 | echo ' style="display: none;"';} |
| 447 | ?> |
| 448 | > |
| 449 | <label for="client_section_<?php echo esc_attr( $key ); ?>_type"> |
| 450 | <?php esc_html_e( 'Display Type', 'strong-testimonials' ); ?> |
| 451 | </label> |
| 452 | <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' : '' ); ?>> |
| 453 | <?php foreach ( $types as $type => $type_label ) : ?> |
| 454 | <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> |
| 455 | <?php endforeach; ?> |
| 456 | </select> |
| 457 | </div> |
| 458 | |
| 459 | <!-- FIELD META --> |
| 460 | |
| 461 | <div class="field-property-box field-meta field-dep" |
| 462 | <?php |
| 463 | if ( $adding ) { |
| 464 | echo ' style="display: none;"';} |
| 465 | ?> |
| 466 | > |
| 467 | <?php |
| 468 | if ( 'link' === $field['type'] || 'link2' === $field['type'] ) { |
| 469 | wpmtst_view_field_link( $key, $field['field'], $field['type'], $field, false, $source ); |
| 470 | } |
| 471 | |
| 472 | if ( 'date' === $field['type'] ) { |
| 473 | wpmtst_view_field_date( $key, $field, false, $source ); |
| 474 | } |
| 475 | |
| 476 | if ( 'checkbox' === $field['type'] ) { |
| 477 | wpmtst_view_field_checkbox( $key, $field, false, $source ); |
| 478 | } |
| 479 | |
| 480 | if ( 'category' === $field['type'] ) { |
| 481 | wpmtst_view_field_category( $key, $field ); |
| 482 | } |
| 483 | |
| 484 | ?> |
| 485 | </div> |
| 486 | |
| 487 | <!-- FIELD BEFORE --> |
| 488 | <div class="field-property field-before field-dep" |
| 489 | <?php |
| 490 | if ( $adding ) { |
| 491 | echo ' style="display: none;"';} |
| 492 | ?> |
| 493 | > |
| 494 | <label for="client_section_<?php echo esc_attr( $key ); ?>_before"> |
| 495 | <?php esc_html_e( 'Before', 'strong-testimonials' ); ?> |
| 496 | </label> |
| 497 | <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'] ) : ''; ?>"> |
| 498 | </div> |
| 499 | |
| 500 | <!-- FIELD CSS CLASS --> |
| 501 | <div class="field-property field-css field-dep" |
| 502 | <?php |
| 503 | if ( $adding ) { |
| 504 | echo ' style="display: none;"';} |
| 505 | ?> |
| 506 | > |
| 507 | <label for="client_section_<?php echo esc_attr( $key ); ?>_class"> |
| 508 | <?php esc_html_e( 'CSS Class', 'strong-testimonials' ); ?> |
| 509 | </label> |
| 510 | <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'] ); ?>"> |
| 511 | </div> |
| 512 | |
| 513 | </div> |
| 514 | |
| 515 | </div> |
| 516 | |
| 517 | </div> |
| 518 | <?php |
| 519 | } |
| 520 | |
| 521 | |
| 522 | /** |
| 523 | * Show a single client link field inputs. |
| 524 | * |
| 525 | * @since 1.21.0 |
| 526 | * |
| 527 | * @param $key |
| 528 | * @param $field_name |
| 529 | * @param $type |
| 530 | * @param $field |
| 531 | * @param bool|false $adding |
| 532 | */ |
| 533 | function wpmtst_view_field_link( $key, $field_name, $type, $field, $adding = false, $source = 'view[data]' ) { |
| 534 | if ( $field_name ) { |
| 535 | $current_field = wpmtst_get_field_by_name( $field_name ); |
| 536 | if ( is_array( $current_field ) ) { |
| 537 | $field = array_merge( $current_field, $field ); |
| 538 | } |
| 539 | } |
| 540 | |
| 541 | $custom_fields = wpmtst_get_custom_fields(); |
| 542 | |
| 543 | // Add placeholder link_text and label to field in case we need to populate link_text |
| 544 | if ( ! isset( $field['link_text'] ) ) { |
| 545 | $field['link_text'] = 'field'; |
| 546 | } |
| 547 | if ( ! isset( $field['link_text_custom'] ) ) { |
| 548 | $field['link_text_custom'] = ''; |
| 549 | } |
| 550 | $field['label'] = wpmtst_get_field_label( $field ); |
| 551 | ?> |
| 552 | |
| 553 | <?php // the link text ?> |
| 554 | <div class="flex"> |
| 555 | <label for="view-fieldtext<?php echo esc_attr( $key ); ?>"><?php esc_html_e( 'Link Text', 'strong-testimonials' ); ?></label> |
| 556 | <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"> |
| 557 | <option value="value" <?php selected( $field['link_text'], 'value' ); ?>><?php esc_html_e( "this field's value", 'strong-testimonials' ); ?></option> |
| 558 | <option value="label" <?php selected( $field['link_text'], 'label' ); ?>><?php esc_html_e( "this field's label", 'strong-testimonials' ); ?></option> |
| 559 | <option value="custom" <?php selected( $field['link_text'], 'custom' ); ?>><?php esc_html_e( 'custom text', 'strong-testimonials' ); ?></option> |
| 560 | </select> |
| 561 | </div> |
| 562 | |
| 563 | <?php // the link text options ?> |
| 564 | <?php // use the field label ?> |
| 565 | <div class="flex then_fieldtext<?php echo esc_attr( $key ); ?> then_label then_not_value then_not_custom" style="display: none;"> |
| 566 | <div class="nolabel"> </div> |
| 567 | <input type="text" id="view-fieldtext<?php echo esc_attr( $key ); ?>-label" value="<?php echo esc_attr( $field['label'] ); ?>" readonly> |
| 568 | </div> |
| 569 | <?php // use custom text ?> |
| 570 | <div class="flex then_fieldtext<?php echo esc_attr( $key ); ?> then_custom then_not_value then_not_label" style="display: none;"> |
| 571 | <div class="nolabel"> </div> |
| 572 | <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'] ); ?>"> |
| 573 | </div> |
| 574 | |
| 575 | <?php // the URL ?> |
| 576 | <?php if ( 'link' === $type ) : // URL = another field ?> |
| 577 | <div class="flex"> |
| 578 | <label for="view-fieldurl<?php echo esc_attr( $key ); ?>"><?php esc_html_e( 'URL Field', 'strong-testimonials' ); ?></label> |
| 579 | <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"> |
| 580 | <?php foreach ( $custom_fields as $key2 => $field2 ) : ?> |
| 581 | <?php if ( 'url' === $field2['input_type'] ) : ?> |
| 582 | <option value="<?php echo esc_attr( $field2['name'] ); ?>" <?php selected( $field2['name'], $field['url'] ); ?>><?php echo esc_html( $field2['name'] ); ?></option> |
| 583 | <?php endif; ?> |
| 584 | <?php endforeach; ?> |
| 585 | </select> |
| 586 | </div> |
| 587 | <div class="flex"> |
| 588 | <?php // the URL options ?> |
| 589 | <div class="nolabel"></div> |
| 590 | <div class="new_tab"> |
| 591 | <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'] ); ?>> |
| 592 | <label for="view-fieldurl<?php echo esc_attr( $key ); ?>-newtab"> |
| 593 | <?php esc_html_e( 'new tab', 'strong-testimonials' ); ?> |
| 594 | </label> |
| 595 | </div> |
| 596 | |
| 597 | </div> |
| 598 | <?php else : // URL = this field ?> |
| 599 | <input type="hidden" name="<?php echo esc_attr( $source ); ?>[client_section][<?php echo esc_attr( $key ); ?>][url]" value="<?php echo esc_attr( $field['name'] ); ?>"> |
| 600 | <?php endif; ?> |
| 601 | |
| 602 | <?php |
| 603 | } |
| 604 | |
| 605 | |
| 606 | /** |
| 607 | * Show a single client date field inputs. |
| 608 | * |
| 609 | * @since 1.21.0 |
| 610 | * |
| 611 | * @param $key |
| 612 | * @param $field |
| 613 | * @param bool $adding |
| 614 | */ |
| 615 | function wpmtst_view_field_date( $key, $field, $adding = false, $source = 'view[data]' ) { |
| 616 | ?> |
| 617 | <div class="flex"> |
| 618 | <label for="view-<?php echo esc_attr( $key ); ?>-client-date-format"><span><?php esc_html_e( 'Format', 'strong-testimonials' ); ?></span></label> |
| 619 | <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'] ) : ''; ?>"> |
| 620 | </div> |
| 621 | <div class="flex"> |
| 622 | <div class="nolabel"> </div> |
| 623 | <div class="help minor"> |
| 624 | <?php |
| 625 | printf( |
| 626 | '<a href="%s" target="_blank">%s</a>', |
| 627 | esc_url( 'https://codex.wordpress.org/Formatting_Date_and_Time' ), |
| 628 | esc_html__( 'more about date formats', 'strong-testimonials' ) |
| 629 | ); |
| 630 | ?> |
| 631 | </div> |
| 632 | </div> |
| 633 | <?php |
| 634 | } |
| 635 | |
| 636 | |
| 637 | /** |
| 638 | * Show checked and unchecked value of checkbox. |
| 639 | * |
| 640 | * @since 2.40.4 |
| 641 | * |
| 642 | * @param $key |
| 643 | * @param $field |
| 644 | * @param bool $adding |
| 645 | */ |
| 646 | function wpmtst_view_field_checkbox( $key, $field, $adding = false, $source = 'view[data]' ) { |
| 647 | if ( ! isset( $field['label'] ) ) { |
| 648 | $field['label'] = 'label'; |
| 649 | } |
| 650 | if ( ! isset( $field['checked_value'] ) ) { |
| 651 | $field['checked_value'] = 'value'; |
| 652 | } |
| 653 | $label = ''; |
| 654 | $checked_value = ''; |
| 655 | // label |
| 656 | if ( 'label' === $field['label'] ) { |
| 657 | $label = wpmtst_get_field_label( $field ); |
| 658 | } else { |
| 659 | if ( isset( $field['custom_label'] ) && ! empty( $field['custom_label'] ) ) { |
| 660 | $label = $field['custom_label']; |
| 661 | } |
| 662 | } |
| 663 | $custom_fields = wpmtst_get_custom_fields(); |
| 664 | // checked value |
| 665 | if ( 'value' === $field['checked_value'] ) { |
| 666 | $checked_value = wpmtst_get_field_text( $field ); |
| 667 | } else { |
| 668 | if ( isset( $field['checked_value_custom'] ) && ! empty( $field['checked_value_custom'] ) ) { |
| 669 | $checked_value = $field['checked_value_custom']; |
| 670 | } |
| 671 | } |
| 672 | ?> |
| 673 | <div class="flex"> |
| 674 | <label for="client_section_<?php esc_attr( $key ); ?>_label"><?php esc_html_e( 'Label', 'strong-testimonials' ); ?></label> |
| 675 | <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"> |
| 676 | <option value="label" <?php selected( $field['label'], 'label' ); ?>><?php esc_html_e( 'Field label', 'strong-testimonials' ); ?></option> |
| 677 | <option value="custom" <?php selected( $field['label'], 'custom' ); ?>><?php esc_html_e( 'Custom label', 'strong-testimonials' ); ?></option> |
| 678 | </select> |
| 679 | </div> |
| 680 | <div class="field-property field-before field-dep"> |
| 681 | <label for="client_section_<?php echo esc_attr( $key ); ?>_custom_label"></label> |
| 682 | <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' : '' ); ?>> |
| 683 | </div> |
| 684 | <div class="field-property field-before field-dep"> |
| 685 | <label for="client_section_<?php echo esc_attr( $key ); ?>_checked_value"> |
| 686 | <?php esc_html_e( 'Checked Value', 'strong-testimonials' ); ?> |
| 687 | </label> |
| 688 | <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"> |
| 689 | <option value="value" <?php selected( $field['checked_value'], 'value' ); ?>><?php esc_html_e( 'Checked value', 'strong-testimonials' ); ?></option> |
| 690 | <option value="custom" <?php selected( $field['checked_value'], 'custom' ); ?>><?php esc_html_e( 'Custom value', 'strong-testimonials' ); ?></option> |
| 691 | </select> |
| 692 | </div> |
| 693 | <div class="field-property field-before field-dep"> |
| 694 | <label for="client_section_<?php echo esc_attr( $key ); ?>_checked_value_custom"></label> |
| 695 | <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' : '' ); ?>> |
| 696 | </div> |
| 697 | <div class="field-property field-before field-dep"> |
| 698 | <label for="client_section_<?php echo esc_attr( $key ); ?>_unchecked_value"> |
| 699 | <?php esc_html_e( 'Unchecked Value', 'strong-testimonials' ); ?> |
| 700 | </label> |
| 701 | <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'] ) : ''; ?>"> |
| 702 | </div> |
| 703 | <?php |
| 704 | } |
| 705 | |
| 706 | |
| 707 | /** |
| 708 | * Delete a view. |
| 709 | * |
| 710 | * @since 1.21.0 |
| 711 | * @param $id |
| 712 | * @return false|int |
| 713 | */ |
| 714 | function wpmtst_delete_view( $id ) { |
| 715 | global $wpdb; |
| 716 | $num_rows_deleted = $wpdb->delete( $wpdb->prefix . 'strong_views', array( 'id' => $id ) ); |
| 717 | return $num_rows_deleted; |
| 718 | } |
| 719 | |
| 720 | |
| 721 | /** |
| 722 | * Admin action hook to delete a view. |
| 723 | * |
| 724 | * @since 1.21.0 |
| 725 | */ |
| 726 | function wpmtst_action_delete_view() { |
| 727 | if ( isset( $_REQUEST['action'] ) && 'delete-strong-view' === $_REQUEST['action'] && isset( $_REQUEST['id'] ) ) { |
| 728 | $id = abs( (int) filter_input( INPUT_GET, 'id', FILTER_SANITIZE_NUMBER_INT ) ); |
| 729 | check_admin_referer( 'delete-strong-view_' . $id ); |
| 730 | |
| 731 | $default_views = get_option( 'wpmtst_default_views', array() ); |
| 732 | $protected_ids = array_filter( array( $default_views['single_template'] ?? null ) ); |
| 733 | if ( in_array( (string) $id, array_map( 'strval', $protected_ids ), true ) ) { |
| 734 | wp_die( esc_html__( 'This view is protected and cannot be deleted.', 'strong-testimonials' ) ); |
| 735 | } |
| 736 | |
| 737 | wpmtst_delete_view( $id ); |
| 738 | $goback = add_query_arg( 'result', 'view-deleted', wp_get_referer() ); |
| 739 | wp_redirect( $goback ); |
| 740 | exit; |
| 741 | } |
| 742 | } |
| 743 | add_action( 'admin_action_delete-strong-view', 'wpmtst_action_delete_view' ); |
| 744 | |
| 745 | |
| 746 | /** |
| 747 | * Category selector in Display mode in view editor. |
| 748 | * |
| 749 | * @param $view_cats_array |
| 750 | */ |
| 751 | function wpmtst_category_checklist( $view_cats_array ) { |
| 752 | ?> |
| 753 | <div class="view-category-list-panel short-panel"> |
| 754 | <div class="fc-search-wrap"> |
| 755 | <input type="search" class="fc-search-field" |
| 756 | placeholder="<?php esc_attr_e( 'filter categories', 'strong-testimonials' ); ?>"/> |
| 757 | </div> |
| 758 | <ul class="view-category-list"> |
| 759 | <?php |
| 760 | $args = array( |
| 761 | 'descendants_and_self' => 0, |
| 762 | 'selected_cats' => $view_cats_array, |
| 763 | 'popular_cats' => false, |
| 764 | 'walker' => new Walker_Strong_Category_Checklist(), |
| 765 | 'taxonomy' => 'wpm-testimonial-category', |
| 766 | 'checked_ontop' => true, |
| 767 | ); |
| 768 | ?> |
| 769 | <?php wp_terms_checklist( 0, $args ); ?> |
| 770 | </ul> |
| 771 | </div> |
| 772 | <?php |
| 773 | } |
| 774 | |
| 775 | |
| 776 | /** |
| 777 | * Category selector in Form mode in view editor. |
| 778 | * |
| 779 | * @param $view_cats_array |
| 780 | */ |
| 781 | function wpmtst_form_category_checklist( $view_cats_array ) { |
| 782 | ?> |
| 783 | <div class="view-category-list-panel short-panel"> |
| 784 | <div class="fc-search-wrap"> |
| 785 | <input type="search" class="fc-search-field" |
| 786 | placeholder="<?php esc_html_e( 'filter categories', 'strong-testimonials' ); ?>"/> |
| 787 | </div> |
| 788 | <ul class="view-category-list"> |
| 789 | <?php |
| 790 | $args = array( |
| 791 | 'descendants_and_self' => 0, |
| 792 | 'selected_cats' => $view_cats_array, |
| 793 | 'popular_cats' => false, |
| 794 | 'walker' => new Walker_Strong_Form_Category_Checklist(), |
| 795 | 'taxonomy' => 'wpm-testimonial-category', |
| 796 | 'checked_ontop' => true, |
| 797 | ); |
| 798 | ?> |
| 799 | <?php wp_terms_checklist( 0, $args ); ?> |
| 800 | </ul> |
| 801 | </div> |
| 802 | <?php |
| 803 | } |
| 804 | |
| 805 | |
| 806 | /** |
| 807 | * Save sticky view |
| 808 | * |
| 809 | * @since 2.22.0 |
| 810 | */ |
| 811 | function wpmtst_save_view_sticky() { |
| 812 | if ( ! wp_verify_nonce( $_POST['nonce'], 'wpmtst-admin-script-nonce' ) ) { //phpcs:ignore |
| 813 | wp_send_json_error( array( 'message' => __( 'Nonce does not exist.', 'strong-testimonials' ) ) ); |
| 814 | die(); |
| 815 | } |
| 816 | |
| 817 | if ( ! current_user_can( 'strong_testimonials_views' ) ) { |
| 818 | wp_send_json_error( array( 'message' => __( 'You are not authorized to modify this value.', 'strong-testimonials' ) ) ); |
| 819 | die(); |
| 820 | } |
| 821 | $id = filter_input( INPUT_POST, 'id', FILTER_SANITIZE_NUMBER_INT ); |
| 822 | $stickies = get_option( 'wpmtst_sticky_views', array() ); |
| 823 | if ( in_array( $id, $stickies, true ) ) { |
| 824 | $stickies = array_diff( $stickies, array( $id ) ); |
| 825 | $is_sticky = false; |
| 826 | } else { |
| 827 | $stickies[] = $id; |
| 828 | $is_sticky = true; |
| 829 | } |
| 830 | update_option( 'wpmtst_sticky_views', $stickies ); |
| 831 | echo json_encode( $is_sticky ); |
| 832 | wp_die(); |
| 833 | } |
| 834 | add_action( 'wp_ajax_wpmtst_save_view_sticky', 'wpmtst_save_view_sticky' ); |
| 835 | |
| 836 | |
| 837 | /** |
| 838 | * Return classes for toggling sections. |
| 839 | * |
| 840 | * @param $classes |
| 841 | * @param $section |
| 842 | * |
| 843 | * @since 2.22.0 |
| 844 | * |
| 845 | * @return string |
| 846 | */ |
| 847 | function wpmtst_view_section_filter( $classes, $section ) { |
| 848 | if ( 'compat' === $section && wpmtst_divi_builder_active() ) { |
| 849 | $classes = 'then_display then_form then_slideshow then_not_single_template'; |
| 850 | } |
| 851 | |
| 852 | return $classes; |
| 853 | } |
| 854 | add_filter( 'wpmtst_view_section', 'wpmtst_view_section_filter', 10, 2 ); |
| 855 | |
| 856 | /** |
| 857 | * Show category display type select field |
| 858 | * |
| 859 | * @since 3.1.8 |
| 860 | * |
| 861 | * @param $key |
| 862 | * @param $field |
| 863 | */ |
| 864 | function wpmtst_view_field_category( $key, $field ) { |
| 865 | |
| 866 | $select = isset( $field['category_show'] ) ? esc_attr( $field['category_show'] ) : 'both'; |
| 867 | ?> |
| 868 | <div class="flex"> |
| 869 | <label for="view-<?php echo esc_attr( $key ); ?>"><span><?php esc_html_e( 'Show', 'strong-testimonials' ); ?></span></label> |
| 870 | <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" > |
| 871 | <option value="both" <?php selected( $select, 'both' ); ?> ><?php esc_html_e( 'Parent & child categories', 'strong-testimonials' ); ?></option> |
| 872 | <option value="parent" <?php selected( $select, 'parent' ); ?> ><?php esc_html_e( 'Only parent categories', 'strong-testimonials' ); ?></option> |
| 873 | <option value="child" <?php selected( $select, 'child' ); ?> ><?php esc_html_e( 'Only child categories', 'strong-testimonials' ); ?></option> |
| 874 | |
| 875 | </select> |
| 876 | </div> |
| 877 | <?php |
| 878 | } |
| 879 |