mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-12-06 12:51:58 +00:00
Fix up the 'Attach' dialog on upload.php.
We are de-emphasising attaching (see [22630]) but this is existing core functionality and will remain for now. This commit just cleans it up a bit so as to be less embarrassing. props lessbloat, helenyhou. fixes #20164. git-svn-id: https://develop.svn.wordpress.org/trunk@22723 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -1421,37 +1421,27 @@ function wp_ajax_find_posts() {
|
||||
|
||||
check_ajax_referer( 'find-posts' );
|
||||
|
||||
if ( empty($_POST['ps']) )
|
||||
wp_die();
|
||||
|
||||
if ( !empty($_POST['post_type']) && in_array( $_POST['post_type'], get_post_types() ) )
|
||||
$what = $_POST['post_type'];
|
||||
else
|
||||
$what = 'post';
|
||||
|
||||
$s = stripslashes($_POST['ps']);
|
||||
preg_match_all('/".*?("|$)|((?<=[\\s",+])|^)[^\\s",+]+/', $s, $matches);
|
||||
$search_terms = array_map('_search_terms_tidy', $matches[0]);
|
||||
$post_types = get_post_types( array( 'public' => true ), 'objects' );
|
||||
unset( $post_types['attachment'] );
|
||||
|
||||
$s = stripslashes( $_POST['ps'] );
|
||||
$searchand = $search = '';
|
||||
foreach ( (array) $search_terms as $term ) {
|
||||
$term = esc_sql( like_escape( $term ) );
|
||||
$search .= "{$searchand}(($wpdb->posts.post_title LIKE '%{$term}%') OR ($wpdb->posts.post_content LIKE '%{$term}%'))";
|
||||
$searchand = ' AND ';
|
||||
}
|
||||
$term = esc_sql( like_escape( $s ) );
|
||||
if ( count($search_terms) > 1 && $search_terms[0] != $s )
|
||||
$search .= " OR ($wpdb->posts.post_title LIKE '%{$term}%') OR ($wpdb->posts.post_content LIKE '%{$term}%')";
|
||||
$args = array(
|
||||
'post_type' => array_keys( $post_types ),
|
||||
'post_status' => 'any',
|
||||
'posts_per_page' => 50,
|
||||
);
|
||||
if ( '' !== $s )
|
||||
$args['s'] = $s;
|
||||
|
||||
$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" );
|
||||
$posts = get_posts( $args );
|
||||
|
||||
if ( ! $posts ) {
|
||||
$posttype = get_post_type_object($what);
|
||||
wp_die( $posttype->labels->not_found );
|
||||
}
|
||||
if ( ! $posts )
|
||||
wp_die( __('No items found.') );
|
||||
|
||||
$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>';
|
||||
$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>';
|
||||
foreach ( $posts as $post ) {
|
||||
$title = trim( $post->post_title ) ? $post->post_title : __( '(no title)' );
|
||||
|
||||
switch ( $post->post_status ) {
|
||||
case 'publish' :
|
||||
@@ -1477,17 +1467,16 @@ function wp_ajax_find_posts() {
|
||||
}
|
||||
|
||||
$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>';
|
||||
$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";
|
||||
$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";
|
||||
}
|
||||
|
||||
$html .= '</tbody></table>';
|
||||
|
||||
$x = new WP_Ajax_Response();
|
||||
$x->add( array(
|
||||
'what' => $what,
|
||||
'data' => $html
|
||||
));
|
||||
$x->send();
|
||||
|
||||
}
|
||||
|
||||
function wp_ajax_widgets_order() {
|
||||
|
||||
@@ -1278,18 +1278,8 @@ function find_posts_div($found_action = '') {
|
||||
<?php wp_nonce_field( 'find-posts', '_ajax_nonce', false ); ?>
|
||||
<label class="screen-reader-text" for="find-posts-input"><?php _e( 'Search' ); ?></label>
|
||||
<input type="text" id="find-posts-input" name="ps" value="" />
|
||||
<input type="button" id="find-posts-search" value="<?php esc_attr_e( 'Search' ); ?>" class="button" /><br />
|
||||
|
||||
<?php
|
||||
$post_types = get_post_types( array('public' => true), 'objects' );
|
||||
foreach ( $post_types as $post ) {
|
||||
if ( 'attachment' == $post->name )
|
||||
continue;
|
||||
?>
|
||||
<input type="radio" name="find-posts-what" id="find-posts-<?php echo esc_attr($post->name); ?>" value="<?php echo esc_attr($post->name); ?>" <?php checked($post->name, 'post'); ?> />
|
||||
<label for="find-posts-<?php echo esc_attr($post->name); ?>"><?php echo $post->label; ?></label>
|
||||
<?php
|
||||
} ?>
|
||||
<span class="spinner"></span>
|
||||
<input type="button" id="find-posts-search" value="<?php esc_attr_e( 'Search' ); ?>" class="button" />
|
||||
</div>
|
||||
<div id="find-posts-response"></div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user