From cc39b5fbce41d65c85c4751f7179cff35db4e579 Mon Sep 17 00:00:00 2001
From: ryan \n";
+ echo "\n";
}
@@ -261,15 +259,26 @@ function media_upload_attachments() {
}
function media_upload_library() {
- if ( empty($_POST) )
- wp_iframe( 'media_upload_library_form', $errors );
+ if ( !empty($_POST) ) {
+ $return = media_upload_form_handler();
+
+ if ( is_string($return) )
+ return $return;
+ if ( is_array($return) )
+ $errors = $return;
+ }
+
+ return wp_iframe( 'media_upload_library_form', $errors );
}
function get_media_items( $post_id, $errors ) {
- if ( $post_id )
+ if ( $post_id ) {
$attachments = get_children("post_parent=$post_id&post_type=attachment&orderby=menu_order ASC, ID&order=DESC");
- else
- $attachments = get_paged_attachments();
+ } else {
+ if ( is_array($GLOBALS['wp_the_query']->posts) )
+ foreach ( $GLOBALS['wp_the_query']->posts as $attachment )
+ $attachments[$attachment->ID] = $attachment;
+ }
if ( empty($attachments) )
return '';
@@ -707,7 +716,141 @@ jQuery(function($){
}
function media_upload_library_form($errors) {
+ global $wpdb, $wp_query, $wp_locale;
+
media_upload_header();
+
+ $post_id = intval($_REQUEST['post_id']);
+
+ $form_action_url = get_option('siteurl') . "/wp-admin/media-upload.php?type=media&tab=library&post_id=$post_id";
+
+ $_GET['paged'] = intval($_GET['paged']);
+ if ( $_GET['paged'] < 1 )
+ $_GET['paged'] = 1;
+ $start = ( $_GET['paged'] - 1 ) * 10;
+ if ( $start < 1 )
+ $start = 0;
+ add_filter( 'post_limits', $limit_filter = create_function( '$a', "return 'LIMIT $start, 10';" ) );
+
+ list($post_mime_types, $avail_post_mime_types) = wp_edit_attachments_query();
+
+?>
+
+