Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class CP_Calendar_Event_Handler extends CP_Custom_Content_Handler_Base
- {
- /**
- * Registers the Calendar Event PostType
- *
- */
- public function on_setup_custom_content()
- {
- CP_Custom_Content_Core::GetInstance()->register_custom_content_type($this);
- add_filter('posts_where_request', array($this, 'filter_events_where'), 10, 1);
- add_filter('posts_join_request', array($this, 'filter_events_join'), 10, 1);
- $this->metadata = array(
- 'misc' => array(
- new URL_Metadata('clickthru_url', 'Click-Thru URL'),
- new URL_Metadata('ticket_purchase_url', 'Ticket Purchase URL'),
- new Checkbox_Metadata('livenation_link', 'LiveNation Ticket Link'),
- new Text_Metadata('ticket_price', 'Ticket Price'),
- new Checkbox_Metadata('sold_out', 'Sold Out'),
- )
- );
- }
- public function get_content_type()
- {
- return 'calendar_event';
- }
- public function get_type_label()
- {
- return 'Event';
- }
- public function get_type_label_plural()
- {
- return 'Events';
- }
- public function get_type_publicly_queryable() {return true; }
- public function get_type_icon_url()
- {
- return CP_BASE_URL.'/child-plugins/cp-calendar-events/menu-events.png';
- }
- public function get_type_permastructure()
- {
- return array('identifier' => 'events', 'structure' => '%identifier%/%year%/%monthnum%/%day%/%postname%/');
- }
- /**
- * Returns an array of features the content type supports
- *
- * @return array
- */
- public function get_type_supports()
- {
- //leaving out thumbnail until we can migrate featured images to use that instead.
- return array('title', 'editor', 'excerpt', 'comments');
- }
- /**
- * First fired on 'request' filter
- * Sets order to 'asc' by default
- * Sets month and year to current if not set and not a search
- *
- * @param array $query_vars
- * @return array
- */
- public function filter_request_query_vars($query_vars)
- {
- if(!is_admin() && (isset($query_vars['taxonomy']) && in_array( $query_vars['taxonomy'], get_object_taxonomies($this->get_content_type())) && $query_vars['post_type'] == $this->get_content_type()))
- {
- $query_vars['order'] = 'asc';
- }
- if(!is_admin() && isset($query_vars['post_type']) && $this->get_content_type() == $query_vars['post_type'])
- {
- if(!isset($query_vars['order']))
- {
- $query_vars['order'] = 'asc';
- }
- if(!isset($query_vars['monthnum']) && empty($query_vars['s']))
- {
- //set month to current
- $query_vars['year'] = date('Y');
- $query_vars['monthnum'] = date('m');
- }
- }
- return $query_vars;
- }
- /**
- * Replaces the submitdiv meta box with a custom one for events
- * Adds metabox for remaining event data
- *
- * @param object $post
- */
- public function add_meta_boxes($post)
- {
- global $wp_meta_boxes;
- //replace the default submit metabox with the special one for events
- $wp_meta_boxes[$this->get_content_type()]['side']['core']['submitdiv'] = array('id' => 'submitdiv', 'title' => 'Publish', 'callback' => array($this, 'submit_meta_box'), 'args' => null);
- add_meta_box('eventmeta', "Misc Event Meta", array($this, 'misc_event_metabox'), $this->get_content_type(), 'normal', 'core');
- }
- /**
- * Meta boxes for ticket price, ticket purchase url, clickthru url, etc
- *
- * @param unknown_type $post
- */
- public function misc_event_metabox($post)
- {
- CP_Custom_Metadata_Base::display_all($this->metadata['misc'], $post->ID);
- }
- /**
- * Save event for the data from the Misc Event Metabox
- *
- * @param int $post_id
- */
- public function on_save_event($post_id, $post)
- {
- if(!((defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) || (defined('DOING_CRON') && DOING_CRON)))
- {
- if ( wp_is_post_revision($post_id) || wp_is_post_autosave($post_id))
- {
- return $post_id;
- }
- CP_Custom_Metadata_Base::save_all($this->metadata['misc'], $post_id);
- }
- }
- /**
- * Runs on 'wp_insert_post_data' filter to change the status from 'future' to 'publish'
- * and validates and saves the end date in meta.
- *
- * @param array $data
- * @param array $posted_data
- * @return array
- */
- public function filter_wp_insert_post_data($data, $posted_data)
- {
- if($data['post_type'] == $this->get_content_type())
- {
- if($posted_data['post_status'] == 'publish' || $data['post_status'] == 'future')
- {
- $data['post_status'] = 'publish';
- }
- if(isset($posted_data['update_event_nonce']) && wp_verify_nonce($posted_data['update_event_nonce'], 'update_event'))
- {
- //update the dates
- $defaults = array(
- 'start_aa' => '',
- 'start_mm' => '',
- 'start_jj' => '',
- 'start_hh' => '',
- 'start_mn' => '',
- 'start_ss' => '',
- 'start_mr' => '',
- 'end_aa' => '',
- 'end_mm' => '',
- 'end_jj' => '',
- 'end_hh' => '',
- 'end_mn' => '',
- 'end_ss' => '',
- 'end_mr' => '',
- );
- $posted_data = array_merge($defaults, $posted_data);
- $is_allday = isset($posted_data['event_is_allday']);
- $start_aa = $posted_data['start_aa'];
- $start_mm = $posted_data['start_mm'];
- $start_jj = $posted_data['start_jj'];
- $start_hh = $posted_data['start_hh'];
- $start_mn = $posted_data['start_mn'];
- $start_ss = $posted_data['start_ss'];
- $start_mr = $posted_data['start_mr'];
- $start_mr = ($start_mr == 'AM') ? 'AM' : 'PM';
- $start_hh = (($start_mr == 'PM' && $start_hh != 12) || ($start_mr != 'PM' && $start_hh = 12)) ? $start_hh + 12 : $start_hh;
- $start_aa = ($start_aa <= 0 ) ? date('Y') : $start_aa;
- $start_mm = ($start_mm <= 0 ) ? date('n') : $start_mm;
- $start_jj = ($start_jj > 31 ) ? 31 : $start_jj;
- $start_jj = ($start_jj <= 0 ) ? date('j') : $start_jj;
- if($is_allday)
- {
- $start_mn = $start_hh = '00';
- }
- else
- {
- $start_hh = ($start_hh > 23 ) ? $start_hh -24 : $start_hh;
- $start_mn = ($start_mn > 59 ) ? $start_mn -60 : $start_mn;
- }
- $data['post_date'] = sprintf( "%04d-%02d-%02d %02d:%02d:00", $start_aa, $start_mm, $start_jj, $start_hh, $start_mn);
- $end_aa = $posted_data['end_aa'];
- $end_mm = $posted_data['end_mm'];
- $end_jj = $posted_data['end_jj'];
- $end_hh = $posted_data['end_hh'];
- $end_mn = $posted_data['end_mn'];
- $end_ss = $posted_data['end_ss'];
- $end_mr = $posted_data['end_mr'];
- $end_mr = ($end_mr == 'AM') ? 'AM' : 'PM';
- $end_hh = (($end_mr == 'PM' && $end_hh != 12) || ($end_mr != 'PM' && $end_hh = 12)) ? $end_hh + 12 : $end_hh;
- $end_aa = ($end_aa <= 0 ) ? date('Y') : $end_aa;
- $end_mm = ($end_mm <= 0 ) ? date('n') : $end_mm;
- $end_jj = ($end_jj > 31 ) ? 31 : $end_jj;
- $end_jj = ($end_jj <= 0 ) ? date('j') : $end_jj;
- if($is_allday)
- {
- $end_mn = $end_hh = '00';
- }
- else
- {
- $end_hh = ($end_hh > 23 ) ? $end_hh -24 : $end_hh;
- $end_mn = ($end_mn > 59 ) ? $end_mn -60 : $end_mn;
- }
- $end_datetime = sprintf( "%04d-%02d-%02d %02d:%02d:00", $end_aa, $end_mm, $end_jj, $end_hh, $end_mn);
- update_post_meta($posted_data['post_ID'], 'event_is_allday', $is_allday ? '1' : '0');
- update_post_meta($posted_data['post_ID'], 'event_end_datetime', $end_datetime);
- }
- }
- return $data;
- }
- /**
- * Submit box for Events, replaces default submit box to add end date and all day option
- *
- * @param object $post
- */
- public function submit_meta_box($post)
- {
- global $action, $wp_locale;
- $post_type_obj = get_post_type_object($post->post_type);
- $can_publish = current_user_can($post_type_obj->cap->publish_posts);
- ?>
- <div class="submitbox" id="submitpost">
- <?php wp_nonce_field('update_event', 'update_event_nonce');?>
- <div id="minor-publishing">
- <?php // Hidden submit button early on so that the browser chooses the right button when form is submitted with Return key ?>
- <div style="display:none;">
- <input type="submit" name="save" value="<?php esc_attr_e('Save'); ?>" />
- </div>
- <div id="minor-publishing-actions">
- <div id="save-action">
- <?php if ( 'publish' != $post->post_status && 'future' != $post->post_status && 'pending' != $post->post_status ) : ?>
- <input <?php if ( 'private' == $post->post_status ) { ?>style="display:none"<?php } ?> type="submit" name="save" id="save-post" value="<?php esc_attr_e('Save Draft'); ?>" tabindex="4" class="button button-highlighted" />
- <?php elseif ( 'pending' == $post->post_status && $can_publish ) : ?>
- <input type="submit" name="save" id="save-post" value="<?php esc_attr_e('Save as Pending'); ?>" tabindex="4" class="button button-highlighted" />
- <?php endif; ?>
- </div>
- <div id="preview-action">
- <?php
- if ( 'publish' == $post->post_status ) {
- $preview_link = esc_url(get_permalink($post->ID));
- $preview_button = __('Preview Changes');
- } else {
- $preview_link = esc_url(apply_filters('preview_post_link', add_query_arg('preview', 'true', get_permalink($post->ID))));
- $preview_button = __('Preview');
- }
- ?>
- <a class="preview button" href="<?php echo $preview_link; ?>" target="wp-preview" id="post-preview" tabindex="4"><?php echo $preview_button; ?></a>
- <input type="hidden" name="wp-preview" id="wp-preview" value="" />
- </div>
- <div class="clear"></div>
- </div><?php // /minor-publishing-actions ?>
- <div id="misc-publishing-actions">
- <div class="misc-pub-section<?php if ( !$can_publish ) { echo ' misc-pub-section-last'; } ?>">
- <label for="post_status"><?php _e('Status:') ?></label>
- <span id="post-status-display">
- <?php
- switch ( $post->post_status ) {
- case 'private':
- _e('Privately Published');
- break;
- case 'publish':
- _e('Published');
- break;
- case 'future':
- _e('Scheduled');
- break;
- case 'pending':
- _e('Pending Review');
- break;
- case 'draft':
- _e('Draft');
- break;
- }
- ?>
- </span>
- <?php if ( 'publish' == $post->post_status || 'private' == $post->post_status || $can_publish ) : ?>
- <a href="#post_status" <?php if ( 'private' == $post->post_status ) { ?>style="display:none;" <?php } ?>class="edit-post-status hide-if-no-js" tabindex='4'><?php _e('Edit') ?></a>
- <div id="post-status-select" class="hide-if-js">
- <input type="hidden" name="hidden_post_status" id="hidden_post_status" value="<?php echo esc_attr($post->post_status); ?>" />
- <select name='post_status' id='post_status' tabindex='4'>
- <?php if ( $can_publish ) : ?>
- <option<?php selected( $post->post_status, 'publish' ); ?> value='publish'><?php _e('Published') ?></option>
- <option<?php selected( $post->post_status, 'private' ); ?> value='publish'><?php _e('Privately Published') ?></option>
- <option<?php selected( $post->post_status, 'future' ); ?> value='future'><?php _e('Scheduled') ?></option>
- <?php endif; ?>
- <option<?php selected( $post->post_status, 'pending' ); ?> value='pending'><?php _e('Pending Review') ?></option>
- <option<?php selected( $post->post_status, 'draft' ); ?> value='draft'><?php _e('Draft') ?></option>
- </select>
- <a href="#post_status" class="save-post-status hide-if-no-js button"><?php _e('OK'); ?></a>
- <a href="#post_status" class="cancel-post-status hide-if-no-js"><?php _e('Cancel'); ?></a>
- </div>
- <?php endif; ?>
- </div><?php // /misc-pub-section ?>
- <div class="misc-pub-section " id="visibility">
- <?php _e('Visibility:'); ?>
- <span id="post-visibility-display">
- <?php
- if ( 'private' == $post->post_status )
- {
- $post->post_password = '';
- $visibility = 'private';
- $visibility_trans = __('Private');
- }
- elseif ( !empty( $post->post_password ) )
- {
- $visibility = 'password';
- $visibility_trans = __('Password protected');
- }
- else
- {
- $visibility = 'public';
- $visibility_trans = __('Public');
- }
- echo esc_html( $visibility_trans );
- ?>
- </span>
- <?php if ( $can_publish ) : ?>
- <a href="#visibility" class="edit-visibility hide-if-no-js"><?php _e('Edit'); ?></a>
- <div id="post-visibility-select" class="hide-if-js">
- <input type="hidden" name="hidden_post_password" id="hidden-post-password" value="<?php echo esc_attr($post->post_password); ?>" />
- <input type="hidden" name="hidden_post_visibility" id="hidden-post-visibility" value="<?php echo esc_attr( $visibility ); ?>" />
- <input type="radio" name="visibility" id="visibility-radio-public" value="public" <?php checked( $visibility, 'public' ); ?> /> <label for="visibility-radio-public" class="selectit"><?php _e('Public'); ?></label><br />
- <input type="radio" name="visibility" id="visibility-radio-password" value="password" <?php checked( $visibility, 'password' ); ?> /> <label for="visibility-radio-password" class="selectit"><?php _e('Password protected'); ?></label><br />
- <span id="password-span"><label for="post_password"><?php _e('Password:'); ?></label> <input type="text" name="post_password" id="post_password" value="<?php echo esc_attr($post->post_password); ?>" /><br /></span>
- <input type="radio" name="visibility" id="visibility-radio-private" value="private" <?php checked( $visibility, 'private' ); ?> /> <label for="visibility-radio-private" class="selectit"><?php _e('Private'); ?></label><br />
- <p>
- <a href="#visibility" class="save-post-visibility hide-if-no-js button"><?php _e('OK'); ?></a>
- <a href="#visibility" class="cancel-post-visibility hide-if-no-js"><?php _e('Cancel'); ?></a>
- </p>
- </div>
- <?php endif; ?>
- </div><?php // /misc-pub-section ?>
- <?php
- $tab_index_attribute = ' tabindex="4"';
- if ( 0 != $post->ID )
- {
- $start_datetime = strtotime($post->post_date);
- if(!$end_date_sql = get_post_meta($post->ID, 'event_end_datetime', true))
- {
- $end_datetime = $start_datetime;
- }
- else
- {
- $end_datetime = strtotime($end_date_sql);
- }
- $is_allday = (bool)get_post_meta($post->ID, 'event_is_allday', true);
- }
- else
- {
- $start_datetime = current_time('timestamp');
- $end_datetime = current_time('timestamp');
- $is_allday = false;
- }
- $start_jj = date( 'd', $start_datetime);
- $start_mm = date( 'm', $start_datetime);
- $start_aa = date( 'Y', $start_datetime);
- $start_hh = date( 'g', $start_datetime);
- $start_mn = date( 'i', $start_datetime);
- $start_ss = date( 's', $start_datetime);
- $start_mr = date( 'A', $start_datetime);
- $end_jj = date( 'd', $end_datetime);
- $end_mm = date( 'm', $end_datetime);
- $end_aa = date( 'Y', $end_datetime);
- $end_hh = date( 'g', $end_datetime);
- $end_mn = date( 'i', $end_datetime);
- $end_ss = date( 's', $end_datetime);
- $end_mr = date( 'A', $end_datetime);
- $start_month = "<select id=\"start_mm\" name=\"start_mm\"$tab_index_attribute>\n";
- for ( $i = 1; $i < 13; $i = $i +1 ) {
- $start_month .= "\t\t\t" . '<option value="' . zeroise($i, 2) . '"';
- if ( $i == $start_mm )
- $start_month .= ' selected="selected"';
- $start_month .= '>' . $wp_locale->get_month_abbrev( $wp_locale->get_month( $i ) ) . "</option>\n";
- }
- $start_month .= '</select>';
- $end_month = "<select id=\"end_mm\" name=\"end_mm\"$tab_index_attribute>\n";
- for ( $i = 1; $i < 13; $i = $i +1 ) {
- $end_month .= "\t\t\t" . '<option value="' . zeroise($i, 2) . '"';
- if ( $i == $end_mm )
- $end_month .= ' selected="selected"';
- $end_month .= '>' . $wp_locale->get_month_abbrev( $wp_locale->get_month( $i ) ) . "</option>\n";
- }
- $end_month .= '</select>';
- $start_day = '<input type="text" id="start_jj" name="start_jj" value="' . $start_jj . '" size="2" maxlength="2"' . $tab_index_attribute . ' autocomplete="off" />';
- $start_year = '<input type="text" id="start_aa" name="start_aa" value="' . $start_aa . '" size="4" maxlength="4"' . $tab_index_attribute . ' autocomplete="off" />';
- $start_hour = '<input type="text" id="start_hh" name="start_hh" value="' . $start_hh . '" size="2" maxlength="2"' . $tab_index_attribute . ' autocomplete="off" />';
- $start_minute = '<input type="text" id="start_mn" name="start_mn" value="' . $start_mn . '" size="2" maxlength="2"' . $tab_index_attribute . ' autocomplete="off" />';
- $start_meridian = '<select id="start_mr" name="start_mr" '.$tab_index_attribute.'>';
- $start_meridian.= '<option value="AM" '.('AM' == $start_mr ? 'selected="selected"' : '').'>AM</option>';
- $start_meridian.= '<option value="PM" '.('PM' == $start_mr ? 'selected="selected"' : '').'>PM</option>';
- $start_meridian.= '</select>';
- $end_day = '<input type="text" id="end_jj" name="end_jj" value="'. $end_jj . '" size="2" maxlength="2"' . $tab_index_attribute . ' autocomplete="off" />';
- $end_year = '<input type="text" id="end_aa" name="end_aa" value="' . $end_aa . '" size="4" maxlength="4"' . $tab_index_attribute . ' autocomplete="off" />';
- $end_hour = '<input type="text" id="end_hh" name="end_hh" value="' . $end_hh . '" size="2" maxlength="2"' . $tab_index_attribute . ' autocomplete="off" />';
- $end_minute = '<input type="text" id="end_mn" name="end_mn" value="' . $end_mn . '" size="2" maxlength="2"' . $tab_index_attribute . ' autocomplete="off" />';
- $end_meridian = '<select id="end_mr" name="end_mr" '.$tab_index_attribute.'>';
- $end_meridian.= '<option value="AM" '.('AM' == $end_mr ? 'selected="selected"' : '').'>AM</option>';
- $end_meridian.= '<option value="PM" '.('PM' == $end_mr ? 'selected="selected"' : '').'>PM</option>';
- $end_meridian.= '</select>';
- ?>
- <div class="misc-pub-section curtime misc-pub-section-last">
- <div id="div_allday">
- <label for="event_is_allday">Is All Day Event?</label>
- <input type="checkbox" id="event_is_allday" name="event_is_allday"<?php echo $is_allday ? 'checked="checked"' : ''?> />
- </div>
- <div>
- <span>Start Date: </span>
- <?php echo "$start_month $start_day, $start_year"?>
- </div>
- <div id="div_start_time">
- <span>Start Time: </span>
- <?php echo "$start_hour : $start_minute $start_meridian"?>
- </div>
- <div>
- <span>End Date: </span>
- <?php echo "$end_month $end_day, $end_year"?>
- </div>
- <div id="div_end_time">
- <span>End Time: </span>
- <?php echo "$end_hour : $end_minute $end_meridian"?>
- </div>
- </div>
- </div>
- <div class="clear"></div>
- </div>
- <div id="major-publishing-actions">
- <?php do_action('post_submitbox_start'); ?>
- <div id="delete-action">
- <?php if ( ( 'edit' == $action ) && current_user_can('delete_page', $post->ID) ) : ?>
- <a class="submitdelete deletion" href="<?php echo wp_nonce_url("page.php?action=trash&post=$post->ID", 'trash-page_' . $post->ID); ?>"><?php _e('Move to Trash'); ?></a>
- <?php endif; ?>
- </div>
- <div id="publishing-action">
- <?php if ( !in_array( $post->post_status, array('publish', 'future', 'private') ) || 0 == $post->ID ) : ?>
- <?php if ( $can_publish ) : ?>
- <input name="original_publish" type="hidden" id="original_publish" value="<?php esc_attr_e('Publish') ?>" />
- <input name="publish" type="submit" class="button-primary" id="publish" tabindex="5" accesskey="p" value="<?php esc_attr_e('Publish') ?>" />
- <?php else : ?>
- <input name="original_publish" type="hidden" id="original_publish" value="<?php esc_attr_e('Submit for Review') ?>" />
- <input name="publish" type="submit" class="button-primary" id="publish" tabindex="5" accesskey="p" value="<?php esc_attr_e('Submit for Review') ?>" />
- <?php endif; ?>
- <?php else: ?>
- <input name="original_publish" type="hidden" id="original_publish" value="<?php esc_attr_e('Update Page') ?>" />
- <input name="save" type="submit" class="button-primary" id="publish" tabindex="5" accesskey="p" value="<?php esc_attr_e('Update Page') ?>" />
- <?php endif; ?>
- </div>
- <div class="clear"></div>
- </div>
- </div>
- <?php
- }
- /**
- * Filter for 'get_previous_posts_where'
- *
- * @todo check that this is still needed in 3.0
- *
- * @param string $where
- * @return string
- */
- public function filter_get_previous_next_post_where($where)
- {
- global $post;
- if($post->post_type == $this->get_content_type())
- {
- $where = str_replace("post_type = 'post'", "post_type = '".$this->get_content_type()."'", $where);
- }
- return $where;
- }
- /**
- * Filters for handle_404 to allow months with no events not to 404
- *
- * @todo This is dependent on http://core.trac.wordpress.org/ticket/10722
- *
- * @param bool $handle_404
- * @return bool
- */
- public function should_handle_404($handle_404)
- {
- global $wp_query;
- if($handle_404 && get_query_var('post_type') == $this->get_content_type())
- {
- $handle_404 = false;
- }
- return $handle_404;
- }
- /**
- * The following 2 functions are a work around to keep empty months from 404ing
- * until http://core.trac.wordpress.org/ticket/10722 is available.
- *
- */
- public function handle_404_workaround()
- {
- if(get_query_var('post_type') == $this->get_content_type() && is_date())
- {
- global $wp_query;
- $wp_query->is_category = true;
- $wp_query->queried_object = true;
- }
- }
- public function reset_handle_404_workaround()
- {
- if(get_query_var('post_type') == $this->get_content_type() && is_date())
- {
- global $wp_query;
- $wp_query->is_category = false;
- unset($wp_query->queried_object);
- }
- }
- /**
- * Runs on 'posts_where_request' to exclude events that ended previous to today.
- *
- * @param string $where
- * @return string
- */
- public function filter_events_where($where)
- {
- global $wpdb;
- if(!is_admin() && ($this->get_content_type() == get_query_var('post_type') || get_query_var('taxonomy') == 'venue'))
- {
- $gmt_time = current_time('timestamp');
- $gmt_bod = mktime(0, 0, 0, date('m', $gmt_time), date('j', $gmt_time), date('Y', $gmt_time));
- $where.= $wpdb->prepare(" AND (($wpdb->posts.post_date >= %s AND EndDate.meta_value is null) OR EndDate.meta_value >= %s)", gmdate('Y-m-d H:i:s', $gmt_bod), gmdate('Y-m-d H:i:s', $gmt_bod));
- }
- return $where;
- }
- /**
- * Runs on 'posts_join_request' filter to add joins needed for filter_events_where method.
- *
- * @param string $join
- * @return string
- */
- public function filter_events_join($join)
- {
- global $wpdb;
- if(!is_admin() && ($this->get_content_type() == get_query_var('post_type') || get_query_var('taxonomy') == 'venue'))
- {
- $join.= "LEFT JOIN $wpdb->postmeta EndDate ON EndDate.post_id = $wpdb->posts.ID AND EndDate.meta_key = 'event_end_datetime' ";
- }
- return $join;
- }
- /**
- * Redirects the events home to the current month.
- *
- */
- public function redirect_event_landing()
- {
- if(in_array($_SERVER['REQUEST_URI'], array('/events', '/events/')))
- {
- wp_redirect(site_url('events'.date('/Y/m/')));
- die();
- }
- if(function_exists('wpcom_is_vip') && (strpos($_SERVER['REQUEST_URI'], '/events?s=') !== false || strpos($_SERVER['REQUEST_URI'], '/events/?s=') !== false))
- {
- wp_redirect(site_url('events/search/'.urlencode($_REQUEST['s']).'/'));
- die();
- }
- }
- /**
- * Adds a date based template for events
- *
- * @param string $template
- * @return string
- */
- public function filter_date_template($template)
- {
- if($this->get_content_type() == get_query_var('post_type'))
- {
- $date_template = locate_template(array('date-calendar_event.php'));
- if($date_template) $template = $date_template;
- }
- return $date_template;
- }
- }
- $cal_handler = new CP_Calendar_Event_Handler();
- add_action('setup_custom_content', array($cal_handler, 'on_setup_custom_content'));
- add_action('save_post', array($cal_handler, 'on_save_event'), 10, 2);
- add_filter('request', array($cal_handler, 'filter_request_query_vars'));
- //add_filter('posts_request', array($cal_handler, 'fix_request'), 10, 1); //added for debugging
- add_action('init', array($cal_handler, 'redirect_event_landing'));
- /**
- * @todo the handle_404 filter requires ticket http://core.trac.wordpress.org/ticket/10722 to be available.
- * the other two functions are a work around until then.
- */
- //add_filter('handle_404', array($cal_handler, 'should_handle_404'), 10, 1);
- add_action('posts_selection', array($cal_handler, 'handle_404_workaround'), 10, 1);
- add_action('template_redirect', array($cal_handler, 'reset_handle_404_workaround'));
- add_filter('date_template', array($cal_handler, 'filter_date_template'), 10, 1);
- add_action('add_meta_boxes_'.$cal_handler->get_content_type(), array($cal_handler, 'add_meta_boxes'), 10, 1);
- add_filter('wp_insert_post_data', array($cal_handler, 'filter_wp_insert_post_data'), 10, 2);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement