Changeset 22723 for trunk/wp-admin/includes/ajax-actions.php
- Timestamp:
- 11/20/2012 06:50:15 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/includes/ajax-actions.php
r22653 r22723 1422 1422 check_ajax_referer( 'find-posts' ); 1423 1423 1424 if ( empty($_POST['ps']) ) 1425 wp_die(); 1426 1427 if ( !empty($_POST['post_type']) && in_array( $_POST['post_type'], get_post_types() ) ) 1428 $what = $_POST['post_type']; 1429 else 1430 $what = 'post'; 1431 1432 $s = stripslashes($_POST['ps']); 1433 preg_match_all('/".*?("|$)|((?<=[\\s",+])|^)[^\\s",+]+/', $s, $matches); 1434 $search_terms = array_map('_search_terms_tidy', $matches[0]); 1435 1424 $post_types = get_post_types( array( 'public' => true ), 'objects' ); 1425 unset( $post_types['attachment'] ); 1426 1427 $s = stripslashes( $_POST['ps'] ); 1436 1428 $searchand = $search = ''; 1437 foreach ( (array) $search_terms as $term ) { 1438 $term = esc_sql( like_escape( $term ) ); 1439 $search .= "{$searchand}(($wpdb->posts.post_title LIKE '%{$term}%') OR ($wpdb->posts.post_content LIKE '%{$term}%'))"; 1440 $searchand = ' AND '; 1441 } 1442 $term = esc_sql( like_escape( $s ) ); 1443 if ( count($search_terms) > 1 && $search_terms[0] != $s ) 1444 $search .= " OR ($wpdb->posts.post_title LIKE '%{$term}%') OR ($wpdb->posts.post_content LIKE '%{$term}%')"; 1445 1446 $posts = $wpdb->get_results( "SELECT ID, post_title, post_status, post_date FROM $wpdb->posts WHERE post_type = '$what' AND post_status IN ('draft', 'publish') AND ($search) ORDER BY post_date_gmt DESC LIMIT 50" ); 1447 1448 if ( ! $posts ) { 1449 $posttype = get_post_type_object($what); 1450 wp_die( $posttype->labels->not_found ); 1451 } 1452 1453 $html = '<table class="widefat" cellspacing="0"><thead><tr><th class="found-radio"><br /></th><th>'.__('Title').'</th><th>'.__('Date').'</th><th>'.__('Status').'</th></tr></thead><tbody>'; 1429 $args = array( 1430 'post_type' => array_keys( $post_types ), 1431 'post_status' => 'any', 1432 'posts_per_page' => 50, 1433 ); 1434 if ( '' !== $s ) 1435 $args['s'] = $s; 1436 1437 $posts = get_posts( $args ); 1438 1439 if ( ! $posts ) 1440 wp_die( __('No items found.') ); 1441 1442 $html = '<table class="widefat" cellspacing="0"><thead><tr><th class="found-radio"><br /></th><th>'.__('Title').'</th><th class="no-break">'.__('Type').'</th><th class="no-break">'.__('Date').'</th><th class="no-break">'.__('Status').'</th></tr></thead><tbody>'; 1454 1443 foreach ( $posts as $post ) { 1444 $title = trim( $post->post_title ) ? $post->post_title : __( '(no title)' ); 1455 1445 1456 1446 switch ( $post->post_status ) { … … 1478 1468 1479 1469 $html .= '<tr class="found-posts"><td class="found-radio"><input type="radio" id="found-'.$post->ID.'" name="found_post_id" value="' . esc_attr($post->ID) . '"></td>'; 1480 $html .= '<td><label for="found-'.$post->ID.'">'.esc_html( $post->post_title ).'</label></td><td>'.esc_html( $time ).'</td><td>'.esc_html( $stat ).'</td></tr>'."\n\n"; 1481 } 1470 $html .= '<td><label for="found-'.$post->ID.'">' . esc_html( $title ) . '</label></td><td class="no-break">' . esc_html( $post_types[$post->post_type]->labels->singular_name ) . '</td><td class="no-break">'.esc_html( $time ) . '</td><td class="no-break">' . esc_html( $stat ). ' </td></tr>' . "\n\n"; 1471 } 1472 1482 1473 $html .= '</tbody></table>'; 1483 1474 1484 1475 $x = new WP_Ajax_Response(); 1485 1476 $x->add( array( 1486 'what' => $what,1487 1477 'data' => $html 1488 1478 )); 1489 1479 $x->send(); 1490 1491 1480 } 1492 1481
Note: See TracChangeset
for help on using the changeset viewer.