function wp_set_post_series($post_ID = 0, $post, $update, $series_id = array(), $dont_skip = false, $is_published = false)
{
    $post_series = null;
    $post_shorttitle = array();
    if (!is_bool($update)) {
        return;
    }
    //safety check for users on earlier version of WP (so existing series don't get messed up)
    //fix for the revisions feature in WP 2.6+  && bulk-edit stuff.
    if ($post->post_type == 'revision' || isset($_GET['bulk_edit_series']) && $_GET['bulk_edit_series'] == 'bulk' || !isset($_REQUEST['is_series_save'])) {
        return;
    }
    $post_ID = (int) $post_ID;
    $old_series = wp_get_post_series($post_ID);
    if (empty($series_id)) {
        $post_series = isset($_REQUEST['post_series']) && is_array($_REQUEST['post_series']) ? $_REQUEST['post_series'] : array($_REQUEST['post_series']);
    } else {
        $post_series = is_array($series_id) ? $series_id : array($series_id);
    }
    $post_series = os_strarr_to_intarr($post_series);
    if (empty($post_series) || count($post_series) >= count($old_series)) {
        $match = false;
    } else {
        $match = array_diff($old_series, $post_series);
    }
    if (empty($post_series) || count($post_series) == 1 && $post_series[0] == 0) {
        $post_series = array();
    }
    if (isset($_POST) || isset($_GET)) {
        if (isset($_POST['series_part'])) {
            $series_part = is_array($_POST['series_part']) ? $_POST['series_part'] : array($_POST['series_part']);
        }
        if (isset($_GET['series_part'])) {
            $series_part = is_array($_GET['series_part']) ? $_GET['series_part'] : array($_GET['series_part']);
        }
        //The "short" title of the post that will be displayed  in the OrgSeries widget.
        if (isset($_POST['serie_post_shorttitle'])) {
            $post_shorttitle = $_POST['serie_post_shorttitle'];
        }
        if (isset($_GET['serie_post_shorttitle'])) {
            $post_shorttitle = $_GET['serie_post_shorttitle'];
        }
        $st_ser_id = is_array($post_series) && isset($post_series[0]) ? (int) $post_series[0] : '';
        $post_shorttitle = is_array($post_shorttitle) && isset($post_shorttitle[$st_ser_id]) ? trim($post_shorttitle[$st_ser_id]) : '';
        update_post_meta($post->ID, SPOST_SHORTTITLE_KEY, $post_shorttitle);
        //if we don't have any changes in the series or series part info (or series post status) then let's get out and save time.
        $p_status = $post->post_status;
        if ($p_status != 'draft' && $p_status != 'future' && $p_status != 'pending') {
            $is_published = TRUE;
        }
        $count = count($post_series);
        $c_chk = 0;
        foreach ($post_series as $ser) {
            if (in_array($ser, $old_series) && $series_part[$ser] == wp_series_part($post_ID, $ser) && !$dont_skip) {
                $c_chk++;
                continue;
            } else {
                $p_ser_edit[] = $ser;
                //these are the series we need to set the parts for (leave the rest alone when we get to this section).
            }
        }
        if ($c_chk == $count && !empty($post_series) && count($post_series) == count($old_series) && !$dont_skip) {
            return;
        }
        //there are no changes so let's just skip the rest
    }
    if (empty($post_series)) {
        foreach ($old_series as $o_ser) {
            $part_key = apply_filters('orgseries_part_key', SERIES_PART_KEY, $o_ser);
            delete_post_meta($post_ID, $part_key);
        }
    }
    foreach ($old_series as $os_id) {
        if (!in_array($os_id, $post_series)) {
            wp_delete_post_series_relationship($post_ID, $os_id);
        }
    }
    if (!empty($match) && $match) {
        foreach ($match as $part_reset_id) {
            wp_reset_series_order_meta_cache($post_ID, $part_reset_id);
        }
    }
    $success = wp_set_object_terms($post_ID, $post_series, 'series');
    if (empty($p_ser_edit)) {
        return;
    }
    //let's get out we've done everything we need to do.
    if ($success) {
        if ($p_status != 'draft' && $p_status != 'future' && $p_status != 'pending') {
            $is_published = TRUE;
        }
        foreach ($p_ser_edit as $ser_id) {
            if (empty($series_part[$ser_id])) {
                $s_pt = wp_series_part($post_ID, $ser_id);
                if (!$series_part) {
                    $series_part = 0;
                }
            } elseif (!$is_published) {
                $s_pt = $series_part[$ser_id];
            } else {
                if (isset($_GET['submit'])) {
                    $set_spart = $_GET['series_part'];
                } else {
                    $set_spart = $_POST['series_part'];
                }
                $s_pt = $set_spart[$ser_id];
            }
            set_series_order($post_ID, $s_pt, $ser_id, $is_published);
        }
        return;
    } else {
        return FALSE;
    }
}
function series_edit_meta_box()
{
    global $post, $postdata, $content, $orgseries;
    $id = isset($post) ? $post->ID : $postdata->ID;
    $ser_id = wp_get_post_series($id);
    ?>
	<p id="jaxseries"></p>
		<span id="series-ajax-response"></span>
		<ul id="serieschecklist" class="list:series serieschecklist form-no-clear">
				<?php 
    get_series_to_select();
    ?>
		</ul>
		<span id="seriespart"><strong> <?php 
    _e('Series Part:', 'organize-series');
    ?>
   </strong><input type="text" name="series_part[<?php 
    echo isset($ser_id[0]) ? $ser_id[0] : 0;
    ?>
]" id="series_part" size="5" value="<?php 
    echo get_post_meta($id, SERIES_PART_KEY, true);
    ?>
" /></span>
			<p id="part-description"><?php 
    _e('Note: that if you leave this blank or enter an invalid number the post will automatically be appended to the rest of the posts in the series', 'organize-series');
    ?>
</p></br>
		<strong> <?php 
    _e('Post title in widget:', 'organize-series');
    ?>
</strong>
		<p id="part-description"><?php 
    _e('A "short" title of the post that will be used in the series widget. [Leave blank to use a full title]', 'organize-series');
    ?>
</p>
		<input type="text" name="serie_post_shorttitle[<?php 
    echo isset($ser_id[0]) ? $ser_id[0] : 0;
    ?>
]" id="serie_post_shorttitle" size="30" value="<?php 
    echo get_post_meta($id, SPOST_SHORTTITLE_KEY, true);
    ?>
"/>
		<input type="hidden" name="is_series_save" value="1" />
	<?php 
}