wpseek.com
Eine auf WordPress spezialiserte Suchmaschine für Entwickler und Theme-Autoren
wp_ajax_get_attachment › WordPress Function
Seit3.5.0
Veraltetn/v
› wp_ajax_get_attachment ( Keine Parameter )
| Definiert in: |
|
| Codex: |
Handles getting an attachment via AJAX.
Ähnliche Funktionen: wp_ajax_save_attachment, wp_ajax_query_attachments, wp_ajax_get_comments, wp_ajax_upload_attachment, wp_get_attachment_url
Quellcode
function wp_ajax_get_attachment() {
if ( ! isset( $_REQUEST['id'] ) ) {
wp_send_json_error();
}
$id = absint( $_REQUEST['id'] );
if ( ! $id ) {
wp_send_json_error();
}
$post = get_post( $id );
if ( ! $post ) {
wp_send_json_error();
}
if ( 'attachment' !== $post->post_type ) {
wp_send_json_error();
}
if ( ! current_user_can( 'upload_files' ) ) {
wp_send_json_error();
}
$attachment = wp_prepare_attachment_for_js( $id );
if ( ! $attachment ) {
wp_send_json_error();
}
wp_send_json_success( $attachment );
}