Ticket #6820: 6820.3.diff
File 6820.3.diff, 9.9 KB (added by , 10 years ago) |
---|
-
src/wp-admin/includes/ajax-actions.php
2267 2267 if ( 'attachment' != $post['post_type'] ) 2268 2268 wp_send_json_error(); 2269 2269 2270 if ( isset( $changes['parent'] ) ) 2271 $post['post_parent'] = $changes['parent']; 2272 2270 2273 if ( isset( $changes['title'] ) ) 2271 2274 $post['post_title'] = $changes['title']; 2272 2275 … … 2980 2983 2981 2984 $GLOBALS['wp_press_this']->add_category(); 2982 2985 } 2986 2987 /** 2988 * AJAX handler for detaching an attachment from its parent 2989 * 2990 * @since 4.2.0 2991 */ 2992 function wp_ajax_detach_from_parent() { 2993 $post = get_post( (int) $_POST['id'] ); 2994 if ( ! $post || ! $post->post_parent || ! current_user_can( 'edit_post', $post->ID ) ) { 2995 wp_send_json_error(); 2996 } 2997 2998 if ( ! wp_update_post( array( 'post_parent' => 0, 'ID' => $post->ID ) ) ) { 2999 wp_send_json_error(); 3000 } 3001 3002 wp_send_json_success(); 3003 } -
src/wp-admin/includes/class-wp-media-list-table.php
139 139 if ( isset( $_REQUEST['found_post_id'] ) && isset( $_REQUEST['media'] ) ) 140 140 return 'attach'; 141 141 142 if ( isset( $_REQUEST['parent_post_id'] ) && isset( $_REQUEST['media'] ) ) 143 return 'detach'; 144 142 145 if ( isset( $_REQUEST['delete_all'] ) || isset( $_REQUEST['delete_all2'] ) ) 143 146 return 'delete_all'; 144 147 … … 406 409 } else { 407 410 echo $title; 408 411 } ?></strong>, 409 <?php echo get_the_time( __( 'Y/m/d' ) ); ?> 412 <?php echo get_the_time( __( 'Y/m/d' ) ); ?><br /> 413 <?php 414 if ( $user_can_edit ): 415 $detach_url = add_query_arg( array( 416 'parent_post_id' => $post->post_parent, 417 'media[]' => $post->ID, 418 '_wpnonce' => wp_create_nonce( 'bulk-' . $this->_args['plural'] ) 419 ), 'upload.php' ); ?> 420 <a class="hide-if-no-js detach-from-parent" href="<?php echo $detach_url ?>"><?php _e( 'Detach' ); ?></a> 421 <?php endif; ?> 410 422 </td> 411 423 <?php 412 424 } else { -
src/wp-admin/includes/media.php
3010 3010 3011 3011 return $metadata; 3012 3012 } 3013 3014 /** 3015 * Encapsulate logic for Attach/Detach actions 3016 * 3017 * @since 4.2.0 3018 * 3019 * @global wpdb $wpdb 3020 * @param int $parent_id 3021 * @param string $action 3022 */ 3023 function wp_media_attach_action( $parent_id, $action = 'attach' ) { 3024 global $wpdb; 3025 3026 if ( ! $parent_id ) { 3027 return; 3028 } 3029 3030 if ( ! current_user_can( 'edit_post', $parent_id ) ) { 3031 wp_die( __( 'You are not allowed to edit this post.' ) ); 3032 } 3033 $ids = array(); 3034 foreach ( (array) $_REQUEST['media'] as $att_id ) { 3035 $att_id = (int) $att_id; 3036 3037 if ( ! current_user_can( 'edit_post', $att_id ) ) { 3038 continue; 3039 } 3040 3041 $ids[] = $att_id; 3042 } 3043 3044 if ( ! empty( $ids ) ) { 3045 $ids_string = implode( ',', $ids ); 3046 if ( 'attach' === $action ) { 3047 $result = $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->posts SET post_parent = %d WHERE post_type = 'attachment' AND ID IN ( $ids_string )", $parent_id ) ); 3048 } else { 3049 $result = $wpdb->query( "UPDATE $wpdb->posts SET post_parent = 0 WHERE post_type = 'attachment' AND ID IN ( $ids_string )" ); 3050 } 3051 3052 foreach ( $ids as $att_id ) { 3053 clean_attachment_cache( $att_id ); 3054 } 3055 } 3056 3057 if ( isset( $result ) ) { 3058 $location = 'upload.php'; 3059 if ( $referer = wp_get_referer() ) { 3060 if ( false !== strpos( $referer, 'upload.php' ) ) { 3061 $location = $referer; 3062 } 3063 } 3064 3065 $key = 'attach' === $action ? 'attached' : 'detached'; 3066 $location = add_query_arg( array( $key => $result ) , $location ); 3067 wp_redirect( $location ); 3068 exit; 3069 } 3070 } 3071 No newline at end of file -
src/wp-admin/upload.php
113 113 } 114 114 115 115 switch ( $doaction ) { 116 case 'detach': 117 wp_media_attach_action( $_REQUEST['parent_post_id'], 'detach' ); 118 break; 119 116 120 case 'attach': 117 $parent_id = (int) $_REQUEST['found_post_id']; 118 if ( !$parent_id ) 119 return; 121 wp_media_attach_action( $_REQUEST['found_post_id'] ); 122 break; 120 123 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;155 124 case 'trash': 156 125 if ( !isset( $post_ids ) ) 157 126 break; … … 256 225 257 226 if ( ! empty( $_GET['attached'] ) && $attached = absint( $_GET['attached'] ) ) { 258 227 $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'] ); 260 229 } 261 230 231 if ( ! 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'] ); 234 } 235 262 236 if ( ! empty( $_GET['deleted'] ) && $deleted = absint( $_GET['deleted'] ) ) { 263 237 $message = sprintf( _n( 'Media attachment permanently deleted.', '%d media attachments permanently deleted.', $deleted ), number_format_i18n( $_GET['deleted'] ) ); 264 238 $_SERVER['REQUEST_URI'] = remove_query_arg(array('deleted'), $_SERVER['REQUEST_URI']); -
src/wp-includes/js/media/views/attachment/details.js
35 35 'click .untrash-attachment': 'untrashAttachment', 36 36 'click .edit-attachment': 'editAttachment', 37 37 'click .refresh-attachment': 'refreshAttachment', 38 'keydown': 'toggleSelectionHandler' 38 'keydown': 'toggleSelectionHandler', 39 'click .detach-from-parent': 'detachFromParent' 39 40 }, 40 41 41 42 initialize: function() { … … 134 135 this.controller.trigger( 'attachment:keydown:arrow', event ); 135 136 return; 136 137 } 138 }, 139 140 /** 141 * @param {Object} event 142 */ 143 detachFromParent: function( event ) { 144 event.preventDefault(); 145 146 this.model.save({ 147 'parent' : 0, 148 'uploadedTo' : 0, 149 'uploadedToLink' : '', 150 'uploadedToTitle' : '' 151 }); 137 152 } 138 153 }); 139 154 -
src/wp-includes/js/media/views/attachment.js
52 52 this.listenTo( this.model, 'change', this.render ); 53 53 } else { 54 54 this.listenTo( this.model, 'change:percent', this.progress ); 55 this.listenTo( this.model, 'change:parent', this.render ); 55 56 } 56 57 this.listenTo( this.model, 'change:title', this._syncTitle ); 57 58 this.listenTo( this.model, 'change:caption', this._syncCaption ); -
src/wp-includes/js/media/views.js
2656 2656 this.listenTo( this.model, 'change', this.render ); 2657 2657 } else { 2658 2658 this.listenTo( this.model, 'change:percent', this.progress ); 2659 this.listenTo( this.model, 'change:parent', this.render ); 2659 2660 } 2660 2661 this.listenTo( this.model, 'change:title', this._syncTitle ); 2661 2662 this.listenTo( this.model, 'change:caption', this._syncCaption ); … … 3195 3196 'click .untrash-attachment': 'untrashAttachment', 3196 3197 'click .edit-attachment': 'editAttachment', 3197 3198 'click .refresh-attachment': 'refreshAttachment', 3198 'keydown': 'toggleSelectionHandler' 3199 'keydown': 'toggleSelectionHandler', 3200 'click .detach-from-parent': 'detachFromParent' 3199 3201 }, 3200 3202 3201 3203 initialize: function() { … … 3294 3296 this.controller.trigger( 'attachment:keydown:arrow', event ); 3295 3297 return; 3296 3298 } 3299 }, 3300 3301 /** 3302 * @param {Object} event 3303 */ 3304 detachFromParent: function( event ) { 3305 event.preventDefault(); 3306 3307 this.model.save({ 3308 'parent' : 0, 3309 'uploadedTo' : 0, 3310 'uploadedToLink' : '', 3311 'uploadedToTitle' : '' 3312 }); 3297 3313 } 3298 3314 }); 3299 3315 -
src/wp-includes/media-template.php
418 418 <# } else { #> 419 419 <span class="value">{{ data.uploadedToTitle }}</span> 420 420 <# } #> 421 <# if ( data.nonces.edit ) { #> 422 <a class="detach-from-parent" data-id="{{ data.id }}" href="#">(<?php _e( 'Detach' ); ?>)</a> 423 <# } #> 421 424 </label> 422 425 <# } #> 423 426 <div class="attachment-compat"></div>