用于保存附件顺序的Ajax处理程序。

原型

wp_ajax_save_attachment_order()

源文件

路径:wp-admin/includes/ajax-actions.php

<?php
...
function wp_ajax_save_attachment_order() {
	if ( ! isset( $_REQUEST['post_id'] ) )
		wp_send_json_error();
	if ( ! $post_id = absint( $_REQUEST['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;
		if ( ! $attachment = get_post( $attachment_id ) )
			continue;
		if ( 'attachment' != $attachment->post_type )
			continue;
		wp_update_post( array( 'ID' => $attachment_id, 'menu_order' => $menu_order ) );
	}
	wp_send_json_success();
}
...
?>

其他

英文文档:https://developer.wordpress.org/reference/functions/wp_ajax_save_attachment_order/