-
-
Save crstauf/5751526 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function trash_past_events() { | |
$args = array( | |
'post_type' => 'event', | |
'posts_per_page' => -1, | |
'meta_key' => '_date', | |
'meta_value' => time(), | |
'meta_compare' => '<' | |
); | |
$events = new WP_Query($args); | |
if ($events->have_posts()) { | |
while ($events->have_posts()) { | |
$events->the_post(); | |
$details = get_post_meta(get_the_ID(),'_details',true); | |
unset($details['date']); | |
update_post_meta(get_the_ID(),'_details',$details); | |
delete_post_meta(get_the_ID(),'_date'); | |
wp_trash_post(get_the_ID()); | |
} | |
} | |
} | |
function meta_boxes() { | |
$positions = array('normal','side','advanced'); | |
add_meta_box('detail','Details',array(&$this,'create_meta_box'),$this->type,$positions[1]); | |
add_meta_box('repeat','Repeat',array(&$this,'create_repeat_events'),$this->type,$positions[1]); | |
} | |
function create_meta_box($post) { | |
$details = get_post_meta($post->ID,'_details',true); | |
$details = wp_parse_args($details,array('date' => '')); | |
if (array_key_exists('date',$details) && !empty($details['date'])) | |
$details['date'] = date("Y-m-d",$details['date']); | |
echo '<input type="hidden" name="' . $this->nonce . '_noncename" id="' . $this->nonce . '_noncename" value="' . wp_create_nonce( __FILE__ ) . '" />'; | |
echo '<p><strong>Date</strong><br />'; | |
echo '<input type="date" name="details[date]" value="' . $details['date'] . '" style="width: 246px;" /></p>'; | |
} | |
function create_repeat_events() { | |
global $post; | |
$repeat = get_post_meta($post->ID,'_repeat',true); | |
$repeatday = get_post_meta($post->ID,'_repeatday',true); | |
echo '<input type="hidden" name="' . $this->nonce . '_noncename" id="' . $this->nonce . '_noncename" value="' . wp_create_nonce( __FILE__ ) . '" />'; | |
echo '<p><input type="checkbox" name="repeat" value="1" ' . checked($repeat,1,false) . ' class="code" style="width: 8%;" /><strong>Check this if Repeat Event</strong></p>'; | |
$days = array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'); | |
echo '<p><select name="repeatday" class="code">'; | |
echo '<option value="">Please select a day</option>'; | |
foreach ($days as $i => $day) | |
echo '<option value="' . $i . '"' . selected($i,$repeatday,false) . '>' . $day . '</option>'; | |
echo '</select></p>'; | |
//echo '<p><select name="repeatday" class="code" style=""><option value="0">Sunday</option><option value="1">Monday</option><option value="2">Tuesday</option><option value="3">Wednesday</option><option value="4">Thursday</option><option value="5">Friday</option><option value="6">Saturday</option></select></p>'; | |
} | |
function save_post($post_id) { | |
$post = get_post($post_id); | |
if (!is_admin() || $post->post_type != $this->type) | |
return; | |
if ( !array_key_exists($this->nonce . '_noncename',$_POST) || !wp_verify_nonce( $_POST[$this->nonce . '_noncename'], __FILE__ )) | |
return $post_id; | |
if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ) | |
return $post_id; | |
if (!current_user_can('edit_post',$post_id)) | |
return $post_id; | |
$details = $_POST['details']; | |
$details['date'] = strtotime($details['date']); | |
update_post_meta($post_id,'_event_date',$details['date']); | |
update_post_meta($post_id,'_details',$details); | |
update_post_meta($post_id,'_repeat',$_POST['repeat']); | |
update_post_meta($post_id,'_repeatday',$_POST['repeatday']); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment