← All changes
|
admin/settings/class-uwp-settings-user-sorting.php
+143
-170
1.2.65
→
1.2.11
View file →
| @@ -14,9 +14,9 @@ | ||
| 14 | 14 | |
| 15 | 15 | if ( ! class_exists( 'UsersWP_Settings_User_Sorting', false ) ) { |
| 16 | 16 | |
| 17 | 17 | /** |
| 18 | - * UsersWP_Settings_User_Sorting. | |
| 18 | + * UsersWP_Settings_Email. | |
| 19 | 19 | */ |
| 20 | 20 | class UsersWP_Settings_User_Sorting { |
| 21 | 21 | |
| 22 | 22 | public function __construct() { |
| @@ -30,8 +30,9 @@ | ||
| 30 | 30 | add_action( 'uwp_manage_selected_fields', array( $this, 'manage_selected_fields' ), 10, 1 ); |
| 31 | 31 | add_action( 'wp_ajax_uwp_ajax_user_sorting_action', array( $this, 'ajax_handler' ) ); |
| 32 | 32 | add_action( 'uwp_add_custom_sort_options', array( $this, 'add_custom_sort_options' ) ); |
| 33 | 33 | add_action( 'pre_user_query', array( $this, 'pre_user_query' ), 99 ); |
| 34 | + | |
| 34 | 35 | } |
| 35 | 36 | |
| 36 | 37 | public function pre_user_query( $vars ) { |
| 37 | 38 | |
| @@ -54,9 +55,9 @@ | ||
| 54 | 55 | if ( substr( strtolower( $sort_by ), - 5 ) == '_desc' ) { |
| 55 | 56 | $order = 'DESC'; |
| 56 | 57 | $meta_key = substr( $sort_by, 0, strlen( $sort_by ) - 5 ); |
| 57 | 58 | $order_by = 'meta_value'; |
| 58 | - } elseif ( substr( strtolower( $sort_by ), - 4 ) == '_asc' ) { | |
| 59 | + } else if ( substr( strtolower( $sort_by ), - 4 ) == '_asc' ) { | |
| 59 | 60 | $order = 'ASC'; |
| 60 | 61 | $meta_key = substr( $sort_by, 0, strlen( $sort_by ) - 4 ); |
| 61 | 62 | $order_by = 'meta_value'; |
| 62 | 63 | } |
| @@ -61,11 +62,11 @@ | ||
| 61 | 62 | $order_by = 'meta_value'; |
| 62 | 63 | } |
| 63 | 64 | |
| 64 | 65 | // check meta key exists |
| 65 | - if ( $meta_key && 'user_registered' !== $meta_key ) { | |
| 66 | + if ($meta_key && 'user_registered' !== $meta_key) { | |
| 66 | 67 | $table = new UsersWP_Tables(); |
| 67 | - if ( ! in_array( $meta_key, $table->get_db_usermeta_columns() ) ) { | |
| 68 | + if (!in_array($meta_key, $table->get_db_usermeta_columns())) { | |
| 68 | 69 | $meta_key = ''; |
| 69 | 70 | } |
| 70 | 71 | } |
| 71 | 72 | |
| @@ -72,21 +73,21 @@ | ||
| 72 | 73 | if ( ! empty( $order_by ) && $meta_key ) { |
| 73 | 74 | $meta_table_name = uwp_get_table_prefix() . 'uwp_usermeta'; |
| 74 | 75 | $table_name = uwp_get_table_prefix() . 'uwp_user_sorting'; |
| 75 | 76 | |
| 76 | - if ( 'user_registered' == $meta_key ) { | |
| 77 | + if('user_registered' == $meta_key){ | |
| 77 | 78 | $orderby = $meta_key; |
| 78 | 79 | } else { |
| 79 | 80 | $orderby = $meta_table_name . '.' . sanitize_key( $meta_key ); |
| 80 | 81 | } |
| 81 | 82 | |
| 82 | - $vars->query_from .= ' INNER JOIN ' . $meta_table_name . ' ON (' . $meta_table_name . ".user_id = $wpdb->users.ID) "; // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching | |
| 83 | + $vars->query_from .= " INNER JOIN " . $meta_table_name . " ON (" . $meta_table_name . ".user_id = $wpdb->users.ID) "; // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching | |
| 83 | 84 | $vars->query_orderby = 'ORDER BY ' . $orderby . ' ' . $order; |
| 84 | 85 | |
| 85 | - $parent_id = $wpdb->get_var( $wpdb->prepare( 'SELECT id FROM ' . $table_name . ' WHERE htmlvar_name = %s AND sort = %s AND tab_parent = 0', $meta_key, $order ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching | |
| 86 | + $parent_id = $wpdb->get_var( $wpdb->prepare( "SELECT id FROM " . $table_name . " WHERE htmlvar_name = %s AND sort = %s AND tab_parent = 0", $meta_key, $order ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching | |
| 86 | 87 | |
| 87 | 88 | if ( $parent_id ) { |
| 88 | - $children = $wpdb->get_results( $wpdb->prepare( 'SELECT * FROM ' . $table_name . ' WHERE tab_parent = %d ORDER BY sort_order ASC', $parent_id ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching | |
| 89 | + $children = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM " . $table_name . " WHERE tab_parent = %d ORDER BY sort_order ASC", $parent_id ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching | |
| 89 | 90 | |
| 90 | 91 | if ( $children ) { |
| 91 | 92 | |
| 92 | 93 | foreach ( $children as $child ) { |
| @@ -99,15 +100,8 @@ | ||
| 99 | 100 | } |
| 100 | 101 | } |
| 101 | 102 | } |
| 102 | 103 | |
| 103 | - if ( is_uwp_users_page() && !empty($_GET['uwp_sort_by']) ) { | |
| 104 | - if ($_GET['uwp_sort_by'] === 'random_asc' || $_GET['uwp_sort_by'] === 'random_desc') { | |
| 105 | - // Random order | |
| 106 | - $vars->query_orderby = 'ORDER BY RAND()'; | |
| 107 | - } | |
| 108 | - } | |
| 109 | - | |
| 110 | 104 | return $vars; |
| 111 | 105 | } |
| 112 | 106 | |
| 113 | 107 | /** |
| @@ -123,8 +117,9 @@ | ||
| 123 | 117 | public function form_builder_tab_items( $tabs ) { |
| 124 | 118 | $tabs['user-sorting'] = __( 'User Sorting', 'userswp' ); |
| 125 | 119 | |
| 126 | 120 | return $tabs; |
| 121 | + | |
| 127 | 122 | } |
| 128 | 123 | |
| 129 | 124 | /** |
| 130 | 125 | * Add a tab to form builder |
| @@ -260,9 +255,9 @@ | ||
| 260 | 255 | 'site_title' => __( 'Newer', 'userswp' ), |
| 261 | 256 | 'htmlvar_name' => 'newer', |
| 262 | 257 | 'field_icon' => 'fas fa-calendar', |
| 263 | 258 | 'sort' => 'asc', |
| 264 | - 'description' => __( 'Sort by new user registration', 'userswp' ), | |
| 259 | + 'description' => __( 'Sort by new user registration', 'userswp' ) | |
| 265 | 260 | ); |
| 266 | 261 | |
| 267 | 262 | $fields['older'] = array( |
| 268 | 263 | 'data_type' => '', |
| @@ -270,9 +265,9 @@ | ||
| 270 | 265 | 'site_title' => __( 'Older', 'userswp' ), |
| 271 | 266 | 'htmlvar_name' => 'older', |
| 272 | 267 | 'field_icon' => 'fas fa-calendar', |
| 273 | 268 | 'sort' => 'desc', |
| 274 | - 'description' => __( 'Sort by new user registration in descending order', 'userswp' ), | |
| 269 | + 'description' => __( 'Sort by new user registration in descending order', 'userswp' ) | |
| 275 | 270 | ); |
| 276 | 271 | |
| 277 | 272 | $fields['display_name'] = array( |
| 278 | 273 | 'data_type' => '', |
| @@ -280,9 +275,9 @@ | ||
| 280 | 275 | 'site_title' => __( 'Display Name', 'userswp' ), |
| 281 | 276 | 'htmlvar_name' => 'display_name', |
| 282 | 277 | 'field_icon' => 'fas fa-sort-alpha-up', |
| 283 | 278 | 'sort' => 'asc', |
| 284 | - 'description' => __( 'Sort alphabetically by display name in ascending order', 'userswp' ), | |
| 279 | + 'description' => __( 'Sort alphabetically by display name in ascending order', 'userswp' ) | |
| 285 | 280 | ); |
| 286 | 281 | |
| 287 | 282 | $fields['first_name'] = array( |
| 288 | 283 | 'data_type' => '', |
| @@ -290,9 +285,9 @@ | ||
| 290 | 285 | 'site_title' => __( 'First Name', 'userswp' ), |
| 291 | 286 | 'htmlvar_name' => 'first_name', |
| 292 | 287 | 'field_icon' => 'fas fa-sort-alpha-up', |
| 293 | 288 | 'sort' => 'asc', |
| 294 | - 'description' => __( 'Sort alphabetically by first name in ascending order', 'userswp' ), | |
| 289 | + 'description' => __( 'Sort alphabetically by first name in ascending order', 'userswp' ) | |
| 295 | 290 | ); |
| 296 | 291 | |
| 297 | 292 | $fields['last_name'] = array( |
| 298 | 293 | 'data_type' => '', |
| @@ -300,29 +295,18 @@ | ||
| 300 | 295 | 'site_title' => __( 'Last Name', 'userswp' ), |
| 301 | 296 | 'htmlvar_name' => 'last_name', |
| 302 | 297 | 'field_icon' => 'fas fa-sort-alpha-up', |
| 303 | 298 | 'sort' => 'asc', |
| 304 | - 'description' => __( 'Sort alphabetically by last name in ascending order', 'userswp' ), | |
| 299 | + 'description' => __( 'Sort alphabetically by last name in ascending order', 'userswp' ) | |
| 305 | 300 | ); |
| 306 | 301 | |
| 307 | - $fields['random'] = array( | |
| 308 | - 'data_type' => '', | |
| 309 | - 'field_type' => 'text', | |
| 310 | - 'site_title' => __( 'Random', 'userswp' ), | |
| 311 | - 'htmlvar_name' => 'random', | |
| 312 | - 'field_icon' => 'fa-solid fa-shuffle', | |
| 313 | - 'sort' => '', | |
| 314 | - 'description' => __( 'Sort users by random', 'userswp' ) | |
| 315 | - ); | |
| 316 | - | |
| 317 | 302 | $fields = apply_filters( 'uwp_add_custom_sort_options', $fields ); |
| 318 | 303 | |
| 319 | 304 | ?> |
| 320 | 305 | <input type="hidden" name="form_type" id="form_type" value="<?php echo esc_attr( $form_type ); ?>"/> |
| 321 | 306 | <input type="hidden" name="manage_field_type" class="manage_field_type" value="user_sorting"> |
| 322 | - <?php wp_nonce_field( 'uwp-admin-settings' ); ?> | |
| 323 | - | |
| 324 | - <ul class="row row-cols-2 px-2 mb-0"> | |
| 307 | + <?php wp_nonce_field( 'uwp-admin-settings','uwp-admin-settings' ); ?> | |
| 308 | + <ul> | |
| 325 | 309 | <?php |
| 326 | 310 | |
| 327 | 311 | if ( ! empty( $fields ) ) { |
| 328 | 312 | foreach ( $fields as $field ) { |
| @@ -336,20 +320,20 @@ | ||
| 336 | 320 | } else { |
| 337 | 321 | $field_icon = '<i class="fas fa-sort" aria-hidden="true"></i>'; |
| 338 | 322 | } |
| 339 | 323 | ?> |
| 340 | - <li class="col px-1"> | |
| 324 | + <li> | |
| 341 | 325 | <a id="uwp-<?php echo esc_attr( $field['htmlvar_name'] ); ?>" |
| 342 | - class="uwp-draggable-form-itemsx btn btn-sm d-block m-0 btn-outline-gray text-dark text-start" | |
| 343 | - data-field_type="<?php echo isset( $field['field_type'] ) ? esc_attr( $field['field_type'] ) : ''; ?>" | |
| 344 | - data-site_title="<?php echo isset( $field['site_title'] ) ? esc_attr( $field['site_title'] ) : ''; ?>" | |
| 345 | - data-field_icon="<?php echo isset( $field['field_icon'] ) ? esc_attr( $field['field_icon'] ) : ''; ?>" | |
| 346 | - data-id="<?php echo isset( $field['htmlvar_name'] ) ? esc_attr( $field['htmlvar_name'] ) : ''; ?>" | |
| 347 | - data-data_type="<?php echo isset( $field['data_type'] ) ? esc_attr( $field['data_type'] ) : 'VARCHAR'; ?>" | |
| 348 | - data-tab_parent="<?php echo isset( $field['tab_parent'] ) ? esc_attr( $field['tab_parent'] ) : ''; ?>" | |
| 349 | - data-tab_level="<?php echo isset( $field['tab_content'] ) ? esc_attr( $field['tab_content'] ) : ''; ?>" | |
| 350 | - data-sort="<?php echo isset( $field['sort'] ) ? esc_attr( $field['sort'] ) : 'asc'; ?>" | |
| 351 | - href="javascript:void(0);"> | |
| 326 | + class="uwp-draggable-form-items" | |
| 327 | + data-field_type="<?php echo isset( $field['field_type'] ) ? esc_attr( $field['field_type'] ) : ''; ?>" | |
| 328 | + data-site_title="<?php echo isset( $field['site_title'] ) ? esc_attr( $field['site_title'] ) : ''; ?>" | |
| 329 | + data-field_icon="<?php echo isset( $field['field_icon'] ) ? esc_attr( $field['field_icon'] ) : ''; ?>" | |
| 330 | + data-id="<?php echo isset( $field['htmlvar_name'] ) ? esc_attr( $field['htmlvar_name'] ) : ''; ?>" | |
| 331 | + data-data_type="<?php echo isset( $field['data_type'] ) ? esc_attr( $field['data_type'] ) : 'VARCHAR'; ?>" | |
| 332 | + data-tab_parent="<?php echo isset( $field['tab_parent'] ) ? esc_attr( $field['tab_parent'] ) : ''; ?>" | |
| 333 | + data-tab_level="<?php echo isset( $field['tab_content'] ) ? esc_attr( $field['tab_content'] ) : ''; ?>" | |
| 334 | + data-sort="<?php echo isset( $field['sort'] ) ? esc_attr( $field['sort'] ) : 'asc'; ?>" | |
| 335 | + href="javascript:void(0);"> | |
| 352 | 336 | <?php echo $field_icon; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> |
| 353 | 337 | <?php echo esc_attr( $field['site_title'] ); ?> |
| 354 | 338 | </a> |
| 355 | 339 | </li> |
| @@ -375,11 +359,11 @@ | ||
| 375 | 359 | $table_name = uwp_get_table_prefix() . 'uwp_user_sorting'; |
| 376 | 360 | ?> |
| 377 | 361 | <input type="hidden" name="form_type" id="form_type" value="<?php echo esc_attr( $form_type ); ?>"/> |
| 378 | 362 | <input type="hidden" name="manage_field_type" class="manage_field_type" value="user_sorting"> |
| 379 | - <ul class="uwp-profile-tabs-selected core uwp_form_extras ps-0 list-group "> | |
| 363 | + <ul class="uwp-profile-tabs-selected core uwp_form_extras"> | |
| 380 | 364 | <?php |
| 381 | - $tabs = $wpdb->get_results( 'SELECT * FROM ' . $table_name . ' order by sort_order asc' ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching | |
| 365 | + $tabs = $wpdb->get_results( "SELECT * FROM " . $table_name . " order by sort_order asc" ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching | |
| 382 | 366 | if ( ! empty( $tabs ) ) { |
| 383 | 367 | foreach ( $tabs as $key => $tab ) { |
| 384 | 368 | $field_ins_upd = 'display'; |
| 385 | 369 | |
| @@ -390,9 +374,9 @@ | ||
| 390 | 374 | ob_start(); |
| 391 | 375 | $this->field_adminhtml( $tab->id, $field_ins_upd ); |
| 392 | 376 | $tab_rendered = ob_get_clean(); |
| 393 | 377 | |
| 394 | - $tab_rendered = str_replace( '</li>', '', $tab_rendered ); | |
| 378 | + $tab_rendered = str_replace( "</li>", "", $tab_rendered ); | |
| 395 | 379 | $child_tabs = ''; |
| 396 | 380 | foreach ( $tabs as $child_tab ) { |
| 397 | 381 | if ( $child_tab->tab_parent == $tab->id ) { |
| 398 | 382 | ob_start(); |
| @@ -401,20 +385,19 @@ | ||
| 401 | 385 | } |
| 402 | 386 | } |
| 403 | 387 | |
| 404 | 388 | if ( $child_tabs ) { |
| 405 | - $tab_rendered .= '<ul>'; | |
| 389 | + $tab_rendered .= "<ul>"; | |
| 406 | 390 | $tab_rendered .= $child_tabs; |
| 407 | - $tab_rendered .= '</ul>'; | |
| 391 | + $tab_rendered .= "</ul>"; | |
| 408 | 392 | } |
| 409 | 393 | |
| 410 | 394 | echo $tab_rendered; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 411 | - echo '</li>'; | |
| 395 | + echo "</li>"; | |
| 412 | 396 | |
| 413 | 397 | unset( $tabs[ $key ] ); |
| 414 | 398 | } |
| 415 | - } | |
| 416 | - ?> | |
| 399 | + } ?> | |
| 417 | 400 | </ul> |
| 418 | 401 | <?php |
| 419 | 402 | } |
| 420 | 403 | |
| @@ -434,14 +417,14 @@ | ||
| 434 | 417 | |
| 435 | 418 | $table_name = uwp_get_table_prefix() . 'uwp_user_sorting'; |
| 436 | 419 | |
| 437 | 420 | if ( ! is_object( $field_id ) && ( is_int( $field_id ) || ctype_digit( $field_id ) ) ) { |
| 438 | - $field = $wpdb->get_row( $wpdb->prepare( 'select * from ' . $table_name . ' where id= %d', array( $field_id ) ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching | |
| 421 | + $field = $wpdb->get_row( $wpdb->prepare( "select * from " . $table_name . " where id= %d", array( $field_id ) ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching | |
| 439 | 422 | } elseif ( is_object( $field_id ) ) { |
| 440 | 423 | $field_id = $field_id->id; |
| 441 | - $field = $wpdb->get_row( $wpdb->prepare( 'select * from ' . $table_name . ' where id= %d', array( (int) $field_id->id ) ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching | |
| 424 | + $field = $wpdb->get_row( $wpdb->prepare( "select * from " . $table_name . " where id= %d", array( (int) $field_id->id ) ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching | |
| 442 | 425 | } elseif ( isset( $field_id ) && ! empty( $field_id ) ) { |
| 443 | - $field = $wpdb->get_row( $wpdb->prepare( 'select * from ' . $table_name . ' where htmlvar_name= %s', array( $field_id ) ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching | |
| 426 | + $field = $wpdb->get_row( $wpdb->prepare( "select * from " . $table_name . " where htmlvar_name= %s", array( $field_id ) ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching | |
| 444 | 427 | } else { |
| 445 | 428 | $field = array(); |
| 446 | 429 | } |
| 447 | 430 | |
| @@ -447,9 +430,9 @@ | ||
| 447 | 430 | |
| 448 | 431 | if ( isset( $request['site_title'] ) ) { |
| 449 | 432 | $site_title = esc_attr( $request['site_title'] ); |
| 450 | 433 | } elseif ( $field && isset( $field->site_title ) ) { |
| 451 | - $site_title = wp_unslash( $field->site_title ); | |
| 434 | + $site_title = $field->site_title; | |
| 452 | 435 | } else { |
| 453 | 436 | $site_title = ''; |
| 454 | 437 | } |
| 455 | 438 | |
| @@ -510,116 +493,109 @@ | ||
| 510 | 493 | } else { |
| 511 | 494 | $tab_level = 0; |
| 512 | 495 | } |
| 513 | 496 | |
| 514 | - $nonce = wp_create_nonce( 'uwp_sort_extras_nonce_' . $field_id ); | |
| 515 | 497 | ?> |
| 516 | 498 | <li class="text li-settings" id="licontainer_<?php echo esc_attr( $field_id ); ?>"> |
| 517 | - <div class="title title<?php echo esc_attr( $field_id ); ?> uwp-fieldset hover-shadow dd-form d-flex justify-content-between rounded c-pointer list-group-item border rounded-smx text-start bg-light " onclick="uwp_tabs_item_settings(this);"> | |
| 499 | + <i class="fas fa-caret-down toggle-arrow" aria-hidden="true" onclick="uwp_show_hide(this);"></i> | |
| 500 | + <div class="title title<?php echo esc_attr( $field_id ); ?> uwp-fieldset"> | |
| 518 | 501 | <?php |
| 502 | + $nonce = wp_create_nonce( 'uwp_sort_extras_nonce_' . $field_id ); | |
| 503 | + echo $field_icon; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 519 | 504 | ?> |
| 520 | - <div class=" flex-fill font-weight-bold fw-bold"> | |
| 521 | - <?php echo $field_icon; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> | |
| 522 | - <b><?php echo esc_html( uwp_ucwords( ' ' . $site_title ) ); ?></b> | |
| 523 | - <span class="field-type float-end text-end small"><?php echo ' (' . esc_html( uwp_ucwords( $field_type ) ) . ')'; ?></span> | |
| 524 | - </div> | |
| 525 | - <div class="dd-handle ui-sortable-handle"> | |
| 526 | - <i class="far fa-trash-alt text-danger ml-2 ms-2" id="delete-16" | |
| 527 | - onclick="delete_field('<?php echo esc_attr( $field_id ); ?>', '<?php echo esc_attr( wp_create_nonce( 'uwp_sort_delete_nonce_' . $field_id ) ); ?>', '<?php echo esc_attr( $htmlvar_name ); ?>', 'user_sorting');event.stopPropagation();return false;"></i> | |
| 528 | - <i class="fas fa-grip-vertical text-muted ml-2 ms-2" style="cursor: move" aria-hidden="true"></i> | |
| 529 | - </div> | |
| 505 | + <b><?php echo esc_html( uwp_ucwords( ' ' . $site_title ) ); ?></b> | |
| 530 | 506 | |
| 531 | 507 | </div> |
| 508 | + <div id="field_frm<?php echo esc_attr( $field_id ); ?>" class="field_frm" | |
| 509 | + style="display:<?php if ( $field_ins_upd == 'submit' ) { | |
| 510 | + echo 'block;'; | |
| 511 | + } else { | |
| 512 | + echo 'none;'; | |
| 513 | + } ?>"> | |
| 532 | 514 | |
| 533 | - <?php // store the form as a template. This saves a load of memory on page load. ?> | |
| 534 | - <script type="text/template" class="dd-setting <?php echo 'dd-type-' . esc_attr( $field_type ); ?>"> | |
| 535 | - <div id="field_frm<?php echo esc_attr( $field_id ); ?>" class="field_frm" style="<?php echo ( $field_ins_upd == 'submit' ) ? 'display:block;' : ''; ?>"> | |
| 515 | + <input type="hidden" name="_wpnonce" id="uwp_sort_extras_nonce" | |
| 516 | + value="<?php echo esc_attr( $nonce ); ?>"/> | |
| 517 | + <input type="hidden" name="field_id" id="field_id" value="<?php echo esc_attr( $field_id ); ?>"/> | |
| 518 | + <input type="hidden" name="form_type" id="form_type" value="user_sorting"/> | |
| 519 | + <input type="hidden" name="field_icon" id="field_icon" value="<?php echo esc_attr( $icon ); ?>"/> | |
| 520 | + <input type="hidden" name="field_type" id="field_type" | |
| 521 | + value="<?php echo esc_attr( $field_type ); ?>"/> | |
| 522 | + <input type="hidden" name="data_type" id="data_type" value="<?php echo esc_attr( $data_type ); ?>"/> | |
| 523 | + <input type="hidden" name="tab_parent" value="<?php echo esc_attr( $tab_parent ); ?>"/> | |
| 524 | + <input type="hidden" name="tab_level" value="<?php echo esc_attr( $tab_level ); ?>"/> | |
| 525 | + <input type="hidden" name="htmlvar_name" value="<?php echo esc_attr( $htmlvar_name ) ?>"/> | |
| 536 | 526 | |
| 537 | - <input type="hidden" name="_wpnonce" id="uwp_sort_extras_nonce" value="<?php echo esc_attr( $nonce ); ?>"/> | |
| 538 | - <input type="hidden" name="field_id" id="field_id" value="<?php echo esc_attr( $field_id ); ?>"/> | |
| 539 | - <input type="hidden" name="form_type" id="form_type" value="user_sorting"/> | |
| 540 | - <input type="hidden" name="field_icon" id="field_icon" value="<?php echo esc_attr( $icon ); ?>"/> | |
| 541 | - <input type="hidden" name="field_type" id="field_type" value="<?php echo esc_attr( $field_type ); ?>"/> | |
| 542 | - <input type="hidden" name="data_type" id="data_type" value="<?php echo esc_attr( $data_type ); ?>"/> | |
| 543 | - <input type="hidden" name="tab_parent" value="<?php echo esc_attr( $tab_parent ); ?>"/> | |
| 544 | - <input type="hidden" name="tab_level" value="<?php echo esc_attr( $tab_level ); ?>"/> | |
| 545 | - <input type="hidden" name="htmlvar_name" value="<?php echo esc_attr( $htmlvar_name ); ?>"/> | |
| 527 | + <ul class="widefat post fixed" style="width:100%;"> | |
| 546 | 528 | |
| 547 | - <?php | |
| 548 | - // site_title | |
| 549 | - echo aui()->input( | |
| 550 | - array( | |
| 551 | - 'id' => 'site_title', | |
| 552 | - 'name' => 'site_title', | |
| 553 | - 'label_type' => 'top', | |
| 554 | - 'label' => esc_html__( 'Frontend title', 'userswp' ) . uwp_help_tip( __( 'This is the text used for the sort option.', 'userswp' ) ), // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 555 | - 'type' => 'text', | |
| 556 | - // 'wrap_class' => uwp_advanced_toggle_class(), | |
| 557 | - 'value' => $site_title, | |
| 558 | - ) | |
| 559 | - ); | |
| 529 | + <li class="uwp-setting-name"> | |
| 530 | + <label for="site_title" class="uwp-tooltip-wrap"> | |
| 531 | + <?php | |
| 532 | + echo uwp_help_tip( __( 'This is the text used for the sort option.', 'userswp' ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 533 | + esc_html_e( 'Frontend title', 'userswp' ); ?> | |
| 534 | + </label> | |
| 535 | + <div class="uwp-input-wrap"> | |
| 536 | + <input type="text" name="site_title" id="site_title" | |
| 537 | + value="<?php echo esc_attr( $site_title ); ?>"/> | |
| 538 | + </div> | |
| 539 | + </li> | |
| 560 | 540 | |
| 561 | - // sort | |
| 562 | - $value = isset( $field->sort ) && $field->sort == 'desc' ? 'desc' : 'asc'; | |
| 563 | - echo aui()->select( | |
| 564 | - array( | |
| 565 | - 'id' => 'uwp-sort-' . ( isset( $field->id ) ? esc_attr( $field->id ) : '' ), | |
| 566 | - 'name' => 'sort', | |
| 567 | - 'label_type' => 'top', | |
| 568 | - 'multiple' => false, | |
| 569 | - 'class' => ' mw-100', | |
| 570 | - 'options' => array( | |
| 571 | - 'asc' => esc_html__( 'Ascending', 'userswp' ), | |
| 572 | - 'desc' => esc_html__( 'Descending', 'userswp' ), | |
| 573 | - ), | |
| 574 | - 'label' => __( 'Ascending or Descending', 'userswp' ) . uwp_help_tip( __( 'Select the sort direction: (A-Z or Z-A).', 'userswp' ) ), // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 575 | - 'value' => $value, | |
| 576 | - // 'wrap_class' => uwp_advanced_toggle_class(), | |
| 577 | - ) | |
| 578 | - ); | |
| 541 | + <li class="uwp-setting-name"> | |
| 542 | + <label for="sort" class="uwp-tooltip-wrap"> | |
| 543 | + <?php | |
| 544 | + echo uwp_help_tip( __( 'Select the sort direction: (A-Z or Z-A).', 'userswp' ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 545 | + esc_html_e( 'Ascending or Descending', 'userswp' ); ?> | |
| 546 | + </label> | |
| 547 | + <div class="uwp-input-wrap"> | |
| 548 | + <select name="sort" id="uwp-sort-<?php echo esc_attr( $field->id ); ?>"> | |
| 549 | + <?php $value = isset( $field->sort ) && $field->sort == 'desc' ? 'desc' : 'asc'; ?> | |
| 550 | + <option value="asc" <?php selected( 'asc', $value, true ); ?>><?php esc_html_e( 'Ascending', 'userswp' ); ?></option> | |
| 551 | + <option value="desc" <?php selected( 'desc', $value, true ); ?>><?php esc_html_e( 'Descending', 'userswp' ); ?></option> | |
| 552 | + </select> | |
| 553 | + </div> | |
| 554 | + </li> | |
| 579 | 555 | |
| 580 | - echo aui()->input( | |
| 581 | - array( | |
| 582 | - 'id' => 'is_default', | |
| 583 | - 'name' => 'is_default', | |
| 584 | - 'type' => 'checkbox', //'!$exclude_privacy_option ? 'hidden' : 'checkbox', | |
| 585 | - 'label_type' => 'horizontal', | |
| 586 | - 'label_col' => '4', | |
| 587 | - 'label' => __( 'Default sort', 'userswp' ), | |
| 588 | - 'checked' => isset( $field->is_default ) && $field->is_default == 1, | |
| 589 | - 'value' => '1', | |
| 590 | - 'switch' => 'md', | |
| 591 | - 'label_force_left' => true, | |
| 592 | - 'help_text' => uwp_help_tip( __( 'This sets the option as the overall default sort value, there can be only one.', 'userswp' ) ), | |
| 593 | - ) | |
| 594 | - ); | |
| 556 | + <li class="uwp-setting-name"> | |
| 595 | 557 | |
| 596 | - echo aui()->input( | |
| 597 | - array( | |
| 598 | - 'id' => 'is_active', | |
| 599 | - 'name' => 'is_active', | |
| 600 | - 'type' => 'checkbox', //'!$exclude_privacy_option ? 'hidden' : 'checkbox', | |
| 601 | - 'label_type' => 'horizontal', | |
| 602 | - 'label_col' => '4', | |
| 603 | - 'label' => __( 'Is active', 'userswp' ), | |
| 604 | - 'checked' => isset( $field->is_active ) && $field->is_active, | |
| 605 | - 'value' => '1', | |
| 606 | - 'switch' => 'md', | |
| 607 | - 'label_force_left' => true, | |
| 608 | - 'help_text' => uwp_help_tip( __( 'Set if this sort option is active or not, if not it will not be shown to users.', 'userswp' ) ), | |
| 609 | - ) | |
| 610 | - ); | |
| 611 | - ?> | |
| 612 | - <input type="hidden" readonly="readonly" name="sort_order" id="sort_order" value="<?php echo (isset( $field->sort_order )) ? esc_attr( $field->sort_order ) : ''; ?>" size="50"/> | |
| 613 | - <?php do_action( 'uwp_user_sorting_custom_fields', $field_id ); ?> | |
| 558 | + <label for="is_default" class="uwp-tooltip-wrap"> | |
| 559 | + <?php | |
| 560 | + echo uwp_help_tip( __( 'This sets the option as the overall default sort value, there can be only one.', 'userswp' ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 561 | + esc_html_e( 'Default sort?', 'userswp' ); ?> | |
| 562 | + </label> | |
| 563 | + <div class="uwp-input-wrap"> | |
| 564 | + <input type="radio" name="is_default" | |
| 565 | + value="1" <?php if ( isset( $field->is_default ) && $field->is_default == 1 ) { | |
| 566 | + echo 'checked="checked"'; | |
| 567 | + } ?>/> | |
| 568 | + </div> | |
| 614 | 569 | |
| 615 | - <div class="uwp-input-wrap uwp-tab-actions" data-setting="save_button"> | |
| 616 | - <a class=" btn btn-link text-muted" href="javascript:void(0);" onclick="uwp_tabs_close_settings(this); return false;"><?php _e( 'Close', 'userswp' ); ?></a> | |
| 617 | - <a href='javascript:void(0);' type="button" class="btn btn-primary" id="save" | |
| 618 | - onclick="save_field('<?php echo esc_attr( $field_id ); ?>', 'user_sorting');return false;"><?php echo esc_attr( __( 'Save', 'userswp' ) ); ?></a> | |
| 619 | - </div> | |
| 620 | - </div> | |
| 621 | - </script> | |
| 570 | + </li> | |
| 571 | + | |
| 572 | + <li class="uwp-setting-name"> | |
| 573 | + <label for="is_active" class="uwp-tooltip-wrap"> | |
| 574 | + <?php | |
| 575 | + echo uwp_help_tip( __( 'Set if this sort option is active or not, if not it will not be shown to users.', 'userswp' ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 576 | + esc_html_e( 'Is active?', 'userswp' ); ?> | |
| 577 | + </label> | |
| 578 | + <div class="uwp-input-wrap"> | |
| 579 | + <?php $value = isset( $field->is_active ) && $field->is_active ? $field->is_active : 0; ?> | |
| 580 | + <input type="hidden" name="is_active" value="0"/> | |
| 581 | + <input type="checkbox" name="is_active" value="1" <?php checked( $value, 1, true ); ?> /> | |
| 582 | + </div> | |
| 583 | + </li> | |
| 584 | + <input type="hidden" readonly="readonly" name="sort_order" id="sort_order" value="<?php if ( isset( $field->sort_order ) ) { echo esc_attr( $field->sort_order ); } ?>" size="50"/> | |
| 585 | + <?php do_action( 'uwp_user_sorting_custom_fields', $field_id ); ?> | |
| 586 | + <li> | |
| 587 | + <div class="uwp-input-wrap uwp-tab-actions" data-setting="save_button"> | |
| 588 | + <input type="button" class="button button-primary" name="save" id="save" | |
| 589 | + value="<?php esc_attr_e( 'Save', 'userswp' ); ?>" | |
| 590 | + onclick="save_field('<?php echo esc_attr( $field_id ); ?>', 'user_sorting')"/> | |
| 591 | + <a class="item-delete submitdelete deletion" | |
| 592 | + id="delete-<?php echo esc_attr( $field_id ); ?>" href="javascript:void(0);" | |
| 593 | + onclick="delete_field('<?php echo esc_attr( $field_id ); ?>', '<?php echo esc_attr( wp_create_nonce( 'uwp_sort_delete_nonce_' . $field_id ) ); ?>', '<?php echo esc_attr( $htmlvar_name ); ?>', 'user_sorting')"><?php esc_html_e( "Remove", "userswp" ); ?></a> | |
| 594 | + </div> | |
| 595 | + </li> | |
| 596 | + </ul> | |
| 597 | + </div> | |
| 622 | 598 | </li> |
| 623 | 599 | <?php |
| 624 | 600 | } |
| 625 | 601 | |
| @@ -657,9 +633,9 @@ | ||
| 657 | 633 | } |
| 658 | 634 | |
| 659 | 635 | /* ---- Show field form in admin ---- */ |
| 660 | 636 | if ( $field_action == 'new' ) { |
| 661 | - if ( ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'uwp-admin-settings' ) ) { | |
| 637 | + if ( ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'uwp-admin-settings') ) { | |
| 662 | 638 | return; |
| 663 | 639 | } |
| 664 | 640 | $htmlvar_name = isset( $_REQUEST['htmlvar_name'] ) ? sanitize_text_field( $_REQUEST['htmlvar_name'] ) : sanitize_text_field( $_REQUEST['tab_key'] ); |
| 665 | 641 | $this->field_adminhtml( $htmlvar_name, $field_action, $_REQUEST ); |
| @@ -718,18 +694,14 @@ | ||
| 718 | 694 | $id = isset( $request_field['field_id'] ) && $request_field['field_id'] ? absint( $request_field['field_id'] ) : ''; |
| 719 | 695 | $data_type = isset( $request_field['data_type'] ) ? sanitize_text_field( $request_field['data_type'] ) : 'VARCHAR'; |
| 720 | 696 | $field_type = isset( $request_field['field_type'] ) ? sanitize_text_field( $request_field['field_type'] ) : ''; |
| 721 | 697 | $site_title = isset( $request_field['site_title'] ) ? sanitize_text_field( $request_field['site_title'] ) : ''; |
| 722 | - $htmlvar_name = ! empty( $request_field['htmlvar_name'] ) ? sanitize_text_field( $request_field['htmlvar_name'] ) : str_replace( | |
| 723 | - array( | |
| 724 | - '-', | |
| 725 | - ' ', | |
| 726 | - '"', | |
| 727 | - "'", | |
| 728 | - ), | |
| 729 | - array( '_', '', '', '' ), | |
| 730 | - sanitize_title_with_dashes( $request_field['site_title'] ) | |
| 731 | - ); | |
| 698 | + $htmlvar_name = ! empty( $request_field['htmlvar_name'] ) ? sanitize_text_field( $request_field['htmlvar_name'] ) : str_replace( array( | |
| 699 | + '-', | |
| 700 | + ' ', | |
| 701 | + '"', | |
| 702 | + "'" | |
| 703 | + ), array( '_', '', '', '' ), sanitize_title_with_dashes( $request_field['site_title'] ) ); | |
| 732 | 704 | $tab_parent = ! empty( $request_field['tab_parent'] ) ? sanitize_text_field( $request_field['tab_parent'] ) : 0; |
| 733 | 705 | $tab_level = ! empty( $request_field['tab_level'] ) ? sanitize_text_field( $request_field['tab_level'] ) : 0; |
| 734 | 706 | $field_icon = isset( $request_field['field_icon'] ) ? sanitize_text_field( $request_field['field_icon'] ) : ''; |
| 735 | 707 | $is_active = isset( $request_field['is_active'] ) ? absint( $request_field['is_active'] ) : 0; |
| @@ -738,9 +710,9 @@ | ||
| 738 | 710 | |
| 739 | 711 | $total_tabs = $wpdb->get_var( "SELECT COUNT(id) FROM {$table_name}" ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching |
| 740 | 712 | |
| 741 | 713 | if ( isset( $is_default ) && $is_default > 0 ) { |
| 742 | - $wpdb->query( 'update ' . $table_name . " set is_default='0' where is_default='1'" ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching | |
| 714 | + $wpdb->query( "update " . $table_name . " set is_default='0' where is_default='1'" ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching | |
| 743 | 715 | } |
| 744 | 716 | |
| 745 | 717 | $data = array( |
| 746 | 718 | 'data_type' => $data_type, |
| @@ -798,9 +770,9 @@ | ||
| 798 | 770 | $table_name = uwp_get_table_prefix() . 'uwp_user_sorting'; |
| 799 | 771 | |
| 800 | 772 | if ( $field_id != '' ) { |
| 801 | 773 | $cf = trim( $field_id, '_' ); |
| 802 | - $wpdb->query( $wpdb->prepare( 'delete from ' . $table_name . ' where id= %d ', array( $cf ) ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching | |
| 774 | + $wpdb->query( $wpdb->prepare( "delete from " . $table_name . " where id= %d ", array( $cf ) ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching | |
| 803 | 775 | |
| 804 | 776 | return $field_id; |
| 805 | 777 | } else { |
| 806 | 778 | return 0; |
| @@ -826,22 +798,22 @@ | ||
| 826 | 798 | $table_name, |
| 827 | 799 | array( |
| 828 | 800 | 'sort_order' => $index, |
| 829 | 801 | 'tab_level' => (int) $tab['tab_level'], |
| 830 | - 'tab_parent' => (int) $tab['tab_parent'], | |
| 802 | + 'tab_parent' => (int) $tab['tab_parent'] | |
| 831 | 803 | ), |
| 832 | 804 | array( 'id' => absint( $tab['id'] ) ), |
| 833 | 805 | array( '%d', '%d', '%d' ) |
| 834 | 806 | ); |
| 835 | - ++$count; | |
| 807 | + $count ++; | |
| 836 | 808 | } |
| 837 | 809 | if ( $result !== false ) { |
| 838 | 810 | return true; |
| 839 | 811 | } else { |
| 840 | - return new WP_Error( 'failed', __( 'Failed to sort tab items.', 'userswp' ) ); | |
| 812 | + return new WP_Error( 'failed', __( "Failed to sort tab items.", "userswp" ) ); | |
| 841 | 813 | } |
| 842 | 814 | } else { |
| 843 | - return new WP_Error( 'failed', __( 'Failed to sort tab items.', 'userswp' ) ); | |
| 815 | + return new WP_Error( 'failed', __( "Failed to sort tab items.", "userswp" ) ); | |
| 844 | 816 | } |
| 845 | 817 | } |
| 846 | 818 | |
| 847 | 819 | /** |
| @@ -854,9 +826,9 @@ | ||
| 854 | 826 | public function add_custom_sort_options( $fields ) { |
| 855 | 827 | global $wpdb; |
| 856 | 828 | $table_name = uwp_get_table_prefix() . 'uwp_form_fields'; |
| 857 | 829 | |
| 858 | - $custom_fields = $wpdb->get_results( 'select data_type,field_type,site_title,htmlvar_name,field_icon from ' . $table_name . " where is_active='1' and user_sort='1' AND field_type != 'fieldset' order by sort_order asc", 'ARRAY_A' ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching | |
| 830 | + $custom_fields = $wpdb->get_results( "select data_type,field_type,site_title,htmlvar_name,field_icon from " . $table_name . " where is_active='1' and user_sort='1' AND field_type != 'fieldset' order by sort_order asc", 'ARRAY_A' ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching | |
| 859 | 831 | |
| 860 | 832 | if ( ! empty( $custom_fields ) ) { |
| 861 | 833 | |
| 862 | 834 | foreach ( $custom_fields as $val ) { |
| @@ -865,9 +837,10 @@ | ||
| 865 | 837 | } |
| 866 | 838 | |
| 867 | 839 | return $fields; |
| 868 | 840 | } |
| 841 | + | |
| 869 | 842 | } |
| 870 | 843 | |
| 871 | 844 | } |
| 872 | 845 | |
| 873 | -new UsersWP_Settings_User_Sorting(); | |
| 846 | +new UsersWP_Settings_User_Sorting(); | |