Ticket #22607: 22607.2.diff
File 22607.2.diff, 5.3 KB (added by , 13 years ago) |
---|
-
wp-admin/admin-ajax.php
56 56 'save-widget', 'set-post-thumbnail', 'date_format', 'time_format', 'wp-fullscreen-save-post', 57 57 'wp-remove-post-lock', 'dismiss-wp-pointer', 'upload-attachment', 'get-attachment', 58 58 'query-attachments', 'save-attachment', 'save-attachment-compat', 'send-link-to-editor', 59 'send-attachment-to-editor', 59 'send-attachment-to-editor', 'save-attachment-order', 60 60 ); 61 61 62 62 // Register core Ajax calls. -
wp-admin/includes/ajax-actions.php
1927 1927 wp_send_json_success( $attachment ); 1928 1928 } 1929 1929 1930 function wp_ajax_save_attachment_order() { 1931 if ( ! isset( $_REQUEST['post_id'] ) ) 1932 wp_send_json_error(); 1933 1934 if ( ! $post_id = absint( $_REQUEST['post_id'] ) ) 1935 wp_send_json_error(); 1936 1937 if ( empty( $_REQUEST['attachments'] ) ) 1938 wp_send_json_error(); 1939 1940 check_ajax_referer( 'update-post_' . $post_id, 'nonce' ); 1941 1942 $attachments = $_REQUEST['attachments']; 1943 1944 if ( ! current_user_can( 'edit_post', $post_id ) ) 1945 wp_send_json_error(); 1946 1947 $post = get_post( $post_id, ARRAY_A ); 1948 1949 foreach ( $attachments as $attachment_id => $menu_order ) { 1950 if ( ! current_user_can( 'edit_post', $attachment_id ) ) 1951 continue; 1952 if ( ! $attachment = get_post( $attachment_id ) ) 1953 continue; 1954 if ( 'attachment' != $attachment->post_type ) 1955 continue; 1956 1957 wp_update_post( array( 'ID' => $attachment_id, 'menu_order' => $menu_order ) ); 1958 } 1959 1960 wp_send_json_success(); 1961 } 1962 1930 1963 /** 1931 1964 * Generates the HTML to send an attachment to the editor. 1932 1965 * Backwards compatible with the media_send_to_editor filter and the chain -
wp-includes/js/media-models.js
523 523 _requery: function() { 524 524 if ( this.props.get('query') ) 525 525 this.mirror( Query.get( this.props.toJSON() ) ); 526 }, 527 528 // If this collection is sorted by `menuOrder`, recalculates and saves 529 // the menu order to the database. 530 saveMenuOrder: function() { 531 if ( 'menuOrder' !== this.props.get('orderby') ) 532 return; 533 534 // Removes any uploading attachments, updates each attachment's 535 // menu order, and returns an object with an { id: menuOrder } 536 // mapping to pass to the request. 537 var attachments = this.chain().filter( function( attachment ) { 538 return ! _.isUndefined( attachment.id ); 539 }).map( function( attachment, index ) { 540 // Indices start at 1. 541 index = index + 1; 542 attachment.set( 'menuOrder', index ); 543 return [ attachment.id, index ]; 544 }).object().value(); 545 546 if ( _.isEmpty( attachments ) ) 547 return; 548 549 return media.post( 'save-attachment-order', { 550 nonce: media.model.settings.updatePostNonce, 551 post_id: media.model.settings.postId, 552 attachments: attachments 553 }); 526 554 } 527 555 }, { 528 556 comparator: function( a, b, options ) { -
wp-includes/js/media-views.js
14 14 15 15 // Copy the `postId` setting over to the model settings. 16 16 media.model.settings.postId = media.view.settings.postId; 17 media.model.settings.updatePostNonce = media.view.settings.nonce.updatePost; 17 18 18 19 // Check if the browser supports CSS 3.0 transitions 19 20 $.support.transition = (function(){ … … 267 268 content: 'browse', 268 269 searchable: true, 269 270 filterable: false, 270 uploads: true 271 uploads: true, 272 sortable: true 271 273 }, 272 274 273 275 initialize: function() { … … 2768 2770 at: ui.item.index(), 2769 2771 silent: true 2770 2772 }); 2773 2774 // If the collection is sorted by menu order, 2775 // update the menu order. 2776 collection.saveMenuOrder(); 2771 2777 } 2772 2778 }); 2773 2779 … … 2783 2789 return; 2784 2790 2785 2791 // If the `collection` has a `comparator`, disable sorting. 2786 this.$el.sortable( 'option', 'disabled', !! this.collection.comparator ); 2792 var collection = this.collection, 2793 orderby = collection.props.get('orderby'), 2794 enabled = 'menuOrder' === orderby || ! collection.comparator; 2795 2796 this.$el.sortable( 'option', 'disabled', ! enabled ); 2787 2797 }, 2788 2798 2789 2799 createAttachmentView: function( attachment ) { … … 3049 3059 }).render() ); 3050 3060 } 3051 3061 3052 if ( this.options.sortable ) {3062 if ( this.options.sortable && ! this.options.filters ) { 3053 3063 this.toolbar.set( 'dragInfo', new media.View({ 3054 3064 el: $( '<div class="instructions">' + l10n.dragInfo + '</div>' )[0], 3055 3065 priority: -40 -
wp-includes/media.php
1433 1433 if ( isset( $args['post'] ) ) { 1434 1434 $post = get_post( $args['post'] ); 1435 1435 $settings['postId'] = $post->ID; 1436 $settings['nonce']['updatePost'] = wp_create_nonce( 'update-post_' . $post->ID ); 1436 1437 } 1437 1438 1438 1439 $hier = $post && is_post_type_hierarchical( $post->post_type );