function bfox_plan_save_post($post_id, $post) { if ('bfox_plan' == $_POST['post_type']) { // See: http://codex.wordpress.org/Function_Reference/add_meta_box // verify this came from the our screen and with proper authorization, // because save_post can be triggered at other times if (!wp_verify_nonce($_POST['bfox_plan_edit_schedule_nonce'], 'bfox')) { return $post_id; } // verify if this is an auto save routine. If it is our form has not been submitted, so we dont want // to do anything if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { return $post_id; } // Check permissions if ('page' == $_POST['post_type']) { if (!current_user_can('edit_page', $post_id)) { return $post_id; } } else { if (!current_user_can('edit_post', $post_id)) { return $post_id; } } // Start Date $scheduler = new BfoxPlanScheduler(); $scheduler->setStartDate($_POST['schedule-start']); // If the start date is a real date, then save it in Y-m-d form // Otherwise, save an empty string as the start date (which means no schedule is being used) if ($scheduler->startTime()) { // Schedule Frequency $scheduler->setFrequency($_POST['schedule-frequency']); $scheduler->setReadingsPerDate($_POST['schedule-per-day']); // Excluded Dates $new_excludes = $_POST['schedule-exclude']; $new_excludes = explode("\n", str_replace(array(';'), "\n", $new_excludes)); foreach ($new_excludes as $new_exclude) { $multi = explode(':', $new_exclude); if (1 == count($multi)) { $scheduler->excludeDate($multi[0]); } else { $scheduler->excludeDateRange($multi); } } // Days of the Week exclusions $scheduler->setDaysOfWeek($_POST['schedule-days']); bfox_plan_update_meta('start_date', $scheduler->startDate(), $post_id); bfox_plan_update_meta('frequency', $scheduler->frequency(), $post_id); bfox_plan_update_meta('per_day', $scheduler->readingsPerDate(), $post_id); bfox_plan_update_meta('excluded_days', $scheduler->excludedDates(), $post_id); } else { bfox_plan_update_meta('start_date', '', $post_id); } bfox_plan_update_reading_data($post_id, $scheduler); } }