Example #1
0
/**
 * Custom metaboxes above th editor
 *
 * @global string $post_type
 */
function wp_event_calendar_editor_below()
{
    global $post_type, $post;
    // Description title
    if (!in_array($post_type, wp_event_calendar_allowed_post_types())) {
        return;
    }
    // Below editor
    do_meta_boxes($post_type, 'below_event_editor', $post);
}
Example #2
0
/**
 * Update post statuses
 *
 * @since 0.1.9
 */
function wp_event_calendar_update_post_statuses()
{
    // End of day, today
    $eod = gmdate('Y-m-d H:i:s', strtotime('midnight tomorrow'));
    // Get old events
    $old_events = new WP_Query(array('fields' => 'ids', 'post_type' => wp_event_calendar_allowed_post_types(), 'post_status' => 'publish', 'posts_per_page' => -1, 'meta_query' => array(array('relation' => 'AND', array('key' => 'wp_event_calendar_date_time', 'value' => $eod, 'type' => 'DATETIME', 'compare' => '<'), array('key' => 'wp_event_calendar_end_date_time', 'value' => $eod, 'type' => 'DATETIME', 'compare' => '<')))));
    // Bail if no posts
    if (empty($old_events->posts)) {
        return;
    }
    // Loop through posts and update status
    foreach ($old_events->posts as $post_id) {
        wp_update_post(array('ID' => $post_id, 'post_status' => 'passed'));
    }
}
Example #3
0
/**
 * Query for events
 *
 * @since 0.4.0
 *
 * @param array $args See WP_Query
 *
 * @return array Array of post objects
 */
function wp_get_events($args = array())
{
    // Parse arguments
    $r = wp_parse_args($args, array('post_type' => wp_event_calendar_allowed_post_types(), 'post_status' => array('publish', 'future'), 'posts_per_page' => -1, 'orderby' => 'meta_value', 'order' => 'ASC', 'hierarchical' => false, 'ignore_sticky_posts' => true, 'suppress_filters' => true, 'no_found_rows' => true, 'meta_query' => wp_event_calendar_get_meta_query()));
    // Query for events
    $query = new WP_Query($r);
    // Return posts
    return $query->posts;
}
Example #4
0
/**
 * Reorder "Events" submenu items to reprioritize "Calendar"
 *
 * @since 0.1.0
 *
 * @param  array $menu_order
 *
 * @return array
 */
function wp_event_calendar_change_menu_order($menu_order = array())
{
    global $submenu;
    // Setup a bunch of empty arrays
    $neighbors = $calendar_menus = $calendar_submenus = array();
    // Get allowed post types
    $allowed_types = wp_event_calendar_allowed_post_types();
    // Loop through allowed types
    foreach ($allowed_types as $type) {
        // Find "All" links
        if ('post' === $type) {
            $pt = 'edit.php';
        } else {
            $pt = 'edit.php?post_type=' . $type;
        }
        $neighbors[] = $pt;
        // Custom menus
        $calendar_menus[] = $type . '-calendar';
        // The calendar submenu arrays
        $calendar_submenus[$pt] = array(esc_html__('Calendar', 'wp-event-calendar'), 'edit_posts', $type . '-calendar', esc_html__('Calendar', 'wp-event-calendar'));
    }
    // Loop through menu order and do some rearranging
    foreach ($submenu as $parent => $children) {
        // Skip if no neighborly match
        if (in_array($parent, $neighbors)) {
            foreach ($children as $child => $menu) {
                // Found a neighbor
                if (in_array($menu[2], $neighbors)) {
                    unset($submenu[$parent][$child]);
                    $submenu[$parent][$child] = $menu;
                    $submenu[$parent][9] = $calendar_submenus[$parent];
                } elseif (in_array($menu[2], $calendar_menus)) {
                    unset($submenu[$parent][$child]);
                }
            }
            ksort($submenu[$parent]);
        }
    }
    // Always return the menu order
    return $menu_order;
}
Example #5
0
/**
 * Event Metabox
 *
 * @since  0.1.1
*/
function wp_event_calendar_add_metabox()
{
    add_meta_box('wp_event_calendar_duration', __('Duration', 'wp-event-calendar'), 'wp_event_calendar_duration_metabox', wp_event_calendar_allowed_post_types(), 'above_event_editor', 'default');
    add_meta_box('wp_event_calendar_details', __('Details', 'wp-event-calendar'), 'wp_event_calendar_details_metabox', wp_event_calendar_allowed_post_types(), 'above_event_editor', 'default');
}