[wp-trac] [WordPress Trac] #22758: menu_order is 0 for new galleries so no backward compatibility
WordPress Trac
noreply at wordpress.org
Wed Dec 5 18:15:56 UTC 2012
#22758: menu_order is 0 for new galleries so no backward compatibility
--------------------------+------------------------
Reporter: vickybiswas | Owner:
Type: defect (bug) | Status: closed
Priority: normal | Milestone:
Component: Gallery | Version:
Severity: normal | Resolution: duplicate
Keywords: |
--------------------------+------------------------
Comment (by vickybiswas):
Replying to [comment:5 nacin]:
> Insert [gallery] manually into your post. Then rearrange "Uploaded to
this post".
>
> There is no way to use the new gallery interface and have it obey
menu_order without messing with the [gallery] shortcode in some way. You
can use new-style galleries, or you can continue to rearrange "Uploaded to
this post" and run queries based on menu order. Can't have both.
The code I am attaching allows editors on my VIP sites to use the new
gallery interface and at the same time maintain the menu_order so that our
galleries dont break.
The aim is to only maintain the backward compatibility and at the same
time use the wonderful new changes.
{{{
/**
* WP 3.5 doesn't update menu_order for ordering attachments, so this
function updates the menu_order so that you can orderby menu_order
* @param int $id
*/
function pmc_gallery_menu_order_fix($id) {
global $post;
$regex_pattern = get_shortcode_regex();
preg_match ('/'.$regex_pattern.'/s',
stripslashes($_POST['content']), $regex_matches);
if ( ! $regex_matches ) {
return false;
}
if ($regex_matches[2] == 'gallery') {
$attribure_str = str_replace(" ", "&", trim
($regex_matches[3]));
$attribure_str = str_replace('"', '', $attribure_str);
$attributes = wp_parse_args($attribure_str);
}
$ids = explode(',', $attributes['ids']);
$images = get_posts( array(
'post_parent' => $post->ID,
'numberposts' => '-1',
'post_status' => 'inherit',
'post_type' => 'attachment',
'post_mime_type' => 'image',
'orderby' => 'menu_order ID',
'order' => 'ASC'
) );
if ( $images ) {
foreach ( $images as $attachment_id => $attachment ) {
if (in_array($attachment->ID, $ids)) {
$update_post = array();
$update_post['ID'] = $attachment->ID;
$update_post['menu_order'] =
array_search($attachment->ID, $ids);
wp_update_post( $update_post );
};
}
}
}
add_action('pre_post_update', 'pmc_gallery_menu_order_fix');
}}}
--
Ticket URL: <http://core.trac.wordpress.org/ticket/22758#comment:6>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list