Changeset 3254912
- Timestamp:
- 03/12/2025 04:43:01 PM (13 months ago)
- Location:
- nhrrob-options-table-manager
- Files:
-
- 8 edited
- 1 copied
-
tags/1.1.4 (copied) (copied from nhrrob-options-table-manager/trunk)
-
tags/1.1.4/assets/js/admin.js (modified) (1 diff)
-
tags/1.1.4/includes/Ajax.php (modified) (7 diffs)
-
tags/1.1.4/nhrrob-options-table-manager.php (modified) (2 diffs)
-
tags/1.1.4/readme.txt (modified) (2 diffs)
-
trunk/assets/js/admin.js (modified) (1 diff)
-
trunk/includes/Ajax.php (modified) (7 diffs)
-
trunk/nhrrob-options-table-manager.php (modified) (2 diffs)
-
trunk/readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
nhrrob-options-table-manager/tags/1.1.4/assets/js/admin.js
r3240675 r3254912 240 240 $( '#nhrotm-data-table-usermeta_wrapper' ).fadeOut(); 241 241 $('.nhrotm-data-table-wrap .logged-user-id').fadeOut(); 242 $('#nhrotm-data-table-better_payment_wrapper').fadeOut(); 242 243 243 244 $( '#nhrotm-data-table_wrapper' ).fadeIn(); 244 245 } else if ( $(this).hasClass('usermeta-table') ) { 245 246 $( '#nhrotm-data-table_wrapper' ).fadeOut(); 247 $('#nhrotm-data-table-better_payment_wrapper').fadeOut(); 246 248 247 249 $( '#nhrotm-data-table-usermeta_wrapper' ).fadeIn(); -
nhrrob-options-table-manager/tags/1.1.4/includes/Ajax.php
r3253999 r3254912 383 383 // } 384 384 385 $option_value = ! empty( $option_value ) && is_serialized($option_value) ? maybe_unserialize($option_value) : $option_value;385 $option_value = ! empty( $option_value ) && is_serialized($option_value) ? unserialize($option_value, ['allowed_classes' => false]) : $option_value; 386 386 387 387 $response = []; … … 481 481 // } 482 482 483 if (preg_match('/O:\d+:"[^"]++":\d+:{/', $raw_option_value)) {484 wp_send_json_error('Object serialization is not allowed');485 wp_die();486 }483 // if (preg_match('/O:\d+:"[^"]++":\d+:{/', $raw_option_value)) { 484 // wp_send_json_error('Object serialization is not allowed'); 485 // wp_die(); 486 // } 487 487 488 488 $original_value = get_option($option_name); … … 490 490 491 491 $decoded_value = json_decode($raw_option_value, true); 492 $sanitized_value = ''; 493 492 494 if ($decoded_value !== null && json_last_error() === JSON_ERROR_NONE) { 493 495 $sanitized_value = $this->sanitize_array_recursive($decoded_value); 494 496 } else if (is_serialized($raw_option_value)) { 495 497 try { 496 $unserialized = maybe_unserialize($raw_option_value);498 $unserialized = unserialize($raw_option_value, ['allowed_classes' => false]); 497 499 498 500 if ($unserialized === false) { … … 501 503 } 502 504 503 if (is_array($unserialized) || is_object($unserialized)) { 505 if (is_array($unserialized) 506 || is_object($unserialized) 507 ) { 504 508 $sanitized_value = $this->sanitize_array_recursive((array)$unserialized); 505 509 } else { … … 674 678 675 679 public function usermeta_table_data() { 676 // Verify nonce 680 // Verify nonce first 677 681 if (!isset($_GET['nonce']) || !wp_verify_nonce(sanitize_text_field(wp_unslash($_GET['nonce'])), 'nhrotm-admin-nonce')) { 678 wp_send_json_error('Invalid security token'); 679 wp_die(); 680 } 681 682 // Check user capabilities 683 if (!current_user_can('manage_options')) { 684 wp_send_json_error('Insufficient permissions'); 685 wp_die(); 686 } 687 682 wp_send_json_error('Invalid nonce'); 683 wp_die(); 684 } 685 688 686 global $wpdb; 689 $table_name = $wpdb->prefix . 'usermeta'; 690 691 // Pagination parameters with defaults and validation 687 688 // Pagination parameters 692 689 $start = isset($_GET['start']) ? max(0, intval($_GET['start'])) : 0; 693 690 $length = isset($_GET['length']) ? min(max(1, intval($_GET['length'])), 100) : 10; 694 691 695 692 // Search parameter 696 693 $search = isset($_GET['search']['value']) ? sanitize_text_field(wp_unslash($_GET['search']['value'])) : ''; 697 694 698 695 // Sorting parameters 699 696 $order_column_index = isset($_GET['order'][0]['column']) ? intval($_GET['order'][0]['column']) : 0; 700 $order_direction = isset($_GET['order'][0]['dir']) && in_array($_GET['order'][0]['dir'], ['asc', 'desc']) 701 ? strtolower(sanitize_text_field(wp_unslash($_GET['order'][0]['dir']))) 702 : 'asc'; 703 704 // Define columns in the correct order for sorting with DB column mapping 705 $columns = [ 706 'umeta_id', 707 'user_id', 708 'meta_key', 709 'meta_value' 710 ]; 711 712 // Ensure order column is valid 713 $order_column = isset($columns[$order_column_index]) ? $columns[$order_column_index] : 'umeta_id'; 714 715 // Base query parts 716 $select_query = "SELECT * FROM {$wpdb->prefix}usermeta"; 717 $count_query = "SELECT COUNT(*) FROM {$wpdb->prefix}usermeta"; 718 719 // Apply search filter if provided 720 $where_clause = ''; 721 $query_args = []; 722 697 $order_direction = isset($_GET['order'][0]['dir']) && in_array($_GET['order'][0]['dir'], ['asc', 'desc']) ? 698 strtolower(sanitize_text_field(wp_unslash($_GET['order'][0]['dir']))) : 'asc'; 699 700 // Define valid columns for usermeta table 701 $columns = ['umeta_id', 'user_id', 'meta_key', 'meta_value']; 702 703 // Validate order column 704 if ($order_column_index < 0 || $order_column_index >= count($columns)) { 705 $order_column_index = 0; 706 } 707 $order_column = $columns[$order_column_index]; 708 709 // Total records count 710 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching 711 $total_records = $wpdb->get_var( 712 "SELECT COUNT(*) FROM {$wpdb->prefix}usermeta" 713 ); 714 715 // Main query logic 723 716 if (!empty($search)) { 724 $where_clause = " WHERE meta_key LIKE %s OR meta_value LIKE %s";725 717 $search_like = '%' . $wpdb->esc_like($search) . '%'; 726 $query_args[] = $search_like; 727 $query_args[] = $search_like; 728 } 729 730 // Add order clause 731 $order_clause = " ORDER BY {$order_column} {$order_direction}"; 732 733 // Add limit clause 734 $limit_clause = " LIMIT %d, %d"; 735 $query_args[] = $start; 736 $query_args[] = $length; 737 738 // Get total records without filtering 739 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching 740 $total_records = $wpdb->get_var($count_query); 741 742 // Get filtered records count 743 if (!empty($where_clause)) { 718 744 719 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching 745 720 $filtered_records = $wpdb->get_var( 746 721 $wpdb->prepare( 747 $count_query . $where_clause, 748 $query_args[0], 749 $query_args[1] 722 "SELECT COUNT(*) FROM {$wpdb->prefix}usermeta 723 WHERE meta_key LIKE %s OR meta_value LIKE %s", 724 $search_like, 725 $search_like 750 726 ) 751 727 ); 728 729 // Handle order with complete prepared statements 730 if ($order_column === 'umeta_id') { 731 if ($order_direction === 'desc') { 732 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching 733 $data = $wpdb->get_results( 734 $wpdb->prepare( 735 "SELECT * FROM {$wpdb->prefix}usermeta 736 WHERE meta_key LIKE %s OR meta_value LIKE %s 737 ORDER BY umeta_id DESC 738 LIMIT %d, %d", 739 $search_like, $search_like, $start, $length 740 ), 741 ARRAY_A 742 ); 743 } else { 744 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching 745 $data = $wpdb->get_results( 746 $wpdb->prepare( 747 "SELECT * FROM {$wpdb->prefix}usermeta 748 WHERE meta_key LIKE %s OR meta_value LIKE %s 749 ORDER BY umeta_id ASC 750 LIMIT %d, %d", 751 $search_like, $search_like, $start, $length 752 ), 753 ARRAY_A 754 ); 755 } 756 } elseif ($order_column === 'user_id') { 757 if ($order_direction === 'desc') { 758 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching 759 $data = $wpdb->get_results( 760 $wpdb->prepare( 761 "SELECT * FROM {$wpdb->prefix}usermeta 762 WHERE meta_key LIKE %s OR meta_value LIKE %s 763 ORDER BY user_id DESC 764 LIMIT %d, %d", 765 $search_like, $search_like, $start, $length 766 ), 767 ARRAY_A 768 ); 769 } else { 770 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching 771 $data = $wpdb->get_results( 772 $wpdb->prepare( 773 "SELECT * FROM {$wpdb->prefix}usermeta 774 WHERE meta_key LIKE %s OR meta_value LIKE %s 775 ORDER BY user_id ASC 776 LIMIT %d, %d", 777 $search_like, $search_like, $start, $length 778 ), 779 ARRAY_A 780 ); 781 } 782 } elseif ($order_column === 'meta_key') { 783 if ($order_direction === 'desc') { 784 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching 785 $data = $wpdb->get_results( 786 $wpdb->prepare( 787 "SELECT * FROM {$wpdb->prefix}usermeta 788 WHERE meta_key LIKE %s OR meta_value LIKE %s 789 ORDER BY meta_key DESC 790 LIMIT %d, %d", 791 $search_like, $search_like, $start, $length 792 ), 793 ARRAY_A 794 ); 795 } else { 796 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching 797 $data = $wpdb->get_results( 798 $wpdb->prepare( 799 "SELECT * FROM {$wpdb->prefix}usermeta 800 WHERE meta_key LIKE %s OR meta_value LIKE %s 801 ORDER BY meta_key ASC 802 LIMIT %d, %d", 803 $search_like, $search_like, $start, $length 804 ), 805 ARRAY_A 806 ); 807 } 808 } else { // meta_value 809 if ($order_direction === 'desc') { 810 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching 811 $data = $wpdb->get_results( 812 $wpdb->prepare( 813 "SELECT * FROM {$wpdb->prefix}usermeta 814 WHERE meta_key LIKE %s OR meta_value LIKE %s 815 ORDER BY meta_value DESC 816 LIMIT %d, %d", 817 $search_like, $search_like, $start, $length 818 ), 819 ARRAY_A 820 ); 821 } else { 822 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching 823 $data = $wpdb->get_results( 824 $wpdb->prepare( 825 "SELECT * FROM {$wpdb->prefix}usermeta 826 WHERE meta_key LIKE %s OR meta_value LIKE %s 827 ORDER BY meta_value ASC 828 LIMIT %d, %d", 829 $search_like, $search_like, $start, $length 830 ), 831 ARRAY_A 832 ); 833 } 834 } 752 835 } else { 753 836 $filtered_records = $total_records; 754 } 755 756 // Get the data 757 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching 758 $data = $wpdb->get_results( 759 $wpdb->prepare( 760 $select_query . $where_clause . $order_clause . $limit_clause, 761 ...$query_args 762 ), 763 ARRAY_A 764 ); 765 766 // Process the results 837 838 // Handle order without search 839 if ($order_column === 'umeta_id') { 840 if ($order_direction === 'desc') { 841 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching 842 $data = $wpdb->get_results( 843 $wpdb->prepare( 844 "SELECT * FROM {$wpdb->prefix}usermeta 845 ORDER BY umeta_id DESC 846 LIMIT %d, %d", 847 $start, $length 848 ), 849 ARRAY_A 850 ); 851 } else { 852 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching 853 $data = $wpdb->get_results( 854 $wpdb->prepare( 855 "SELECT * FROM {$wpdb->prefix}usermeta 856 ORDER BY umeta_id ASC 857 LIMIT %d, %d", 858 $start, $length 859 ), 860 ARRAY_A 861 ); 862 } 863 } elseif ($order_column === 'user_id') { 864 if ($order_direction === 'desc') { 865 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching 866 $data = $wpdb->get_results( 867 $wpdb->prepare( 868 "SELECT * FROM {$wpdb->prefix}usermeta 869 ORDER BY user_id DESC 870 LIMIT %d, %d", 871 $start, $length 872 ), 873 ARRAY_A 874 ); 875 } else { 876 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching 877 $data = $wpdb->get_results( 878 $wpdb->prepare( 879 "SELECT * FROM {$wpdb->prefix}usermeta 880 ORDER BY user_id ASC 881 LIMIT %d, %d", 882 $start, $length 883 ), 884 ARRAY_A 885 ); 886 } 887 } elseif ($order_column === 'meta_key') { 888 if ($order_direction === 'desc') { 889 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching 890 $data = $wpdb->get_results( 891 $wpdb->prepare( 892 "SELECT * FROM {$wpdb->prefix}usermeta 893 ORDER BY meta_key DESC 894 LIMIT %d, %d", 895 $start, $length 896 ), 897 ARRAY_A 898 ); 899 } else { 900 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching 901 $data = $wpdb->get_results( 902 $wpdb->prepare( 903 "SELECT * FROM {$wpdb->prefix}usermeta 904 ORDER BY meta_key ASC 905 LIMIT %d, %d", 906 $start, $length 907 ), 908 ARRAY_A 909 ); 910 } 911 } else { // meta_value 912 if ($order_direction === 'desc') { 913 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching 914 $data = $wpdb->get_results( 915 $wpdb->prepare( 916 "SELECT * FROM {$wpdb->prefix}usermeta 917 ORDER BY meta_value DESC 918 LIMIT %d, %d", 919 $start, $length 920 ), 921 ARRAY_A 922 ); 923 } else { 924 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching 925 $data = $wpdb->get_results( 926 $wpdb->prepare( 927 "SELECT * FROM {$wpdb->prefix}usermeta 928 ORDER BY meta_value ASC 929 LIMIT %d, %d", 930 $start, $length 931 ), 932 ARRAY_A 933 ); 934 } 935 } 936 } 937 938 // Format output 767 939 foreach ($data as &$row) { 768 // Apply proper escaping for output 769 // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_value 940 // phpcs:ignore:WordPress.DB.SlowDBQuery.slow_db_query_meta_value 770 941 $row['meta_value'] = '<div class="scrollable-cell">' . esc_html($row['meta_value']) . '</div>'; 771 772 // Add action buttons with proper escaping773 942 $row['actions'] = sprintf( 774 943 '<button class="nhrotm-edit-button-usermeta" data-id="%1$s">Edit</button> ' . … … 777 946 ); 778 947 } 779 780 // Prepare response for DataTables 948 781 949 $response = [ 782 950 "draw" => isset($_GET['draw']) ? intval($_GET['draw']) : 0, … … 785 953 "data" => $data 786 954 ]; 787 955 788 956 wp_send_json($response); 789 wp_die(); // Ensure proper termination790 } 957 wp_die(); 958 } 791 959 792 960 public function edit_usermeta() { -
nhrrob-options-table-manager/tags/1.1.4/nhrrob-options-table-manager.php
r3253999 r3254912 6 6 * Author: Nazmul Hasan Robin 7 7 * Author URI: https://profiles.wordpress.org/nhrrob/ 8 * Version: 1.1. 38 * Version: 1.1.4 9 9 * Requires at least: 6.0 10 10 * Requires PHP: 7.4 … … 28 28 * @var string 29 29 */ 30 const nhrotm_version = '1.1. 3';30 const nhrotm_version = '1.1.4'; 31 31 32 32 /** -
nhrrob-options-table-manager/tags/1.1.4/readme.txt
r3253999 r3254912 5 5 Tested up to: 6.7 6 6 Requires PHP: 7.4 7 Stable tag: 1.1. 37 Stable tag: 1.1.4 8 8 License: GPLv2 or later 9 9 License URI: https://www.gnu.org/licenses/gpl-2.0.html … … 76 76 == Changelog == 77 77 78 = 1.1.4 - 12/03/2025 = 79 - Few minor bug fixing & improvements 80 78 81 = 1.1.3 - 09/03/2025 = 79 82 - Added: Better Payment table support added -
nhrrob-options-table-manager/trunk/assets/js/admin.js
r3240675 r3254912 240 240 $( '#nhrotm-data-table-usermeta_wrapper' ).fadeOut(); 241 241 $('.nhrotm-data-table-wrap .logged-user-id').fadeOut(); 242 $('#nhrotm-data-table-better_payment_wrapper').fadeOut(); 242 243 243 244 $( '#nhrotm-data-table_wrapper' ).fadeIn(); 244 245 } else if ( $(this).hasClass('usermeta-table') ) { 245 246 $( '#nhrotm-data-table_wrapper' ).fadeOut(); 247 $('#nhrotm-data-table-better_payment_wrapper').fadeOut(); 246 248 247 249 $( '#nhrotm-data-table-usermeta_wrapper' ).fadeIn(); -
nhrrob-options-table-manager/trunk/includes/Ajax.php
r3253999 r3254912 383 383 // } 384 384 385 $option_value = ! empty( $option_value ) && is_serialized($option_value) ? maybe_unserialize($option_value) : $option_value;385 $option_value = ! empty( $option_value ) && is_serialized($option_value) ? unserialize($option_value, ['allowed_classes' => false]) : $option_value; 386 386 387 387 $response = []; … … 481 481 // } 482 482 483 if (preg_match('/O:\d+:"[^"]++":\d+:{/', $raw_option_value)) {484 wp_send_json_error('Object serialization is not allowed');485 wp_die();486 }483 // if (preg_match('/O:\d+:"[^"]++":\d+:{/', $raw_option_value)) { 484 // wp_send_json_error('Object serialization is not allowed'); 485 // wp_die(); 486 // } 487 487 488 488 $original_value = get_option($option_name); … … 490 490 491 491 $decoded_value = json_decode($raw_option_value, true); 492 $sanitized_value = ''; 493 492 494 if ($decoded_value !== null && json_last_error() === JSON_ERROR_NONE) { 493 495 $sanitized_value = $this->sanitize_array_recursive($decoded_value); 494 496 } else if (is_serialized($raw_option_value)) { 495 497 try { 496 $unserialized = maybe_unserialize($raw_option_value);498 $unserialized = unserialize($raw_option_value, ['allowed_classes' => false]); 497 499 498 500 if ($unserialized === false) { … … 501 503 } 502 504 503 if (is_array($unserialized) || is_object($unserialized)) { 505 if (is_array($unserialized) 506 || is_object($unserialized) 507 ) { 504 508 $sanitized_value = $this->sanitize_array_recursive((array)$unserialized); 505 509 } else { … … 674 678 675 679 public function usermeta_table_data() { 676 // Verify nonce 680 // Verify nonce first 677 681 if (!isset($_GET['nonce']) || !wp_verify_nonce(sanitize_text_field(wp_unslash($_GET['nonce'])), 'nhrotm-admin-nonce')) { 678 wp_send_json_error('Invalid security token'); 679 wp_die(); 680 } 681 682 // Check user capabilities 683 if (!current_user_can('manage_options')) { 684 wp_send_json_error('Insufficient permissions'); 685 wp_die(); 686 } 687 682 wp_send_json_error('Invalid nonce'); 683 wp_die(); 684 } 685 688 686 global $wpdb; 689 $table_name = $wpdb->prefix . 'usermeta'; 690 691 // Pagination parameters with defaults and validation 687 688 // Pagination parameters 692 689 $start = isset($_GET['start']) ? max(0, intval($_GET['start'])) : 0; 693 690 $length = isset($_GET['length']) ? min(max(1, intval($_GET['length'])), 100) : 10; 694 691 695 692 // Search parameter 696 693 $search = isset($_GET['search']['value']) ? sanitize_text_field(wp_unslash($_GET['search']['value'])) : ''; 697 694 698 695 // Sorting parameters 699 696 $order_column_index = isset($_GET['order'][0]['column']) ? intval($_GET['order'][0]['column']) : 0; 700 $order_direction = isset($_GET['order'][0]['dir']) && in_array($_GET['order'][0]['dir'], ['asc', 'desc']) 701 ? strtolower(sanitize_text_field(wp_unslash($_GET['order'][0]['dir']))) 702 : 'asc'; 703 704 // Define columns in the correct order for sorting with DB column mapping 705 $columns = [ 706 'umeta_id', 707 'user_id', 708 'meta_key', 709 'meta_value' 710 ]; 711 712 // Ensure order column is valid 713 $order_column = isset($columns[$order_column_index]) ? $columns[$order_column_index] : 'umeta_id'; 714 715 // Base query parts 716 $select_query = "SELECT * FROM {$wpdb->prefix}usermeta"; 717 $count_query = "SELECT COUNT(*) FROM {$wpdb->prefix}usermeta"; 718 719 // Apply search filter if provided 720 $where_clause = ''; 721 $query_args = []; 722 697 $order_direction = isset($_GET['order'][0]['dir']) && in_array($_GET['order'][0]['dir'], ['asc', 'desc']) ? 698 strtolower(sanitize_text_field(wp_unslash($_GET['order'][0]['dir']))) : 'asc'; 699 700 // Define valid columns for usermeta table 701 $columns = ['umeta_id', 'user_id', 'meta_key', 'meta_value']; 702 703 // Validate order column 704 if ($order_column_index < 0 || $order_column_index >= count($columns)) { 705 $order_column_index = 0; 706 } 707 $order_column = $columns[$order_column_index]; 708 709 // Total records count 710 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching 711 $total_records = $wpdb->get_var( 712 "SELECT COUNT(*) FROM {$wpdb->prefix}usermeta" 713 ); 714 715 // Main query logic 723 716 if (!empty($search)) { 724 $where_clause = " WHERE meta_key LIKE %s OR meta_value LIKE %s";725 717 $search_like = '%' . $wpdb->esc_like($search) . '%'; 726 $query_args[] = $search_like; 727 $query_args[] = $search_like; 728 } 729 730 // Add order clause 731 $order_clause = " ORDER BY {$order_column} {$order_direction}"; 732 733 // Add limit clause 734 $limit_clause = " LIMIT %d, %d"; 735 $query_args[] = $start; 736 $query_args[] = $length; 737 738 // Get total records without filtering 739 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching 740 $total_records = $wpdb->get_var($count_query); 741 742 // Get filtered records count 743 if (!empty($where_clause)) { 718 744 719 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching 745 720 $filtered_records = $wpdb->get_var( 746 721 $wpdb->prepare( 747 $count_query . $where_clause, 748 $query_args[0], 749 $query_args[1] 722 "SELECT COUNT(*) FROM {$wpdb->prefix}usermeta 723 WHERE meta_key LIKE %s OR meta_value LIKE %s", 724 $search_like, 725 $search_like 750 726 ) 751 727 ); 728 729 // Handle order with complete prepared statements 730 if ($order_column === 'umeta_id') { 731 if ($order_direction === 'desc') { 732 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching 733 $data = $wpdb->get_results( 734 $wpdb->prepare( 735 "SELECT * FROM {$wpdb->prefix}usermeta 736 WHERE meta_key LIKE %s OR meta_value LIKE %s 737 ORDER BY umeta_id DESC 738 LIMIT %d, %d", 739 $search_like, $search_like, $start, $length 740 ), 741 ARRAY_A 742 ); 743 } else { 744 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching 745 $data = $wpdb->get_results( 746 $wpdb->prepare( 747 "SELECT * FROM {$wpdb->prefix}usermeta 748 WHERE meta_key LIKE %s OR meta_value LIKE %s 749 ORDER BY umeta_id ASC 750 LIMIT %d, %d", 751 $search_like, $search_like, $start, $length 752 ), 753 ARRAY_A 754 ); 755 } 756 } elseif ($order_column === 'user_id') { 757 if ($order_direction === 'desc') { 758 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching 759 $data = $wpdb->get_results( 760 $wpdb->prepare( 761 "SELECT * FROM {$wpdb->prefix}usermeta 762 WHERE meta_key LIKE %s OR meta_value LIKE %s 763 ORDER BY user_id DESC 764 LIMIT %d, %d", 765 $search_like, $search_like, $start, $length 766 ), 767 ARRAY_A 768 ); 769 } else { 770 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching 771 $data = $wpdb->get_results( 772 $wpdb->prepare( 773 "SELECT * FROM {$wpdb->prefix}usermeta 774 WHERE meta_key LIKE %s OR meta_value LIKE %s 775 ORDER BY user_id ASC 776 LIMIT %d, %d", 777 $search_like, $search_like, $start, $length 778 ), 779 ARRAY_A 780 ); 781 } 782 } elseif ($order_column === 'meta_key') { 783 if ($order_direction === 'desc') { 784 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching 785 $data = $wpdb->get_results( 786 $wpdb->prepare( 787 "SELECT * FROM {$wpdb->prefix}usermeta 788 WHERE meta_key LIKE %s OR meta_value LIKE %s 789 ORDER BY meta_key DESC 790 LIMIT %d, %d", 791 $search_like, $search_like, $start, $length 792 ), 793 ARRAY_A 794 ); 795 } else { 796 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching 797 $data = $wpdb->get_results( 798 $wpdb->prepare( 799 "SELECT * FROM {$wpdb->prefix}usermeta 800 WHERE meta_key LIKE %s OR meta_value LIKE %s 801 ORDER BY meta_key ASC 802 LIMIT %d, %d", 803 $search_like, $search_like, $start, $length 804 ), 805 ARRAY_A 806 ); 807 } 808 } else { // meta_value 809 if ($order_direction === 'desc') { 810 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching 811 $data = $wpdb->get_results( 812 $wpdb->prepare( 813 "SELECT * FROM {$wpdb->prefix}usermeta 814 WHERE meta_key LIKE %s OR meta_value LIKE %s 815 ORDER BY meta_value DESC 816 LIMIT %d, %d", 817 $search_like, $search_like, $start, $length 818 ), 819 ARRAY_A 820 ); 821 } else { 822 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching 823 $data = $wpdb->get_results( 824 $wpdb->prepare( 825 "SELECT * FROM {$wpdb->prefix}usermeta 826 WHERE meta_key LIKE %s OR meta_value LIKE %s 827 ORDER BY meta_value ASC 828 LIMIT %d, %d", 829 $search_like, $search_like, $start, $length 830 ), 831 ARRAY_A 832 ); 833 } 834 } 752 835 } else { 753 836 $filtered_records = $total_records; 754 } 755 756 // Get the data 757 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching 758 $data = $wpdb->get_results( 759 $wpdb->prepare( 760 $select_query . $where_clause . $order_clause . $limit_clause, 761 ...$query_args 762 ), 763 ARRAY_A 764 ); 765 766 // Process the results 837 838 // Handle order without search 839 if ($order_column === 'umeta_id') { 840 if ($order_direction === 'desc') { 841 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching 842 $data = $wpdb->get_results( 843 $wpdb->prepare( 844 "SELECT * FROM {$wpdb->prefix}usermeta 845 ORDER BY umeta_id DESC 846 LIMIT %d, %d", 847 $start, $length 848 ), 849 ARRAY_A 850 ); 851 } else { 852 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching 853 $data = $wpdb->get_results( 854 $wpdb->prepare( 855 "SELECT * FROM {$wpdb->prefix}usermeta 856 ORDER BY umeta_id ASC 857 LIMIT %d, %d", 858 $start, $length 859 ), 860 ARRAY_A 861 ); 862 } 863 } elseif ($order_column === 'user_id') { 864 if ($order_direction === 'desc') { 865 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching 866 $data = $wpdb->get_results( 867 $wpdb->prepare( 868 "SELECT * FROM {$wpdb->prefix}usermeta 869 ORDER BY user_id DESC 870 LIMIT %d, %d", 871 $start, $length 872 ), 873 ARRAY_A 874 ); 875 } else { 876 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching 877 $data = $wpdb->get_results( 878 $wpdb->prepare( 879 "SELECT * FROM {$wpdb->prefix}usermeta 880 ORDER BY user_id ASC 881 LIMIT %d, %d", 882 $start, $length 883 ), 884 ARRAY_A 885 ); 886 } 887 } elseif ($order_column === 'meta_key') { 888 if ($order_direction === 'desc') { 889 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching 890 $data = $wpdb->get_results( 891 $wpdb->prepare( 892 "SELECT * FROM {$wpdb->prefix}usermeta 893 ORDER BY meta_key DESC 894 LIMIT %d, %d", 895 $start, $length 896 ), 897 ARRAY_A 898 ); 899 } else { 900 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching 901 $data = $wpdb->get_results( 902 $wpdb->prepare( 903 "SELECT * FROM {$wpdb->prefix}usermeta 904 ORDER BY meta_key ASC 905 LIMIT %d, %d", 906 $start, $length 907 ), 908 ARRAY_A 909 ); 910 } 911 } else { // meta_value 912 if ($order_direction === 'desc') { 913 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching 914 $data = $wpdb->get_results( 915 $wpdb->prepare( 916 "SELECT * FROM {$wpdb->prefix}usermeta 917 ORDER BY meta_value DESC 918 LIMIT %d, %d", 919 $start, $length 920 ), 921 ARRAY_A 922 ); 923 } else { 924 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching 925 $data = $wpdb->get_results( 926 $wpdb->prepare( 927 "SELECT * FROM {$wpdb->prefix}usermeta 928 ORDER BY meta_value ASC 929 LIMIT %d, %d", 930 $start, $length 931 ), 932 ARRAY_A 933 ); 934 } 935 } 936 } 937 938 // Format output 767 939 foreach ($data as &$row) { 768 // Apply proper escaping for output 769 // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_value 940 // phpcs:ignore:WordPress.DB.SlowDBQuery.slow_db_query_meta_value 770 941 $row['meta_value'] = '<div class="scrollable-cell">' . esc_html($row['meta_value']) . '</div>'; 771 772 // Add action buttons with proper escaping773 942 $row['actions'] = sprintf( 774 943 '<button class="nhrotm-edit-button-usermeta" data-id="%1$s">Edit</button> ' . … … 777 946 ); 778 947 } 779 780 // Prepare response for DataTables 948 781 949 $response = [ 782 950 "draw" => isset($_GET['draw']) ? intval($_GET['draw']) : 0, … … 785 953 "data" => $data 786 954 ]; 787 955 788 956 wp_send_json($response); 789 wp_die(); // Ensure proper termination790 } 957 wp_die(); 958 } 791 959 792 960 public function edit_usermeta() { -
nhrrob-options-table-manager/trunk/nhrrob-options-table-manager.php
r3253999 r3254912 6 6 * Author: Nazmul Hasan Robin 7 7 * Author URI: https://profiles.wordpress.org/nhrrob/ 8 * Version: 1.1. 38 * Version: 1.1.4 9 9 * Requires at least: 6.0 10 10 * Requires PHP: 7.4 … … 28 28 * @var string 29 29 */ 30 const nhrotm_version = '1.1. 3';30 const nhrotm_version = '1.1.4'; 31 31 32 32 /** -
nhrrob-options-table-manager/trunk/readme.txt
r3253999 r3254912 5 5 Tested up to: 6.7 6 6 Requires PHP: 7.4 7 Stable tag: 1.1. 37 Stable tag: 1.1.4 8 8 License: GPLv2 or later 9 9 License URI: https://www.gnu.org/licenses/gpl-2.0.html … … 76 76 == Changelog == 77 77 78 = 1.1.4 - 12/03/2025 = 79 - Few minor bug fixing & improvements 80 78 81 = 1.1.3 - 09/03/2025 = 79 82 - Added: Better Payment table support added
Note: See TracChangeset
for help on using the changeset viewer.