wp_ajax_save_attachment_order()  Ajax handler for saving the attachment order.   Source  File: wp-admin/includes/ajax-actions.php. View all references  function wp_ajax_save_attachment_order() {
	if ( ! isset( $_REQUEST['post_id'] ) ) {
		wp_send_json_error();
	}

	$post_id = absint( $_REQUEST['post_id'] );
	if ( ! $post_id ) {
		wp_send_json_error();
	}

	if ( empty( $_REQUEST['attachments'] ) ) {
		wp_send_json_error();
	}

	check_ajax_referer( 'update-post_' . $post_id, 'nonce' );

	$attachments = $_REQUEST['attachments'];

	if ( ! current_user_can( 'edit_post', $post_id ) ) {
		wp_send_json_error();
	}

	foreach ( $attachments as $attachment_id => $menu_order ) {
		if ( ! current_user_can( 'edit_post', $attachment_id ) ) {
			continue;
		}

		$attachment = get_post( $attachment_id );

		if ( ! $attachment ) {
			continue;
		}

		if ( 'attachment' !== $attachment->post_type ) {
			continue;
		}

		wp_update_post(
			array(
				'ID'         => $attachment_id,
				'menu_order' => $menu_order,
			)
		);
	}

	wp_send_json_success();
}
   Related  Uses    Uses Description      wp_update_post() wp-includes/post.php   Updates a post with new post data.     current_user_can() wp-includes/capabilities.php   Returns whether the current user has the specified capability.     check_ajax_referer() wp-includes/pluggable.php   Verifies the Ajax request to prevent processing requests external of the blog.     wp_send_json_error() wp-includes/functions.php   Sends a JSON response back to an Ajax request, indicating failure.     absint() wp-includes/functions.php   Converts a value to non-negative integer.     wp_send_json_success() wp-includes/functions.php   Sends a JSON response back to an Ajax request, indicating success.     get_post() wp-includes/post.php   Retrieves post data given a post ID or post object.   
    Changelog    Version Description     3.5.0 Introduced.    

    
{'path': 'public/docs/wordpress/functions/wp_ajax_save_attachment_order.html', 'source': 'DevDocs.IO'}