/** * Load defaults function. */ public function load_defaults() { $this->category_fields = apply_filters('em_event_category_fields', array('color' => array('id' => 'em-color', 'type' => 'color_picker', 'label' => __('Color', 'events-maker'), 'default' => '', 'description' => 'The color of events filed under that category (to be used in Full Calendar display).', 'column' => true, 'column_cb' => array(&$this, 'event_category_manage_columns_content')))); $this->location_fields = apply_filters('em_event_location_fields', array('google_map' => array('id' => 'em-google_map', 'type' => 'google_map', 'label' => __('Google Map', 'events-maker'), 'default' => '', 'description' => '', 'column' => false), 'address' => array('id' => 'em-address', 'type' => 'text', 'label' => __('Address', 'events-maker'), 'default' => '', 'description' => '', 'column' => false), 'city' => array('id' => 'em-city', 'type' => 'text', 'label' => __('City', 'events-maker'), 'default' => '', 'description' => '', 'column' => false), 'state' => array('id' => 'em-state', 'type' => 'text', 'label' => __('State / Province', 'events-maker'), 'default' => '', 'description' => '', 'column' => false), 'zip' => array('id' => 'em-zip', 'type' => 'text', 'label' => __('Zip Code', 'events-maker'), 'default' => '', 'description' => '', 'column' => false), 'country' => array('id' => 'em-country', 'type' => 'select', 'label' => __('Country', 'events-maker'), 'default' => '', 'description' => '', 'options' => Events_Maker()->localisation->countries, 'column' => false), 'image' => array('id' => 'em-image', 'type' => 'image', 'label' => __('Image', 'events-maker'), 'default' => '', 'description' => '', 'column' => false))); $this->organizer_fields = apply_filters('em_event_organizer_fields', array('contact_name' => array('id' => 'em-contact_name', 'type' => 'text', 'label' => __('Contact name', 'events-maker'), 'default' => '', 'description' => '', 'column' => false), 'phone' => array('id' => 'em-phone', 'type' => 'text', 'label' => __('Phone', 'events-maker'), 'default' => '', 'description' => '', 'column' => false), 'email' => array('id' => 'em-email', 'type' => 'email', 'label' => __('E-mail', 'events-maker'), 'default' => '', 'description' => '', 'column' => false), 'website' => array('id' => 'em-website', 'type' => 'url', 'label' => __('Website', 'events-maker'), 'default' => '', 'description' => '', 'column' => false), 'image' => array('id' => 'em-image', 'type' => 'image', 'label' => __('Image', 'events-maker'), 'default' => '', 'description' => '', 'column' => false))); $this->taxonomy_field_args = apply_filters('em_taxonomy_field_args', array('container' => 'div', 'class' => array('form-field'), 'description_container' => 'p', 'description_class' => array('description'), 'label_container' => 'label', 'label_class' => array(), 'input_class' => array(), 'required' => false, 'readonly' => false, 'return' => true, 'context' => '')); }
public function __construct() { // set instance Events_Maker()->localisation = $this; // actions add_action('after_setup_theme', array(&$this, 'load_defaults')); }
public function __construct() { // set instance Events_Maker()->welcome = $this; // actions add_action('admin_menu', array(&$this, 'admin_menus')); add_action('admin_head', array(&$this, 'admin_head')); add_action('admin_init', array(&$this, 'welcome')); }
public function __construct() { // set instance Events_Maker()->ical = $this; if ((int) Events_Maker()->options['general']['ical_feed'] != false) { //actions add_action('init', array(&$this, 'add_events_ical_feed')); //filters add_filter('parse_request', array(&$this, 'parse_ical_request')); } }
/** * Locate and include template files. */ public function template_include($template) { if (Events_Maker()->options['templates']['default_templates'] === true) { if (is_post_type_archive('event')) { $new_template = em_locate_template('archive-event.php'); } if (is_tax('event-category')) { $new_template = em_locate_template('taxonomy-event-category.php'); } if (is_tax('event-location')) { $new_template = em_locate_template('taxonomy-event-location.php'); } if (is_tax('event-organizer')) { $new_template = em_locate_template('taxonomy-event-organizer.php'); } if (is_tax('event-tag')) { $new_template = em_locate_template('taxonomy-event-tag.php'); } if (is_singular('event')) { $new_template = em_locate_template('single-event.php'); } } return apply_filters('em_template_include', !empty($new_template) ? $new_template : $template); }
/** * Save event metaboxes data. */ public function save_event($post_ID) { // break if doing autosave if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { return $post_ID; } // break if current user can't edit events if (!current_user_can('edit_event', $post_ID)) { return $post_ID; } // delete calendar transient / cache // WPML support if (class_exists('SitePress') && array_key_exists('sitepress', $GLOBALS)) { global $wpdb; $query = $wpdb->prepare("SELECT language_code FROM {$wpdb->prefix}icl_translations WHERE element_type LIKE '%%post_%%' AND element_id = %d", $post_ID); $language = $wpdb->get_row($query, 'ARRAY_A'); if ($language) { delete_transient('em_calendar_query-' . $language['language_code']); } // Polylang support } elseif (class_exists('Polylang') && function_exists('pll_default_language')) { global $polylang; $language = $polylang->model->get_post_language($post_ID); if ($language) { delete_transient('em_calendar_query-' . $language->slug); } } else { delete_transient('em_calendar_query'); } // event gallery validation if (isset($_POST['event_gallery']) && wp_verify_nonce($_POST['event_nonce_gallery'], 'events_maker_save_event_gallery')) { $attachment_ids = array_map('esc_attr', array_filter(explode(',', $_POST['event_gallery']))); update_post_meta($post_ID, '_event_gallery', implode(',', $attachment_ids)); } // event date & time validation if (isset($_POST['event_nonce_datetime']) && wp_verify_nonce($_POST['event_nonce_datetime'], 'events_maker_save_event_datetime')) { // event date and time section $em_helper = new Events_Maker_Helper(); $event_all_day = isset($_POST['event_all_day']) ? 1 : 0; $start_date_ok = false; update_post_meta($post_ID, '_event_all_day', $event_all_day); $event_start_date = $event_end_date = $current_datetime = current_time('mysql', false); $current_date = date('Y-m-d', current_time('timestamp', false)); // is it all day long event? if ($event_all_day === 1) { if ($em_helper->is_valid_date($_POST['event_start_date'])) { $start_date_ok = true; update_post_meta($post_ID, '_event_start_date', $_POST['event_start_date'] . ' 00:00:00'); $event_start_date = $_POST['event_start_date'] . ' 00:00:00'; } else { update_post_meta($post_ID, '_event_start_date', $current_datetime); $event_start_date = $current_datetime; } if ($em_helper->is_valid_date($_POST['event_end_date'])) { if ($start_date_ok) { if ($em_helper->is_after_date($_POST['event_end_date'], $_POST['event_start_date'])) { update_post_meta($post_ID, '_event_end_date', $_POST['event_end_date'] . ' 00:00:00'); $event_end_date = $_POST['event_end_date'] . ' 00:00:00'; } else { $event_end_date = $event_start_date; update_post_meta($post_ID, '_event_end_date', $event_end_date); } } else { update_post_meta($post_ID, '_event_end_date', $_POST['event_end_date'] . ' 00:00:00'); $event_end_date = $_POST['event_end_date'] . ' 00:00:00'; } } else { $event_end_date = $event_start_date; update_post_meta($post_ID, '_event_end_date', $event_end_date); } } else { if ($em_helper->is_valid_date($_POST['event_start_date']) && $em_helper->is_valid_time($_POST['event_start_time'])) { $start_date_ok = true; $event_start_date = date('Y-m-d H:i:s', strtotime($_POST['event_start_date'] . ' ' . $_POST['event_start_time'])); update_post_meta($post_ID, '_event_start_date', $event_start_date); } else { update_post_meta($post_ID, '_event_start_date', $current_datetime); $event_start_date = $current_datetime; } if ($em_helper->is_valid_date($_POST['event_end_date']) && $em_helper->is_valid_time($_POST['event_end_time'])) { if ($start_date_ok) { if ($em_helper->is_after_date($_POST['event_end_date'] . ' ' . $_POST['event_end_time'], $_POST['event_start_date'] . ' ' . $_POST['event_start_time'])) { $event_end_date = date('Y-m-d H:i:s', strtotime($_POST['event_end_date'] . ' ' . $_POST['event_end_time'])); update_post_meta($post_ID, '_event_end_date', $event_end_date); } else { $event_end_date = $event_start_date; update_post_meta($post_ID, '_event_end_date', $event_end_date); } } else { $event_end_date = date('Y-m-d H:i:s', strtotime($_POST['event_end_date'] . ' ' . $_POST['event_end_time'])); update_post_meta($post_ID, '_event_end_date', $event_end_date); } } else { $event_end_date = $event_start_date; update_post_meta($post_ID, '_event_end_date', $event_end_date); } } // remove all previous occurrences delete_post_meta($post_ID, '_event_occurrence_date'); delete_post_meta($post_ID, '_event_occurrence_last_date'); // add first occurrence even for one time events update_post_meta($post_ID, '_event_occurrence_date', $event_start_date . '|' . $event_end_date); $recurrence = $_POST['event_recurrence']; if (isset(Events_Maker()->recurrences[$recurrence['type']])) { $recurrence['until'] = date('Y-m-d', strtotime($recurrence['until'])); $today = (int) date('N', strtotime($event_start_date)); if ($recurrence['type'] === 'once') { $event_recurrence = array('type' => 'once', 'repeat' => 1, 'until' => $current_date, 'weekly_days' => array($today), 'monthly_day_type' => 1, 'separate_end_date' => array()); // add last occurrence (same as first) update_post_meta($post_ID, '_event_occurrence_last_date', $event_start_date . '|' . $event_end_date); } elseif ($recurrence['type'] === 'custom') { $event_recurrence = array('type' => 'custom', 'repeat' => 1, 'until' => $current_date, 'weekly_days' => array($today), 'monthly_day_type' => 1); if (!empty($recurrence['custom']['separate_end_date'])) { $separates = $recurrence['custom']['separate_end_date']; } else { $separates = array(); } // add custom dates $event_recurrence['separate_end_date'] = $this->add_custom_dates($post_ID, $recurrence['custom']['dates'], $event_all_day, $separates, $event_start_date, $event_end_date); } else { $weekly_days = array(); $monthly_day_type = 1; if ($recurrence['type'] === 'weekly') { if (isset($recurrence['weekly']['weekly_days'])) { foreach ($recurrence['weekly']['weekly_days'] as $week_id => $weekday) { $id = (int) $week_id; if ($id >= 1 && $id <= 7) { $weekly_days[] = $id; } } if (empty($weekly_days)) { $weekly_days = array($today); } } else { $weekly_days = array($today); } } elseif ($recurrence['type'] === 'monthly') { $weekly_days = array($today); if (isset($recurrence['monthly']['monthly_day_type'])) { $id = (int) $recurrence['monthly']['monthly_day_type']; $monthly_day_type = $id === 2 ? 2 : 1; } } $event_recurrence = array('type' => $recurrence['type'], 'repeat' => ($repeat = (int) $recurrence['repeat']) > 0 ? $repeat : 1, 'until' => $recurrence['until'], 'weekly_days' => $weekly_days, 'monthly_day_type' => $monthly_day_type, 'separate_end_date' => array()); // create occurrences $this->create_recurrences($post_ID, $event_start_date, $event_end_date, $recurrence['type'], $recurrence['repeat'], $recurrence['until'], $weekly_days, $monthly_day_type); } } update_post_meta($post_ID, '_event_recurrence', $event_recurrence); } // event tickets validation, if tickets are in use if (Events_Maker()->options['general']['use_event_tickets'] && isset($_POST['event_nonce_tickets']) && wp_verify_nonce($_POST['event_nonce_tickets'], 'events_maker_save_event_tickets')) { update_post_meta($post_ID, '_event_free', isset($_POST['event_free']) ? 1 : 0); $tickets = array(); if (!isset($_POST['event_free'])) { $ticket_url = isset($_POST['event_tickets_url']) ? $_POST['event_tickets_url'] : ''; if (isset($_POST['event_tickets']) && is_array($_POST['event_tickets']) && !empty($_POST['event_tickets'])) { foreach ($_POST['event_tickets'] as $id => $ticket) { $tickets_fields = array(); $empty = 0; foreach ($this->tickets_fields as $key => $trans) { $tickets_fields[$key] = sanitize_text_field(isset($ticket[$key]) ? $ticket[$key] : ''); $empty += $tickets_fields[$key] !== '' ? 1 : 0; } if ($empty > 0) { $tickets[$id] = $tickets_fields; } } if (empty($tickets)) { $ticket_url = ''; update_post_meta($post_ID, '_event_free', 1); } update_post_meta($post_ID, '_event_tickets', $tickets); } else { $ticket_url = ''; update_post_meta($post_ID, '_event_tickets', array()); update_post_meta($post_ID, '_event_free', 1); } update_post_meta($post_ID, '_event_tickets_url', esc_url($ticket_url)); } else { update_post_meta($post_ID, '_event_tickets', $tickets); update_post_meta($post_ID, '_event_tickets_url', ''); } } // event display options validation if (isset($_POST['event_nonce_options']) && wp_verify_nonce($_POST['event_nonce_options'], 'events_maker_save_event_options')) { $options = array('google_map' => __('Google Map', 'events-maker'), 'display_gallery' => __('Event Gallery', 'events-maker'), 'display_location_details' => __('Location Details', 'events-maker')); // if tickets are enabled if (Events_Maker()->options['general']['use_event_tickets']) { $options = array_merge($options, array('price_tickets_info' => __('Tickets', 'events-maker'))); } // if organizers are enabled if (Events_Maker()->options['general']['use_organizers']) { $options = array_merge($options, array('display_organizer_details' => __('Organizer Details', 'events-maker'))); } $options = apply_filters('em_metabox_event_display_options', $options, $post_ID); $values = array(); if (is_array($options) && !empty($options)) { foreach ($options as $key => $name) { $values[$key] = isset($_POST['event_display_options'][$key]) ? true : false; } } update_post_meta($post_ID, '_event_display_options', $values); // validate featured event update_post_meta($post_ID, '_event_featured', isset($_POST['event_featured']) && !empty($_POST['event_featured']) ? true : false); } }
/** * Retrive specific page id. * * @param string $page * @return int */ function em_get_page_id($page = '') { $page_id = Events_Maker()->admin->get_action_page_id($page); return $page_id ? absint($page_id) : 0; }
/** * Synchronize events base permalink on events page update. */ public function synchronize_save_post($post_id, $post) { // break, if user has no cap if (!current_user_can('edit_post', $post_id)) { return $post_id; } // break, if it's not event page being updated if ($post_id !== (int) Events_Maker()->options['general']['pages']['events']['id']) { return $post_id; } // break, if it is just a revision if (wp_is_post_revision($post_id)) { return $post_id; } // break, if it's not a page if ($post->post_type != 'page') { return $post_id; } // break, if the post status is not publish if ($post->post_status != 'publish') { return $post_id; } // ok, let's synchronize $this->synchronize_permalink($post_id); }
/** * */ public function check_update() { if (!current_user_can('manage_options')) { return; } // updating? if (isset($_POST['events_maker_update'], $_POST['events_maker_number'])) { if ($_POST['events_maker_number'] === 'update_1') { if (is_multisite() && is_network_admin()) { global $wpdb; $current_blog_id = $wpdb->blogid; $blogs_ids = $wpdb->get_col($wpdb->prepare('SELECT blog_id FROM ' . $wpdb->blogs, '')); foreach ($blogs_ids as $blog_id) { switch_to_blog($blog_id); $current_db_version = get_option('events_maker_version', '1.0.0'); // update only not updated sites if (version_compare($current_db_version, EVENTS_MAKER_UPDATE_VERSION_1, '<=')) { // run update $this->update_1(); // update plugin version update_option('events_maker_version', Events_Maker()->defaults['version']); } } switch_to_blog($current_blog_id); } else { $this->update_1(); // update plugin version update_option('events_maker_version', Events_Maker()->defaults['version']); } Events_Maker()->admin->add_notice(__('Datebase was succesfully updated. Enjoy new features!', 'events-maker'), 'updated', true); } } $update_1_html = ' <form action="" method="post"> <input type="hidden" name="events_maker_number" value="update_1"/> <p>' . __('<strong>Events Maker:</strong> New features require a database update. Make sure you backup your database and then click.', 'events-maker') . ' <input type="submit" class="button button-primary" name="events_maker_update" value="' . __('Update', 'events-maker') . '"/></p> </form>'; // is it multisite network page? if (is_multisite() && is_network_admin()) { global $wpdb; $current_blog_id = $wpdb->blogid; $blogs_ids = $wpdb->get_col($wpdb->prepare('SELECT blog_id FROM ' . $wpdb->blogs, '')); $update_required = false; foreach ($blogs_ids as $blog_id) { switch_to_blog($blog_id); // get current database version $current_db_version = get_option('events_maker_version', '1.0.0'); // new version? if (version_compare($current_db_version, Events_Maker()->defaults['version'], '<')) { // is update 1 required? if (version_compare($current_db_version, EVENTS_MAKER_UPDATE_VERSION_1, '<=')) { $update_required = true; } else { // update plugin version update_option('events_maker_version', Events_Maker()->defaults['version']); } } } if ($update_required) { Events_Maker()->admin->add_notice($update_1_html); } switch_to_blog($current_blog_id); } else { // get current database version $current_db_version = get_option('events_maker_version', '1.0.0'); // new version? if (version_compare($current_db_version, Events_Maker()->defaults['version'], '<')) { // is update 1 required? if (version_compare($current_db_version, EVENTS_MAKER_UPDATE_VERSION_1, '<=')) { Events_Maker()->admin->add_notice($update_1_html); } else { // update plugin version update_option('events_maker_version', Events_Maker()->defaults['version']); } } } }
/** * Get events for calendar display. */ private function get_full_calendar_events($args) { // get calendar query transient / cache if (defined('ICL_LANGUAGE_CODE')) { // WPML & Polylang support $calendar = get_transient('em_calendar_query' . '-' . ICL_LANGUAGE_CODE); } else { $calendar = get_transient('em_calendar_query'); } if ($calendar === false) { $events = em_get_events($args); $calendar = array(); if (empty($events)) { return $calendar; } foreach ($events as $event) { $classes = array(); $event_categories = wp_get_post_terms($event->ID, 'event-category'); $event_tags = wp_get_post_terms($event->ID, 'event-tag'); if (!empty($event_categories) && !is_wp_error($event_categories)) { $term_meta = get_option('event_category_' . $event_categories[0]->term_taxonomy_id); foreach ($event_categories as $category) { $classes[] = "fc-event-cat-" . $category->slug; $classes[] = "fc-event-cat-" . $category->term_id; } } if (!empty($event_tags) && !is_wp_error($event_tags)) { foreach ($event_tags as $tag) { $classes[] = "fc-event-tag-" . $tag->slug; $classes[] = "fc-event-tag-" . $tag->term_id; } } if (em_is_recurring($event->ID) && Events_Maker()->options['general']['show_occurrences']) { $start = $event->event_occurrence_start_date; $end = $event->event_occurrence_end_date; } else { $start = $event->_event_start_date; $end = $event->_event_end_date; } $all_day_event = em_is_all_day($event->ID); $calendar[] = apply_filters('em_calendar_event_data', array('title' => $event->post_title, 'start' => $start, 'end' => $all_day_event ? date('Y-m-d H:i:s', strtotime($end . '+1 day')) : $end, 'className' => implode(' ', $classes), 'allDay' => $all_day_event, 'url' => get_permalink($event->ID), 'backgroundColor' => isset($term_meta['color']) ? $term_meta['color'] : ''), $event); } $expiration = absint(apply_filters('em_calendar_query_expiration', 24 * 60 * 60)); // set calendar query transient / cache if (defined('ICL_LANGUAGE_CODE')) { // WPML & Polylang support set_transient('em_calendar_query' . '-' . ICL_LANGUAGE_CODE, $calendar, $expiration); } else { set_transient('em_calendar_query', $calendar, $expiration); } } return apply_filters('em_shortcode_full_calendar_events', $calendar); }
/** * Check pages on post status change. */ public function transition_post_status_action_page($new_status, $old_status, $post) { if ($post->post_type === 'page' && $old_status === 'publish' && $new_status !== 'publish' && in_array((int) $post->ID, $ids = $this->get_action_page_id(), true)) { foreach (array_keys($ids, (int) $post->ID, true) as $page) { Events_Maker()->options['general']['pages'][$page]['id'] = 0; } Events_Maker()->options['general']['pages_notice'] = !$this->is_action_page_set(Events_Maker()->options['general']['pages']); update_option('events_maker_general', Events_Maker()->options['general']); } }
/** * Add button link to view full events calendar. */ public function view_full_calendar_button() { global $pagenow; if ($pagenow === 'edit.php' && get_post_type() === 'event') { $page_id = 0; // backward compatibility if (isset(Events_Maker()->options['general']['full_calendar_display']['type']) && Events_Maker()->options['general']['full_calendar_display']['type'] === 'page' && isset(Events_Maker()->options['general']['full_calendar_display']['page'])) { $page_id = (int) Events_Maker()->options['general']['full_calendar_display']['page']; } elseif (Events_Maker()->options['general']['pages']['calendar']['position'] != 'manual' && (int) Events_Maker()->options['general']['pages']['calendar']['id'] > 0) { $page_id = (int) Events_Maker()->options['general']['pages']['calendar']['id']; } if ($page_id > 0) { ?> <script type="text/javascript"> jQuery( '.wrap h2 .add-new-h2' ).after( '<a href="<?php echo esc_url(get_permalink($page_id)); ?> " class="add-new-h2"><?php echo __('View Calendar', 'events-maker'); ?> </a>' ); </script> <?php } } }
/** * Get post type and taxonomy slugs. */ public function set_translated_slugs() { $plugin = ''; // check if WPML or Polylang is active include_once ABSPATH . 'wp-admin/includes/plugin.php'; if (is_plugin_active('polylang/polylang.php') && class_exists('Polylang')) { global $polylang; $plugin = 'Polylang'; } elseif (is_plugin_active('sitepress-multilingual-cms/sitepress.php') && is_plugin_active('wpml-string-translation/plugin.php' && class_exists('SitePress'))) { global $sitepress; $plugin = 'WPML'; } if (empty($plugin)) { return; } $languages = array(); $default = ''; // Polylang if ($plugin === 'Polylang' && array_key_exists('polylang', $GLOBALS)) { global $polylang; // get registered languages $registered_languages = $polylang->model->get_languages_list(); if (!empty($registered_languages)) { foreach ($registered_languages as $language) { $languages[] = $language->slug; } } // get default language $default = pll_default_language(); // WPML } elseif ($plugin === 'WPML' && array_key_exists('sitepress', $GLOBALS)) { global $sitepress; // get registered languages $registered_languages = icl_get_languages(); if (!empty($registered_languages)) { foreach ($registered_languages as $language) { $languages[] = $language['language_code']; } } // get default language $default = $sitepress->get_default_language(); $current = $sitepress->get_current_language(); } if (!empty($languages)) { foreach ($languages as $language) { $slugs = array(); if ($plugin === 'Polylang' && function_exists('pll_translate_string')) { // get language strings $slugs['event_rewrite_base'] = pll_translate_string(untrailingslashit(esc_html(Events_Maker()->options['permalinks']['event_rewrite_base'])), $language); $slugs['event_rewrite_slug'] = pll_translate_string(untrailingslashit(esc_html(Events_Maker()->options['permalinks']['event_rewrite_slug'])), $language); $slugs['event_categories_rewrite_slug'] = pll_translate_string(untrailingslashit(esc_html(Events_Maker()->options['permalinks']['event_categories_rewrite_slug'])), $language); $slugs['event_locations_rewrite_slug'] = pll_translate_string(untrailingslashit(esc_html(Events_Maker()->options['permalinks']['event_locations_rewrite_slug'])), $language); if (Events_Maker()->options['general']['use_tags'] === true) { $slugs['event_tags_rewrite_slug'] = pll_translate_string(untrailingslashit(esc_html(Events_Maker()->options['permalinks']['event_tags_rewrite_slug'])), $language); } if (Events_Maker()->options['general']['use_organizers'] === true) { $slugs['event_organizers_rewrite_slug'] = pll_translate_string(untrailingslashit(esc_html(Events_Maker()->options['permalinks']['event_organizers_rewrite_slug'])), $language); } } elseif ($plugin === 'WPML' && function_exists('icl_t')) { $sitepress->switch_lang($language, true); $has_translation = null; // required by WPML icl_t() function $slugs['event_rewrite_base'] = icl_t('Events Maker', 'Event rewrite base', untrailingslashit(esc_html(Events_Maker()->options['permalinks']['event_rewrite_base'])), $has_translation, false, $language); $slugs['event_rewrite_slug'] = icl_t('Events Maker', 'Event rewrite slug', untrailingslashit(esc_html(Events_Maker()->options['permalinks']['event_rewrite_slug'])), $has_translation, false, $language); $slugs['event_categories_rewrite_slug'] = icl_t('Events Maker', 'Event Categories rewrite slug', untrailingslashit(esc_html(Events_Maker()->options['permalinks']['event_categories_rewrite_slug'])), $has_translation, false, $language); $slugs['event_locations_rewrite_slug'] = icl_t('Events Maker', 'Event Locations rewrite slug', untrailingslashit(esc_html(Events_Maker()->options['permalinks']['event_locations_rewrite_slug'])), $has_translation, false, $language); if (Events_Maker()->options['general']['use_tags'] === true) { $slugs['event_tags_rewrite_slug'] = icl_t('Events Maker', 'Event Tags rewrite slug', untrailingslashit(esc_html(Events_Maker()->options['permalinks']['event_tags_rewrite_slug'])), $has_translation, false, $language); } if (Events_Maker()->options['general']['use_organizers'] === true) { $slugs['event_organizers_rewrite_slug'] = icl_t('Events Maker', 'Event Organizers rewrite slug', untrailingslashit(esc_html(Events_Maker()->options['permalinks']['event_organizers_rewrite_slug'])), $has_translation, false, $language); } } $slugs = apply_filters('em_translated_taxonomy_rewrite_slugs_' . $language, $slugs); // set translated post type slugs $this->post_type_slugs['event'][$language] = array('has_archive' => $slugs['event_rewrite_base'], 'rewrite' => array('slug' => $slugs['event_rewrite_base'] . '/' . $slugs['event_rewrite_slug'])); // set translated taxonomy slugs $this->taxonomy_slugs['event-category'][$language] = $slugs['event_rewrite_base'] . '/' . $slugs['event_categories_rewrite_slug']; $this->taxonomy_slugs['event-location'][$language] = $slugs['event_rewrite_base'] . '/' . $slugs['event_locations_rewrite_slug']; if (Events_Maker()->options['general']['use_tags'] === true) { $this->taxonomy_slugs['event-tag'][$language] = $slugs['event_rewrite_base'] . '/' . $slugs['event_tags_rewrite_slug']; } if (Events_Maker()->options['general']['use_organizers'] === true) { $this->taxonomy_slugs['event-organizer'][$language] = $slugs['event_rewrite_base'] . '/' . $slugs['event_organizers_rewrite_slug']; } } // switch back to current language if ($plugin === 'WPML') { $sitepress->switch_lang($current, true); } } }
return $links; } /** * Add link to Support Forum. */ public function plugin_extend_links($links, $file) { if (!current_user_can('install_plugins')) { return $links; } $plugin = plugin_basename(__FILE__); if ($file == $plugin) { return array_merge($links, array(sprintf('<a href="http://www.dfactory.eu/support/forum/events-maker/" target="_blank">%s</a>', __('Support', 'events-maker')))); } return $links; } } /** * Initialise Events Maker. */ function Events_Maker() { static $instance; // first call to instance() initializes the plugin if ($instance === null || !$instance instanceof Events_Maker) { $instance = Events_Maker::instance(); } return $instance; } Events_Maker();
/** * Page menu classes fix. */ public function page_menu_class_fix($classes, $item) { if (is_post_type_archive('event') || is_singular('event') || is_tax('event-location') || is_tax('event-organizer')) { if (Events_Maker()->admin->get_action_page_id('events') > 0) { $events_page = get_post((int) Events_Maker()->admin->get_action_page_id('events')); if (empty($events_page)) { return $classes; } // events page menu classes if ($events_page->post_title === $item->post_title) { if (is_singular('event')) { $classes[] = 'current_page_parent'; $classes[] = 'current_page_ancestor'; } elseif (is_tax('event-location') || is_tax('event-organizer')) { $classes[] = 'current_page_ancestor'; } else { $classes[] = 'current_page_item'; } } // location page menu classes if (is_tax('event-location') && Events_Maker()->admin->get_action_page_id('locations') > 0) { $locations_page = get_post((int) Events_Maker()->admin->get_action_page_id('locations')); if ($locations_page->post_title === $item->post_title) { $classes[] = 'current_page_ancestor'; } } elseif (is_tax('event-organizer') && Events_Maker()->admin->get_action_page_id('organizers') > 0) { $organizers_page = get_post((int) Events_Maker()->admin->get_action_page_id('organizers')); if ($organizers_page->post_title === $item->post_title) { $classes[] = 'current_page_ancestor'; } } } } return $classes; }
/** * Fix for events page rules if permalinks are disabled, unfortunatelly not too elegant. */ public function alter_event_page_request($request) { if (!is_admin() && !get_option('permalink_structure') && isset($request['page_id'])) { $is_event_archive = false; // WPML & Polylang if (function_exists('icl_object_id') && defined('ICL_LANGUAGE_CODE')) { if ((int) $request['page_id'] === (int) icl_object_id(Events_Maker()->options['general']['pages']['events']['id'], 'page', true, ICL_LANGUAGE_CODE)) { $is_event_archive = true; } } elseif ((int) $request['page_id'] === (int) Events_Maker()->options['general']['pages']['events']['id']) { $is_event_archive = true; } // is requested page an event archive page? if ($is_event_archive === true) { // the query isn't run if we don't pass any query vars $query = new WP_Query(); $query->parse_query($request); if ($query->is_page()) { unset($request['page_id']); $request['post_type'] = 'event'; } } } return $request; }
/** * */ public function update($new_instance, $old_instance) { // number of events $old_instance['number_of_events'] = (int) (isset($new_instance['number_of_events']) ? $new_instance['number_of_events'] : $this->em_defaults['number_of_events']); // order $old_instance['order_by'] = isset($new_instance['order_by']) && in_array($new_instance['order_by'], array_keys($this->em_orders), true) ? $new_instance['order_by'] : $this->em_defaults['order_by']; $old_instance['order'] = isset($new_instance['order']) && in_array($new_instance['order'], array_keys($this->em_order_types), true) ? $new_instance['order'] : $this->em_defaults['order']; // thumbnail size $old_instance['thumbnail_size'] = isset($new_instance['thumbnail_size']) && in_array($new_instance['thumbnail_size'], $this->em_image_sizes, true) ? $new_instance['thumbnail_size'] : $this->em_defaults['thumbnail_size']; // booleans $old_instance['show_past_events'] = isset($new_instance['show_past_events']) ? true : false; $old_instance['show_occurrences'] = isset($new_instance['show_occurrences']) ? true : false; $old_instance['show_event_thumbnail'] = isset($new_instance['show_event_thumbnail']) ? true : false; $old_instance['show_event_excerpt'] = isset($new_instance['show_event_excerpt']) ? true : false; $old_instance['show_featured'] = isset($new_instance['show_featured']) ? true : false; $old_instance['show_archive_link'] = isset($new_instance['show_archive_link']) ? true : false; // texts $old_instance['title'] = sanitize_text_field(isset($new_instance['title']) ? $new_instance['title'] : $this->em_defaults['title']); $old_instance['no_events_message'] = sanitize_text_field(isset($new_instance['no_events_message']) ? $new_instance['no_events_message'] : $this->em_defaults['no_events_message']); // date format $old_instance['date_format'] = sanitize_text_field(isset($new_instance['date_format']) ? $new_instance['date_format'] : $this->em_defaults['date_format']); $old_instance['time_format'] = sanitize_text_field(isset($new_instance['time_format']) ? $new_instance['time_format'] : $this->em_defaults['time_format']); // taxonomies $old_instance['categories'] = isset($new_instance['categories']) && in_array($new_instance['categories'], array_keys($this->em_taxonomies), true) ? $new_instance['categories'] : $this->em_defaults['categories']; $old_instance['locations'] = isset($new_instance['locations']) && in_array($new_instance['locations'], array_keys($this->em_taxonomies), true) ? $new_instance['locations'] : $this->em_defaults['locations']; // categories if ($old_instance['categories'] === 'selected') { $old_instance['categories_arr'] = array(); if (isset($new_instance['categories_arr']) && is_array($new_instance['categories_arr'])) { foreach ($new_instance['categories_arr'] as $cat_id) { $old_instance['categories_arr'][] = (int) $cat_id; } $old_instance['categories_arr'] = array_unique($old_instance['categories_arr'], SORT_NUMERIC); } } else { $old_instance['categories_arr'] = array(); } // locations if ($old_instance['locations'] === 'selected') { $old_instance['locations_arr'] = array(); if (isset($new_instance['locations_arr']) && is_array($new_instance['locations_arr'])) { foreach ($new_instance['locations_arr'] as $cat_id) { $old_instance['locations_arr'][] = (int) $cat_id; } $old_instance['locations_arr'] = array_unique($old_instance['locations_arr'], SORT_NUMERIC); } } else { $old_instance['locations_arr'] = array(); } // organizers if (Events_Maker()->options['general']['use_organizers'] === true) { $old_instance['organizers'] = isset($new_instance['organizers']) && in_array($new_instance['organizers'], array_keys($this->em_taxonomies), true) ? $new_instance['organizers'] : $this->em_defaults['organizers']; if ($old_instance['organizers'] === 'selected') { $old_instance['organizers_arr'] = array(); if (isset($new_instance['organizers_arr']) && is_array($new_instance['organizers_arr'])) { foreach ($new_instance['organizers_arr'] as $cat_id) { $old_instance['organizers_arr'][] = (int) $cat_id; } $old_instance['organizers_arr'] = array_unique($old_instance['organizers_arr'], SORT_NUMERIC); } } else { $old_instance['organizers_arr'] = array(); } } return $old_instance; }