wp_ajax_save_attachment_order

Ajax handler for saving the attachment order.

Description

wp_ajax_save_attachment_order(); 

Usage

  1. if ( !function_exists( 'wp_ajax_save_attachment_order' ) ) { 
  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_order(); 
  7.  

Defined (1)

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

/wp-admin/includes/ajax-actions.php  
  1. function wp_ajax_save_attachment_order() { 
  2. if ( ! isset( $_REQUEST['post_id'] ) ) 
  3.  
  4. if ( ! $post_id = absint( $_REQUEST['post_id'] ) ) 
  5.  
  6. if ( empty( $_REQUEST['attachments'] ) ) 
  7.  
  8. check_ajax_referer( 'update-post_' . $post_id, 'nonce' ); 
  9.  
  10. $attachments = $_REQUEST['attachments']; 
  11.  
  12. if ( ! current_user_can( 'edit_post', $post_id ) ) 
  13.  
  14. foreach ( $attachments as $attachment_id => $menu_order ) { 
  15. if ( ! current_user_can( 'edit_post', $attachment_id ) ) 
  16. continue; 
  17. if ( ! $attachment = get_post( $attachment_id ) ) 
  18. continue; 
  19. if ( 'attachment' != $attachment->post_type ) 
  20. continue; 
  21.  
  22. wp_update_post( array( 'ID' => $attachment_id, 'menu_order' => $menu_order ) ); 
  23.