Make WordPress Core


Ignore:
Timestamp:
03/05/2015 05:34:40 AM (7 years ago)
Author:
wonderboymusic
Message:

Allow attachments to be Detached from their parent in media grid and list modes.

See #6820.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/upload.php

    r31562 r31619  
    114114
    115115    switch ( $doaction ) {
     116        case 'detach':
     117            wp_media_attach_action( $_REQUEST['parent_post_id'], 'detach' );
     118            break;
     119
    116120        case 'attach':
    117             $parent_id = (int) $_REQUEST['found_post_id'];
    118             if ( !$parent_id )
    119                 return;
    120 
    121             $parent = get_post( $parent_id );
    122             if ( !current_user_can( 'edit_post', $parent_id ) )
    123                 wp_die( __( 'You are not allowed to edit this post.' ) );
    124 
    125             $attach = array();
    126             foreach ( (array) $_REQUEST['media'] as $att_id ) {
    127                 $att_id = (int) $att_id;
    128 
    129                 if ( !current_user_can( 'edit_post', $att_id ) )
    130                     continue;
    131 
    132                 $attach[] = $att_id;
    133             }
    134 
    135             if ( ! empty( $attach ) ) {
    136                 $attach_string = implode( ',', $attach );
    137                 $attached = $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->posts SET post_parent = %d WHERE post_type = 'attachment' AND ID IN ( $attach_string )", $parent_id ) );
    138                 foreach ( $attach as $att_id ) {
    139                     clean_attachment_cache( $att_id );
    140                 }
    141             }
    142 
    143             if ( isset( $attached ) ) {
    144                 $location = 'upload.php';
    145                 if ( $referer = wp_get_referer() ) {
    146                     if ( false !== strpos( $referer, 'upload.php' ) )
    147                         $location = $referer;
    148                 }
    149 
    150                 $location = add_query_arg( array( 'attached' => $attached ) , $location );
    151                 wp_redirect( $location );
    152                 exit;
    153             }
    154             break;
     121            wp_media_attach_action( $_REQUEST['found_post_id'] );
     122            break;
     123
    155124        case 'trash':
    156125            if ( !isset( $post_ids ) )
     
    257226if ( ! empty( $_GET['attached'] ) && $attached = absint( $_GET['attached'] ) ) {
    258227    $message = sprintf( _n('Reattached %d attachment.', 'Reattached %d attachments.', $attached), $attached );
    259     $_SERVER['REQUEST_URI'] = remove_query_arg(array('attached'), $_SERVER['REQUEST_URI']);
     228    $_SERVER['REQUEST_URI'] = remove_query_arg( array( 'detached', 'attached' ), $_SERVER['REQUEST_URI'] );
     229}
     230
     231if ( ! empty( $_GET['detached'] ) && $detached = absint( $_GET['detached'] ) ) {
     232    $message = sprintf( _n( 'Detached %d attachment.', 'Detached %d attachments.', $detached ), $detached );
     233    $_SERVER['REQUEST_URI'] = remove_query_arg( array( 'detached', 'attached' ), $_SERVER['REQUEST_URI'] );
    260234}
    261235
Note: See TracChangeset for help on using the changeset viewer.