Changeset 15642 for trunk/wp-admin/upload.php
- Timestamp:
- 09/22/2010 12:10:39 AM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/upload.php
r15578 r15642 14 14 15 15 // Handle bulk actions 16 if ( isset($_REQUEST['find_detached']) ) { 16 $doaction = $wp_list_table->current_action(); 17 18 if ( $doaction ) { 17 19 check_admin_referer('bulk-media'); 18 20 19 if ( !current_user_can('edit_posts') ) 20 wp_die( __('You are not allowed to scan for lost attachments.') ); 21 22 $lost = $wpdb->get_col( " 23 SELECT ID FROM $wpdb->posts 24 WHERE post_type = 'attachment' AND post_parent > '0' 25 AND post_parent NOT IN ( 26 SELECT ID FROM $wpdb->posts 27 WHERE post_type NOT IN ( 'attachment', '" . join( "', '", get_post_types( array( 'public' => false ) ) ) . "' ) 28 ) 29 " ); 30 31 $_REQUEST['detached'] = 1; 32 33 } elseif ( isset( $_REQUEST['found_post_id'] ) && isset( $_REQUEST['media'] ) ) { 34 check_admin_referer( 'bulk-media' ); 35 36 $parent_id = (int) $_REQUEST['found_post_id']; 37 if ( !$parent_id ) 38 return; 39 40 $parent = &get_post( $parent_id ); 41 if ( !current_user_can( 'edit_post', $parent_id ) ) 42 wp_die( __( 'You are not allowed to edit this post.' ) ); 43 44 $attach = array(); 45 foreach ( (array) $_REQUEST['media'] as $att_id ) { 46 $att_id = (int) $att_id; 47 48 if ( !current_user_can( 'edit_post', $att_id ) ) 49 continue; 50 51 $attach[] = $att_id; 52 clean_attachment_cache( $att_id ); 53 } 54 55 if ( ! empty( $attach ) ) { 56 $attach = implode( ',', $attach ); 57 $attached = $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->posts SET post_parent = %d WHERE post_type = 'attachment' AND ID IN ( $attach )", $parent_id ) ); 58 } 59 60 if ( isset( $attached ) ) { 61 $location = 'upload.php'; 62 if ( $referer = wp_get_referer() ) { 63 if ( false !== strpos( $referer, 'upload.php' ) ) 64 $location = $referer; 65 } 66 67 $location = add_query_arg( array( 'attached' => $attached ) , $location ); 68 wp_redirect( $location ); 69 exit; 70 } 71 72 } elseif ( isset( $_REQUEST['doaction'] ) || isset( $_REQUEST['doaction2'] ) || isset( $_REQUEST['delete_all'] ) || isset( $_REQUEST['delete_all2'] ) ) { 73 check_admin_referer( 'bulk-media' ); 74 75 if ( isset( $_REQUEST['delete_all'] ) || isset( $_REQUEST['delete_all2'] ) ) { 21 if ( 'delete_all' == $doaction ) { 76 22 $post_ids = $wpdb->get_col( "SELECT ID FROM $wpdb->posts WHERE post_type='attachment' AND post_status = 'trash'" ); 77 23 $doaction = 'delete'; 78 } elseif ( ( $_REQUEST['action'] != -1 || $_REQUEST['action2'] != -1 ) && ( isset( $_REQUEST['media'] ) || isset( $_REQUEST['ids'] ) ) ) { 79 $post_ids = isset( $_REQUEST['media'] ) ? $_REQUEST['media'] : explode( ',', $_REQUEST['ids'] ); 80 $doaction = ( $_REQUEST['action'] != -1 ) ? $_REQUEST['action'] : $_REQUEST['action2']; 81 } else { 82 wp_redirect( $_SERVER['HTTP_REFERER'] ); 24 } elseif ( isset( $_REQUEST['media'] ) ) { 25 $post_ids = $_REQUEST['media']; 26 } elseif ( isset( $_REQUEST['ids'] ) ) { 27 $post_ids = explode( ',', $_REQUEST['ids'] ); 83 28 } 84 29 … … 90 35 91 36 switch ( $doaction ) { 37 case 'find_detached': 38 if ( !current_user_can('edit_posts') ) 39 wp_die( __('You are not allowed to scan for lost attachments.') ); 40 41 $lost = $wpdb->get_col( " 42 SELECT ID FROM $wpdb->posts 43 WHERE post_type = 'attachment' AND post_parent > '0' 44 AND post_parent NOT IN ( 45 SELECT ID FROM $wpdb->posts 46 WHERE post_type NOT IN ( 'attachment', '" . join( "', '", get_post_types( array( 'public' => false ) ) ) . "' ) 47 ) 48 " ); 49 50 $_REQUEST['detached'] = 1; 51 break; 52 case 'attach': 53 $parent_id = (int) $_REQUEST['found_post_id']; 54 if ( !$parent_id ) 55 return; 56 57 $parent = &get_post( $parent_id ); 58 if ( !current_user_can( 'edit_post', $parent_id ) ) 59 wp_die( __( 'You are not allowed to edit this post.' ) ); 60 61 $attach = array(); 62 foreach ( (array) $_REQUEST['media'] as $att_id ) { 63 $att_id = (int) $att_id; 64 65 if ( !current_user_can( 'edit_post', $att_id ) ) 66 continue; 67 68 $attach[] = $att_id; 69 clean_attachment_cache( $att_id ); 70 } 71 72 if ( ! empty( $attach ) ) { 73 $attach = implode( ',', $attach ); 74 $attached = $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->posts SET post_parent = %d WHERE post_type = 'attachment' AND ID IN ( $attach )", $parent_id ) ); 75 } 76 77 if ( isset( $attached ) ) { 78 $location = 'upload.php'; 79 if ( $referer = wp_get_referer() ) { 80 if ( false !== strpos( $referer, 'upload.php' ) ) 81 $location = $referer; 82 } 83 84 $location = add_query_arg( array( 'attached' => $attached ) , $location ); 85 wp_redirect( $location ); 86 exit; 87 } 88 break; 92 89 case 'trash': 93 90 foreach ( (array) $post_ids as $post_id ) {
Note: See TracChangeset
for help on using the changeset viewer.