Make WordPress Core

Ticket #22607: 22607.diff

File 22607.diff, 1.3 KB (added by nacin, 12 years ago)

An ajax endpoint for koopersmith to work with.

  • wp-admin/includes/ajax-actions.php

     
    19191919        wp_send_json_success( $attachment );
    19201920}
    19211921
     1922function wp_ajax_save_attachment_order() {
     1923        if ( ! isset( $_REQUEST['post_id'] ) )
     1924                wp_send_json_error();
     1925
     1926        if ( ! $id = absint( $_REQUEST['post_id'] ) )
     1927                wp_send_json_error();
     1928
     1929        if ( empty( $_REQUEST['attachments'] ) )
     1930                wp_send_json_error();
     1931
     1932        check_ajax_referer( 'update-post_' . $post_id, 'nonce' );
     1933
     1934        $attachments = $_REQUEST['attachments'];
     1935
     1936        if ( ! current_user_can( 'edit_post', $post_id ) )
     1937                wp_send_json_error();
     1938
     1939        $post = get_post( $post_id, ARRAY_A );
     1940
     1941        foreach ( $attachments as $attachment_id => $menu_order ) {
     1942                if ( ! current_user_can( 'edit_post', $attachment_id ) )
     1943                        continue;
     1944                if ( ! $attachment = get_post( $attachment_id ) )
     1945                        continue;
     1946                if ( 'attachment' != $attachment->post_type )
     1947                        continue;
     1948
     1949                wp_update_post( array( 'ID' => $attachment_id, 'menu_order' => $menu_order ) );
     1950        }
     1951
     1952        wp_send_json_success();
     1953}
     1954
    19221955/**
    19231956 * Generates the HTML to send an attachment to the editor.
    19241957 * Backwards compatible with the media_send_to_editor filter and the chain