wp_ajax_save_attachment_compat

Ajax handler for saving backward compatible attachment attributes.

Description

wp_ajax_save_attachment_compat(); 

Usage

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

Defined (1)

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

/wp-admin/includes/ajax-actions.php  
  1. function wp_ajax_save_attachment_compat() { 
  2. if ( ! isset( $_REQUEST['id'] ) ) 
  3.  
  4. if ( ! $id = absint( $_REQUEST['id'] ) ) 
  5.  
  6. if ( empty( $_REQUEST['attachments'] ) || empty( $_REQUEST['attachments'][ $id ] ) ) 
  7. $attachment_data = $_REQUEST['attachments'][ $id ]; 
  8.  
  9. check_ajax_referer( 'update-post_' . $id, 'nonce' ); 
  10.  
  11. if ( ! current_user_can( 'edit_post', $id ) ) 
  12.  
  13. $post = get_post( $id, ARRAY_A ); 
  14.  
  15. if ( 'attachment' != $post['post_type'] ) 
  16.  
  17. /** This filter is documented in wp-admin/includes/media.php */ 
  18. $post = apply_filters( 'attachment_fields_to_save', $post, $attachment_data ); 
  19.  
  20. if ( isset( $post['errors'] ) ) { 
  21. $errors = $post['errors']; // @todo return me and display me! 
  22. unset( $post['errors'] ); 
  23.  
  24. wp_update_post( $post ); 
  25.  
  26. foreach ( get_attachment_taxonomies( $post ) as $taxonomy ) { 
  27. if ( isset( $attachment_data[ $taxonomy ] ) ) 
  28. wp_set_object_terms( $id, array_map( 'trim', preg_split( '/, +/', $attachment_data[ $taxonomy ] ) ), $taxonomy, false ); 
  29.  
  30. if ( ! $attachment = wp_prepare_attachment_for_js( $id ) ) 
  31.  
  32. wp_send_json_success( $attachment );