/**
 * If a menu isn't being used the above won't work. They're using wp_list_pages, so the
 * best we can do is append a link to the end of the list.
 * Hooked onto wp_list_pages
 *
 * @ignore
 * @access private
 * @since 1.0
 */
function eventorganiser_menu_link($items)
{
    if (eventorganiser_get_option('addtomenu') != '1') {
        return $items;
    }
    $class = 'menu-item menu-item-type-event';
    if (is_post_type_archive('event') || is_singular('event') || eo_is_event_taxonomy()) {
        $class = 'current_page_item';
    }
    $items .= sprintf('<li class="%s"><a href="%s" > %s </a></li>', $class, get_post_type_archive_link('event'), esc_html(eventorganiser_get_option('navtitle')));
    return $items;
}
/**
 * Checks whether a given query is for events
 * @package event-query-functions
 * @param WP_Query $query The query to test
 * @param bool $exclusive Whether to test if the query is *exclusively* for events, or can include other post types
 * @return bool True if the query is an event query. False otherwise.
 */
function eventorganiser_is_event_query($query, $exclusive = false)
{
    $post_types = $query->get('post_type');
    if ('any' == $post_types) {
        $post_types = get_post_types(array('exclude_from_search' => false));
    }
    if ($post_types == 'event' || array('event') == $post_types) {
        $bool = true;
    } elseif ($query && $query->is_feed('eo-events') || is_feed('eo-events')) {
        $bool = true;
    } elseif (empty($post_types) && eo_is_event_taxonomy($query)) {
        //Querying by taxonomy - check if 'event' is the only post type
        $post_types = array();
        $taxonomies = wp_list_pluck($query->tax_query->queries, 'taxonomy');
        foreach (get_post_types() as $pt) {
            if (version_compare('3.4', get_bloginfo('version')) <= 0) {
                $object_taxonomies = $pt === 'attachment' ? get_taxonomies_for_attachments() : get_object_taxonomies($pt);
            } else {
                //Backwards compat for 3.3
                $object_taxonomies = $pt === 'attachment' ? array() : get_object_taxonomies($pt);
            }
            if (array_intersect($taxonomies, $object_taxonomies)) {
                $post_types[] = $pt;
            }
        }
        if (in_array('event', $post_types)) {
            if ($exclusive && 1 == count($post_types)) {
                $query->set('post_type', 'event');
                $bool = true;
            } elseif (!$exclusive) {
                $bool = true;
            } else {
                $bool = false;
            }
        } else {
            $bool = false;
        }
    } elseif ($exclusive) {
        $bool = false;
    } elseif (is_array($post_types) && in_array('event', $post_types)) {
        $bool = true;
    } else {
        $bool = false;
    }
    /**
     * Filters whether the query is an event query.
     * 
     * This should be `true` if the query is for events, `false` otherwise. The 
     * third parameter, `$exclusive` qualifies if this means 'query exclusively 
     * for events' or not. If `true` then this filter should return `true` only 
     * if the query is exclusively for events.
     * 
     * @param bool     $bool      Whether the query is an event query.
     * @param WP_Query $query     The WP_Query instance to check.
     * @param bool     $exclusive Whether the check if for queries exclusively for events. 
     */
    return apply_filters('eventorganiser_is_event_query', $bool, $query, $exclusive);
}
/**
 * Checks whether a given query is for events
 * @package event-query-functions
 * @param WP_Query $query The query to test
 * @param bool $exclusive Whether to test if the query is *exclusively* for events, or can include other post types
 * @return bool True if the query is an event query. False otherwise.
 */
function eventorganiser_is_event_query($query, $exclusive = false)
{
    $post_types = $query->get('post_type');
    if ('any' == $post_types) {
        $post_types = get_post_types(array('exclude_from_search' => false));
    }
    if ($post_types == 'event' || array('event') == $post_types) {
        $bool = true;
    } elseif ($query && $query->is_feed('eo-events') || is_feed('eo-events')) {
        $bool = true;
    } elseif (empty($post_types) && eo_is_event_taxonomy($query)) {
        //Querying by taxonomy - check if 'event' is the only post type
        $post_types = array();
        $taxonomies = wp_list_pluck($query->tax_query->queries, 'taxonomy');
        foreach (get_post_types() as $pt) {
            if (version_compare('3.4', get_bloginfo('version')) <= 0) {
                $object_taxonomies = $pt === 'attachment' ? get_taxonomies_for_attachments() : get_object_taxonomies($pt);
            } else {
                //Backwards compat for 3.3
                $object_taxonomies = $pt === 'attachment' ? array() : get_object_taxonomies($pt);
            }
            if (array_intersect($taxonomies, $object_taxonomies)) {
                $post_types[] = $pt;
            }
        }
        if (in_array('event', $post_types)) {
            if ($exclusive && 1 == count($post_types)) {
                $query->set('post_type', 'event');
                $bool = true;
            } elseif (!$exclusive) {
                $bool = true;
            } else {
                $bool = false;
            }
        } else {
            $bool = false;
        }
    } elseif ($exclusive) {
        $bool = false;
    } elseif (is_array($post_types) && in_array('event', $post_types)) {
        $bool = true;
    } else {
        $bool = false;
    }
    return apply_filters('eventorganiser_is_event_query', $bool, $query, $exclusive);
}
function eventorganiser_menu_link($items)
{
    $eo_options = get_option('eventorganiser_options');
    if ($eo_options['addtomenu'] != '1') {
        return $items;
    }
    global $wp_query;
    $title = isset($eo_options['navtitle']) ? $eo_options['navtitle'] : 'Events';
    $class = 'menu-item menu-item-type-event';
    if (is_post_type_archive('event') || is_singular('event') || eo_is_event_taxonomy()) {
        $class = 'current_page_item';
    }
    $eventlink = '<li class="' . $class . '"><a href="' . get_post_type_archive_link('event') . '">' . $title . '</a></li>';
    $items = $items . $eventlink;
    return $items;
}