wp_ajax_get_attachment

Ajax handler for getting an attachment.

Description

wp_ajax_get_attachment(); 

Usage

  1. if ( !function_exists( 'wp_ajax_get_attachment' ) ) { 
  2. require_once ABSPATH . '/wp-admin/includes/ajax-actions.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = wp_ajax_get_attachment(); 
  7.  

Defined (1)

The function is defined in the following location(s).

/wp-admin/includes/ajax-actions.php  
  1. function wp_ajax_get_attachment() { 
  2. if ( ! isset( $_REQUEST['id'] ) ) 
  3.  
  4. if ( ! $id = absint( $_REQUEST['id'] ) ) 
  5.  
  6. if ( ! $post = get_post( $id ) ) 
  7.  
  8. if ( 'attachment' != $post->post_type ) 
  9.  
  10. if ( ! current_user_can( 'upload_files' ) ) 
  11.  
  12. if ( ! $attachment = wp_prepare_attachment_for_js( $id ) ) 
  13.  
  14. wp_send_json_success( $attachment );