function ContentScheduler_save_postdata_fn($post_id) { // verify this came from our screen and with proper authorization, // because save_post can be triggered at other times if (!empty($_POST['ContentScheduler_noncename'])) { if (!wp_verify_nonce($_POST['ContentScheduler_noncename'], 'content_scheduler_values')) { return $post_id; } } else { 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, whether we're editing a Page or a Post 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; } } // OK, we're authenticated: we need to find and save the data // First, let's make sure we'll do date operations in the right timezone for this blog // $this->setup_timezone(); // Checkbox for "enable scheduling" $enabled = empty($_POST['_cs-enable-schedule']) ? 'Disable' : $_POST['_cs-enable-schedule']; // Value should be either 'Enable' or 'Disable'; otherwise something is screwy if ($enabled != 'Enable' and $enabled != 'Disable') { // $enabled is something we don't expect // let's make it empty $enabled = 'Disable'; // Now we're done with this function? return false; } // Textbox for "expiration date" $dateString = $_POST['_cs-expire-date']; $offsetHours = 0; // if it is empty then set it to tomorrow // we just want to pass an offset into getTimestampFromReadableDate since that is where our DateTime is made if (empty($dateString)) { // set it to now + 24 hours $offsetHours = 24; } // TODO handle datemath if field reads "default" if (trim(strtolower($dateString)) == 'default') { // get the default value from the database $default_expiration_array = $this->options['exp-default']; if (!empty($default_expiration_array)) { $default_hours = $default_expiration_array['def-hours']; $default_days = $default_expiration_array['def-days']; $default_weeks = $default_expiration_array['def-weeks']; } else { $default_hours = '0'; $default_days = '0'; $default_weeks = '0'; } // we need to move weeks into days and days into hours $default_hours += ($default_weeks * 7 + $default_days) * 24 * 60 * 60; // if it is valid, get the published or scheduled datetime, add the default to it, and set it as the $date if (!empty($_POST['save'])) { if ($_POST['save'] == 'Update') { $publish_date = $_POST['aa'] . '-' . $_POST['mm'] . '-' . $_POST['jj'] . ' ' . $_POST['hh'] . ':' . $_POST['mn'] . ':' . $_POST['ss']; } else { $publish_date = $_POST['post_date']; } // convert publish_date string into unix timestamp $publish_date = DateUtilities::getTimestampFromReadableDate($publish_date); } else { $publish_date = time(); // current unix timestamp // no conversion from string needed } // time to add our default // we need $publish_date to be in unix timestamp format, like time() $expiration_date = $publish_date + $default_hours * 60 * 60; $_POST['_cs-expire-date'] = $expiration_date; } else { $expiration_date = DateUtilities::getTimestampFromReadableDate($dateString, $offsetHours); } // We probably need to store the date differently, // and handle timezone situation update_post_meta($post_id, '_cs-enable-schedule', $enabled); update_post_meta($post_id, '_cs-expire-date', $expiration_date); return true; }
<?php /* Should take human readable date strings and turn them into unix timestamps */ require_once "DateUtilities.php"; // find posts that need to take some expiration action global $wpdb; // select all Posts / Pages that have "enable-expiration" set and have expiration date older than right now $querystring = 'SELECT postmetadate.post_id, postmetadate.meta_value FROM ' . $wpdb->postmeta . ' AS postmetadate WHERE postmetadate.meta_key = "_cs-expire-date"'; $result = $wpdb->get_results($querystring); // Act upon the results if (!empty($result)) { // Proceed with the updating process // step through the results foreach ($result as $cur_post) { // do the date munging $unixTimestamp = DateUtilities::getTimestampFromReadableDate($cur_post->meta_value, 0); // update it update_post_meta($cur_post->post_id, '_cs-expire-date', $unixTimestamp, $cur_post->meta_value); } // end foreach } // endif