[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 16:52:08 UTC 2012
#22758: menu_order is 0 for new galleries so no backward compatibility
--------------------------+------------------------------
Reporter: vickybiswas | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Gallery | Version:
Severity: normal | Resolution:
Keywords: |
--------------------------+------------------------------
Comment (by vickybiswas):
The function we are using to handle the same is as below
{{{
function pmc_gallery_menu_order_fix($id) {
$regex_pattern = get_shortcode_regex();
preg_match ('/'.$regex_pattern.'/s',
stripslashes($_POST['content']), $regex_matches);
if ($regex_matches[2] == 'gallery') :
$attribureStr = str_replace (" ", "&", trim
($regex_matches[3]));
$attribureStr = str_replace ('"', '', $attribureStr);
$attributes = wp_parse_args ($attribureStr);
endif;
$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 ( empty($images) ) {
// no attachments here
} else {
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:1>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list