Changeset 31619
- Timestamp:
- 03/05/2015 05:34:40 AM (10 years ago)
- Location:
- trunk/src
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/includes/ajax-actions.php
r31534 r31619 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']; -
trunk/src/wp-admin/includes/class-wp-media-list-table.php
r31220 r31619 139 139 if ( isset( $_REQUEST['found_post_id'] ) && isset( $_REQUEST['media'] ) ) 140 140 return 'attach'; 141 142 if ( isset( $_REQUEST['parent_post_id'] ) && isset( $_REQUEST['media'] ) ) 143 return 'detach'; 141 144 142 145 if ( isset( $_REQUEST['delete_all'] ) || isset( $_REQUEST['delete_all2'] ) ) … … 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 -
trunk/src/wp-admin/includes/media.php
r31440 r31619 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 = remove_query_arg( array( 'attached', 'detached' ), $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 } -
trunk/src/wp-admin/upload.php
r31562 r31619 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; 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 155 124 case 'trash': 156 125 if ( !isset( $post_ids ) ) … … 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'] ); 229 } 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'] ); 260 234 } 261 235 -
trunk/src/wp-includes/js/media/views.js
r31618 r31619 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 ); … … 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 … … 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 }); -
trunk/src/wp-includes/js/media/views/attachment.js
r31491 r31619 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 ); -
trunk/src/wp-includes/js/media/views/attachment/details.js
r31491 r31619 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 … … 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 }); -
trunk/src/wp-includes/media-template.php
r31546 r31619 418 418 <# } else { #> 419 419 <span class="value">{{ data.uploadedToTitle }}</span> 420 <# } #> 421 <# if ( data.nonces.edit ) { #> 422 <a class="detach-from-parent" data-id="{{ data.id }}" href="#">(<?php _e( 'Detach' ); ?>)</a> 420 423 <# } #> 421 424 </label>
Note: See TracChangeset
for help on using the changeset viewer.