wp_ajax_save_attachment_order() - WordPress 函数参考中文文档

返回介绍

wp_ajax_save_attachment_order()

发布于 2017-09-11 字数1872 浏览 919 评论 0

wp_ajax_save_attachment_order()

Ajax handler for saving the attachment order.


描述


源代码

File: wp-admin/includes/ajax-actions.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();
}

更新日志

Version 描述
3.5.0 Introduced.

相关函数

Uses

  • wp-includes/capabilities.php:
    current_user_can()
  • wp-includes/pluggable.php:
    check_ajax_referer()
  • wp-includes/functions.php:
    wp_send_json_error()
  • wp-includes/functions.php:
    absint()
  • wp-includes/functions.php:
    wp_send_json_success()
  • wp-includes/post.php:
    wp_update_post()
  • wp-includes/post.php:
    get_post()
  • Show 2 more uses
    Hide more uses


User Contributed Notes

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

目前还没有任何评论,快来抢沙发吧!