Changeset 13522 for sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/admin/class-customizations.php
- Timestamp:
- 04/15/2024 06:59:14 AM (8 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/admin/class-customizations.php
r13512 r13522 35 35 add_filter( 'query_vars', array( $this, 'query_vars' ) ); 36 36 add_action( 'pre_get_posts', array( $this, 'pre_get_posts' ) ); 37 add_filter( 'posts_search', array( $this, 'posts_search' ), 10, 2 ); 37 38 38 39 add_action( 'load-edit.php', array( $this, 'bulk_action_plugins' ) ); … … 263 264 $query->set( 'meta_query', $meta_query ); 264 265 } 266 } 267 268 /** 269 * Filter searches to search by slug in wp-admin. 270 * 271 * WP_Query::parse_search() doesn't allow specifying the post_name field as a searchable field. 272 * 273 * @param string $where The WHERE clause of the search query. 274 * @param \WP_Query $wp_query The WP_Query object. 275 * @return string The WHERE clause of the query. 276 */ 277 public function posts_search( $where, $wp_query ) { 278 global $wpdb; 279 280 if ( ! $where || ! $wp_query->is_main_query() || ! $wp_query->is_search() ) { 281 return $where; 282 } 283 284 // WP_Query::parse_search() is protected, so we'll just do a poor job of it here. 285 $custom_or = $wpdb->prepare( 286 "( {$wpdb->posts}.post_name LIKE %s )", 287 '%' . $wpdb->esc_like( $wp_query->get( 's' ) ) . '%' 288 ); 289 290 // Merge the custom column search into the existing search SQL. 291 $where = preg_replace( '#^(\s*AND\s*)(.+)$#i', ' AND ( $2 OR ' . $custom_or . ' )', $where ); 292 293 return $where; 265 294 } 266 295
Note: See TracChangeset
for help on using the changeset viewer.