Fix pagination on the Unattached tab in the media library, show Attach in the "Attached to" column for orphan attachments
git-svn-id: https://develop.svn.wordpress.org/trunk@12196 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
51f2c4d17d
commit
3f51751c4d
|
@ -1215,12 +1215,12 @@ case 'find_posts':
|
|||
if ( count($search_terms) > 1 && $search_terms[0] != $s )
|
||||
$search .= " OR ($wpdb->posts.post_title LIKE '%{$term}%') OR ($wpdb->posts.post_content LIKE '%{$term}%')";
|
||||
|
||||
$posts = $wpdb->get_results( "SELECT ID, post_title, post_status, post_date FROM $wpdb->posts WHERE post_type = '$what' AND $search ORDER BY post_date_gmt DESC LIMIT 50" );
|
||||
$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" );
|
||||
|
||||
if ( ! $posts )
|
||||
exit( __('No posts found.') );
|
||||
|
||||
$html = '<table class="widefat" cellspacing="0"><thead><tr><th class="found-radio"><br /></th><th>'.__('Title').'</th><th>'.__('Time').'</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>'.__('Date').'</th><th>'.__('Status').'</th></tr></thead><tbody>';
|
||||
foreach ( $posts as $post ) {
|
||||
|
||||
switch ( $post->post_status ) {
|
||||
|
@ -1235,7 +1235,7 @@ case 'find_posts':
|
|||
$stat = __('Pending Review');
|
||||
break;
|
||||
case 'draft' :
|
||||
$stat = __('Unpublished');
|
||||
$stat = __('Draft');
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
@ -173,7 +173,8 @@ foreach ($posts_columns as $column_name => $column_display_name ) {
|
|||
<?php
|
||||
} else {
|
||||
?>
|
||||
<td <?php echo $attributes ?>> </td>
|
||||
<td <?php echo $attributes ?>><?php _e('(Unattached)'); ?><br />
|
||||
<a class="hide-if-no-js" onclick="findPosts.open('media[]','<?php echo $post->ID ?>');return false;" href="#the-list"><?php _e('Attach'); ?></a></td>
|
||||
<?php
|
||||
}
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@ var findPosts;
|
|||
_ajax_nonce: $('#_ajax_nonce').val()
|
||||
};
|
||||
|
||||
if ( $('#find-posts-pages:checked').val() ) {
|
||||
if ( $('#find-posts-pages').is(':checked') ) {
|
||||
post['pages'] = 1;
|
||||
} else {
|
||||
post['posts'] = 1;
|
||||
|
|
|
@ -1 +1 @@
|
|||
var findPosts;(function(a){findPosts={open:function(d,c){var b=document.documentElement.scrollTop||a(document).scrollTop();if(d&&c){a("#affected").attr("name",d).val(c)}a("#find-posts").show().draggable({handle:"#find-posts-head"}).css({top:b+50+"px",left:"50%",marginLeft:"-250px"});a("#find-posts-input").focus().keyup(function(f){if(f.which==27){findPosts.close()}});return false},close:function(){a("#find-posts-response").html("");a("#find-posts").draggable("destroy").hide()},send:function(){var b={ps:a("#find-posts-input").val(),action:"find_posts",_ajax_nonce:a("#_ajax_nonce").val()};if(a("#find-posts-pages:checked").val()){b.pages=1}else{b.posts=1}a.ajax({type:"POST",url:ajaxurl,data:b,success:function(c){findPosts.show(c)},error:function(c){findPosts.error(c)}})},show:function(b){if(typeof(b)=="string"){this.error({responseText:b});return}var c=wpAjax.parseAjaxResponse(b);if(c.errors){this.error({responseText:wpAjax.broken})}c=c.responses[0];a("#find-posts-response").html(c.data)},error:function(b){var c=b.statusText;if(b.responseText){c=b.responseText.replace(/<.[^<>]*?>/g,"")}if(c){a("#find-posts-response").html(c)}}};a(document).ready(function(){a("#find-posts-submit").click(function(b){if(""==a("#find-posts-response").html()){b.preventDefault()}});a("#doaction, #doaction2").click(function(b){a('select[name^="action"]').each(function(){if(a(this).val()=="attach"){b.preventDefault();findPosts.open()}})})})})(jQuery);
|
||||
var findPosts;(function(a){findPosts={open:function(d,c){var b=document.documentElement.scrollTop||a(document).scrollTop();if(d&&c){a("#affected").attr("name",d).val(c)}a("#find-posts").show().draggable({handle:"#find-posts-head"}).css({top:b+50+"px",left:"50%",marginLeft:"-250px"});a("#find-posts-input").focus().keyup(function(f){if(f.which==27){findPosts.close()}});return false},close:function(){a("#find-posts-response").html("");a("#find-posts").draggable("destroy").hide()},send:function(){var b={ps:a("#find-posts-input").val(),action:"find_posts",_ajax_nonce:a("#_ajax_nonce").val()};if(a("#find-posts-pages").is(":checked")){b.pages=1}else{b.posts=1}a.ajax({type:"POST",url:ajaxurl,data:b,success:function(c){findPosts.show(c)},error:function(c){findPosts.error(c)}})},show:function(b){if(typeof(b)=="string"){this.error({responseText:b});return}var c=wpAjax.parseAjaxResponse(b);if(c.errors){this.error({responseText:wpAjax.broken})}c=c.responses[0];a("#find-posts-response").html(c.data)},error:function(b){var c=b.statusText;if(b.responseText){c=b.responseText.replace(/<.[^<>]*?>/g,"")}if(c){a("#find-posts-response").html(c)}}};a(document).ready(function(){a("#find-posts-submit").click(function(b){if(""==a("#find-posts-response").html()){b.preventDefault()}});a("#doaction, #doaction2").click(function(b){a('select[name^="action"]').each(function(){if(a(this).val()=="attach"){b.preventDefault();findPosts.open()}})})})})(jQuery);
|
|
@ -62,7 +62,7 @@ if ( isset($_GET['find_detached']) ) {
|
|||
$location = $referer;
|
||||
}
|
||||
|
||||
$location = add_query_arg( array( 'detached' => 1, 'attached' => $attached ) , $location );
|
||||
$location = add_query_arg( array( 'attached' => $attached ) , $location );
|
||||
wp_redirect($location);
|
||||
exit;
|
||||
}
|
||||
|
@ -76,13 +76,14 @@ if ( isset($_GET['find_detached']) ) {
|
|||
} elseif ( ( $_GET['action'] != -1 || $_GET['action2'] != -1 ) && ( isset($_GET['media']) || isset($_GET['ids']) ) ) {
|
||||
$post_ids = isset($_GET['media']) ? $_GET['media'] : explode(',', $_GET['ids']);
|
||||
$doaction = ($_GET['action'] != -1) ? $_GET['action'] : $_GET['action2'];
|
||||
} else
|
||||
} else {
|
||||
wp_redirect($_SERVER['HTTP_REFERER']);
|
||||
}
|
||||
|
||||
$location = 'upload.php';
|
||||
if ( $referer = wp_get_referer() ) {
|
||||
if ( false !== strpos($referer, 'upload.php') )
|
||||
$location = remove_query_arg( array('trashed', 'untrashed', 'deleted', 'message', 'ids'), $referer );
|
||||
$location = remove_query_arg( array('trashed', 'untrashed', 'deleted', 'message', 'ids', 'posted'), $referer );
|
||||
}
|
||||
|
||||
switch ( $doaction ) {
|
||||
|
@ -118,7 +119,6 @@ if ( isset($_GET['find_detached']) ) {
|
|||
break;
|
||||
}
|
||||
|
||||
$location = remove_query_arg('posted', $location);
|
||||
wp_redirect($location);
|
||||
exit;
|
||||
} elseif ( isset($_GET['_wp_http_referer']) && ! empty($_GET['_wp_http_referer']) ) {
|
||||
|
@ -134,16 +134,20 @@ if ( ! isset( $_GET['paged'] ) || $_GET['paged'] < 1 )
|
|||
|
||||
if ( isset($_GET['detached']) ) {
|
||||
|
||||
$media_per_page = (int) get_user_option('upload_per_page');
|
||||
if ( empty($media_per_page) )
|
||||
$media_per_page = 20;
|
||||
|
||||
if ( !empty($lost) ) {
|
||||
$start = ( $_GET['paged'] - 1 ) * 50;
|
||||
$page_links_total = ceil(count($lost) / 50);
|
||||
$start = ( (int) $_GET['paged'] - 1 ) * $media_per_page;
|
||||
$page_links_total = ceil(count($lost) / $media_per_page);
|
||||
$lost = implode(',', $lost);
|
||||
|
||||
$orphans = $wpdb->get_results( "SELECT * FROM $wpdb->posts WHERE post_type = 'attachment' AND ID IN ($lost) LIMIT $start, 50" );
|
||||
$orphans = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $wpdb->posts WHERE post_type = 'attachment' AND ID IN (%s) LIMIT %d, %d", $lost, $start, $media_per_page ) );
|
||||
} else {
|
||||
$start = ( $_GET['paged'] - 1 ) * 25;
|
||||
$orphans = $wpdb->get_results( "SELECT SQL_CALC_FOUND_ROWS * FROM $wpdb->posts WHERE post_type = 'attachment' AND post_status != 'trash' AND post_parent < 1 LIMIT $start, 25" );
|
||||
$page_links_total = ceil($wpdb->get_var( "SELECT FOUND_ROWS()" ) / 25);
|
||||
$start = ( (int) $_GET['paged'] - 1 ) * $media_per_page;
|
||||
$orphans = $wpdb->get_results( $wpdb->prepare( "SELECT SQL_CALC_FOUND_ROWS * FROM $wpdb->posts WHERE post_type = 'attachment' AND post_status != 'trash' AND post_parent < 1 LIMIT %d, %d", $start, $media_per_page ) );
|
||||
$page_links_total = ceil($wpdb->get_var( "SELECT FOUND_ROWS()" ) / $media_per_page);
|
||||
}
|
||||
|
||||
$post_mime_types = get_post_mime_types();
|
||||
|
@ -429,7 +433,7 @@ foreach ($arc_result as $arc_row) {
|
|||
</tbody>
|
||||
</table>
|
||||
|
||||
<?php find_posts_div();
|
||||
<?php
|
||||
|
||||
} else {
|
||||
include( 'edit-attachment-rows.php' );
|
||||
|
@ -466,6 +470,7 @@ if ( $page_links )
|
|||
|
||||
<br class="clear" />
|
||||
</div>
|
||||
<?php find_posts_div(); ?>
|
||||
</form>
|
||||
<br class="clear" />
|
||||
|
||||
|
|
Loading…
Reference in New Issue