| | 1922 | function wp_ajax_save_attachment_order() { |
| | 1923 | if ( ! isset( $_REQUEST['post_id'] ) ) |
| | 1924 | wp_send_json_error(); |
| | 1925 | |
| | 1926 | if ( ! $id = absint( $_REQUEST['post_id'] ) ) |
| | 1927 | wp_send_json_error(); |
| | 1928 | |
| | 1929 | if ( empty( $_REQUEST['attachments'] ) ) |
| | 1930 | wp_send_json_error(); |
| | 1931 | |
| | 1932 | check_ajax_referer( 'update-post_' . $post_id, 'nonce' ); |
| | 1933 | |
| | 1934 | $attachments = $_REQUEST['attachments']; |
| | 1935 | |
| | 1936 | if ( ! current_user_can( 'edit_post', $post_id ) ) |
| | 1937 | wp_send_json_error(); |
| | 1938 | |
| | 1939 | $post = get_post( $post_id, ARRAY_A ); |
| | 1940 | |
| | 1941 | foreach ( $attachments as $attachment_id => $menu_order ) { |
| | 1942 | if ( ! current_user_can( 'edit_post', $attachment_id ) ) |
| | 1943 | continue; |
| | 1944 | if ( ! $attachment = get_post( $attachment_id ) ) |
| | 1945 | continue; |
| | 1946 | if ( 'attachment' != $attachment->post_type ) |
| | 1947 | continue; |
| | 1948 | |
| | 1949 | wp_update_post( array( 'ID' => $attachment_id, 'menu_order' => $menu_order ) ); |
| | 1950 | } |
| | 1951 | |
| | 1952 | wp_send_json_success(); |
| | 1953 | } |
| | 1954 | |