| 2944 | // Set menu_order of attached images in Gallery |
| 2945 | $regex_pattern = get_shortcode_regex(); |
| 2946 | preg_match ('/'.$regex_pattern.'/s', stripslashes($data['post_content']), $regex_matches); |
| 2947 | if ( $regex_matches ) { |
| 2948 | if ($regex_matches[2] == 'gallery') { |
| 2949 | $attribure_str = str_replace(" ", "&", trim ($regex_matches[3])); |
| 2950 | $attribure_str = str_replace('"', '', $attribure_str); |
| 2951 | $attributes = wp_parse_args($attribure_str); |
| 2952 | } |
| 2953 | $ids = explode(',', $attributes[ids]); |
| 2954 | $images = get_posts( array( |
| 2955 | 'post_parent' => $post_ID, |
| 2956 | 'numberposts' => '-1', |
| 2957 | 'post_status' => 'inherit', |
| 2958 | 'post_type' => 'attachment', |
| 2959 | 'post_mime_type' => 'image', |
| 2960 | 'orderby' => 'menu_order ID', |
| 2961 | 'order' => 'ASC' |
| 2962 | ) ); |
| 2963 | if ( $images ) { |
| 2964 | foreach ( $images as $attachment_id => $attachment ) { |
| 2965 | if (in_array($attachment->ID, $ids)) { |
| 2966 | $update_post = array(); |
| 2967 | $update_post['ID'] = $attachment->ID; |
| 2968 | $update_post['menu_order'] = array_search($attachment->ID, $ids); |
| 2969 | wp_update_post( $update_post ); |
| 2970 | }; |
| 2971 | } |
| 2972 | } |
| 2973 | } |
| 2974 | |