Changeset 14147 for sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-login/admin/class-user-registrations-list-table.php
- Timestamp:
- 10/25/2024 02:40:52 AM (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-login/admin/class-user-registrations-list-table.php
r13842 r14147 40 40 ]; 41 41 42 $default = 'all'; 43 $current_view = $_REQUEST['view'] ?? $default; 42 $current_view = $this->get_current_view(); 44 43 45 44 if ( ! empty( $_GET['s'] ) ) { 46 $default = 'search';47 45 $views[0] = [ 48 46 'search', 'All search results' … … 50 48 51 49 array_unshift( $views, [ 'all', 'All' ] ); 52 53 if ( 'all' === $current_view ) {54 $current_view = 'search';55 }56 50 } 57 51 … … 60 54 global $wpdb; 61 55 62 $count = $wpdb->get_var( 63 "SELECT count(*) FROM {$wpdb->base_prefix}user_pending_registrations registrations " . 64 $this->get_join_where_sql( $item[0] ) 65 ); 56 $view = $item[0]; 57 $is_search = ( ! empty( $_GET['s'] ) && 'all' != $view ); 58 59 // If we're searching, and the search didn't have any results, all the "sub views" are 0. 60 if ( $is_search && ! $this->get_view_total_count( 'search' ) ) { 61 $count = 0; 62 } else { 63 $count = $this->get_view_total_count( $view ); 64 } 66 65 67 66 $url = admin_url( 'admin.php?page=user-registrations' ); 68 if ( !empty( $_GET['s'] ) && 'all' != $item[0]) {69 $url = add_query_arg( 's', urlencode( $_GET['s']), $url );67 if ( $is_search ) { 68 $url = add_query_arg( 's', urlencode( wp_unslash( $_GET['s'] ) ), $url ); 70 69 } 71 70 72 if ( 'all' !== $ item[0]) {73 $url = add_query_arg( 'view', $ item[0], $url );71 if ( 'all' !== $view ) { 72 $url = add_query_arg( 'view', $view, $url ); 74 73 } 75 74 … … 77 76 '<a href="%s" class="%s">%s <span class="count">(%s)</span></a>', 78 77 $url, 79 $current_view === $ item[0]? 'current' : '',78 $current_view === $view ? 'current' : '', 80 79 $item[1], 81 80 number_format_i18n( $count ), … … 85 84 } 86 85 86 /** 87 * Get the current view to display. 88 * 89 * @return string 90 */ 91 protected function get_current_view() { 92 $view = $_REQUEST['view'] ?? false; 93 if ( ! $view ) { 94 $view = 'all'; 95 if ( ! empty( $_GET['s'] ) ) { 96 $view = 'search'; 97 } 98 } 99 100 if ( 'all' === $view && ! empty( $_GET['s'] ) ) { 101 $view = 'search'; 102 } 103 104 return $view; 105 } 106 107 /** 108 * Get the total count for a given view. 109 * 110 * @param string $view The view to get the count for. 111 * @return int 112 */ 113 protected function get_view_total_count( $view ) { 114 global $wpdb; 115 static $counts = []; 116 117 // Search view has no results if no search term... 118 if ( 'search' === $view && empty( $_GET['s'] ) ) { 119 return 0; 120 } 121 122 $current_view = $this->get_current_view(); 123 if ( $view === $current_view ) { 124 return $this->get_pagination_arg( 'total_items' ); 125 } 126 127 $counts[ $view ] ??= $wpdb->get_var( 128 "SELECT count(*) FROM {$wpdb->base_prefix}user_pending_registrations registrations " . 129 $this->get_join_where_sql( $view ) 130 ); 131 132 return $counts[ $view ]; 133 } 134 135 /** 136 * Get the SQL WHERE clause for a given view. 137 * 138 * @param string $view The view to get the WHERE clause for. 139 * @return string 140 */ 87 141 protected function get_view_sql_where( $view ) { 88 142 switch ( $view ) { … … 109 163 } 110 164 165 /** 166 * Get the SQL JOIN and WHERE clause for a given view. 167 * 168 * @param string $view The view to get the JOIN and WHERE clause for. 169 * @return string 170 */ 111 171 protected function get_join_where_sql( $view = null ) { 112 172 global $wpdb; … … 124 184 // Limit searches to where they're likely, for performance. 125 185 if ( str_contains( $search_term, '@' ) ) { 126 // Looks like an email, so just search the emails. 127 $where .= $wpdb->prepare( 128 "AND registrations.user_email LIKE %s", 129 $search_like 130 ); 186 // If it looks like a full email, exact match. 187 if ( preg_match( '/^.{3,}@.+[.].+$/', $search_term ) ) { 188 // Looks like an email, so just search the emails. 189 $where .= $wpdb->prepare( 190 "AND registrations.user_email = %s", 191 $search_term 192 ); 193 } else { 194 // Otherwise, a wildcard on the email. 195 $where .= $wpdb->prepare( 196 "AND registrations.user_email LIKE %s", 197 $search_like 198 ); 199 } 131 200 } elseif ( 132 201 // If it looks like an IP 133 202 preg_match( '/^\d{1,3}\.[0-9.]*$/', $search_term ) || 134 203 // Or it looks like a country code, 135 preg_match( '/^[A-Z]{2} /', $search_term )204 preg_match( '/^[A-Z]{2}$/', $search_term ) 136 205 ) { 137 // then only look in metadata .206 // then only look in metadata, case sensitive. 138 207 $where .= $wpdb->prepare( 139 "AND registrations.meta LIKE %s",140 $search_like208 "AND registrations.meta LIKE BINARY %s", 209 '%"' . $wpdb->esc_like( $search_term ) . '%' // Anchor it with a " at the start of the field. 141 210 ); 142 211 } else {
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)