用于获取附件的Ajax处理程序。

原型

wp_ajax_get_attachment()

源文件

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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
<?php
...
function wp_ajax_get_attachment() {
	if ( ! isset( $_REQUEST['id'] ) )
		wp_send_json_error();

	if ( ! $id = absint( $_REQUEST['id'] ) )
		wp_send_json_error();

	if ( ! $post = get_post( $id ) )
		wp_send_json_error();

	if ( 'attachment' != $post->post_type )
		wp_send_json_error();

	if ( ! current_user_can( 'upload_files' ) )
		wp_send_json_error();

	if ( ! $attachment = wp_prepare_attachment_for_js( $id ) )
		wp_send_json_error();

	wp_send_json_success( $attachment );
}

...
?>

其他

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