post_type === 'am_event' && is_admin()) { wp_enqueue_script( 'jquery-custom', plugins_url('/script/jquery-ui-1.10.2.custom.min.js', __FILE__) ); //JQuery datetime picker from http://trentrichardson.com/examples/timepicker/ // Localization for datetimepicker $localization = array( // Date picker 'clearText' => _x('Clear', 'date picker', 'am-events'), //Display text for clear link 'clearStatus' => _x('Erase the current date', 'date picker', 'am-events'), //Status text for clear link 'closeText' => _x('Close', 'date picker', 'am-events'), //Display text for close link 'closeStatus' => _x('Close without change', 'date picker', 'am-events'), //Status text for close link 'prevText' => _x(' _x('<<', 'date picker', 'am-events'), //Display text for previous year link 'prevStatus' => _x('Show the previous month', 'date picker', 'am-events'), //Status text for previous month link 'prevBigStatus' => _x('Show the previous year', 'date picker', 'am-events'), //Status text for previous year link 'nextText' => _x('Next>', 'date picker', 'am-events'), //Display text for next month link 'nextBigText' => _x('>>', 'date picker', 'am-events'), //Display text for next year link 'nextStatus' => _x('Show the next month', 'date picker', 'am-events'), //Status text for next month link 'nextBigStatus' => _x('Show the next year', 'date picker', 'am-events'), //Status text for next year link 'currentText' => _x('Today', 'date picker', 'am-events'), //Display text for current month link 'currentStatus' => _x('Show the current month', 'date picker', 'am-events'), //Status text for current month link 'january' => __('January', 'am-events'), 'february' => __('February', 'am-events'), 'march' => __('March', 'am-events'), 'april' => __('April', 'am-events'), 'may' => __('May', 'am-events'), 'june' => __('June', 'am-events'), 'july' => __('July', 'am-events'), 'august' => __('August', 'am-events'), 'september' => __('September', 'am-events'), 'october' => __('October', 'am-events'), 'november' => __('November', 'am-events'), 'december' => __('December', 'am-events'), 'januaryShort' => __('Jan', 'am-events'), 'februaryShort' => __('Feb', 'am-events'), 'marchShort' => __('Mar', 'am-events'), 'aprilShort' => __('Apr', 'am-events'), 'mayShort' => __('May', 'am-events'), 'juneShort' => __('Jun', 'am-events'), 'julyShort' => __('Jul', 'am-events'), 'augustShort' => __('Aug', 'am-events'), 'septemperShort' => __('Sep', 'am-events'), 'octoberShort' => __('Oct', 'am-events'), 'novemberShort' => __('Nov', 'am-events'), 'decemberShort' => __('Dec', 'am-events'), 'monthStatus' => _x('Show a different month', 'date picker', 'am-events'), //Status text for selecting a month 'yearStatus' => _x('Show a different year', 'date picker', 'am-events'), //Status text for selecting a year 'weekHeader' => _x('Wk', 'date picker', 'am-events'), //Header for the week of the year column 'weekStatus' => _x('Week of the year', 'date picker', 'am-events'), //Status text for the week of the year column 'dayNameFullMon' => __('Monday', 'am-events'), 'dayNameFullTue' => __('Tuesday', 'am-events'), 'dayNameFullWed' => __('Wednesday', 'am-events'), 'dayNameFullThu' => __('Thursday', 'am-events'), 'dayNameFullFri' => __('Friday', 'am-events'), 'dayNameFullSat' => __('Saturday', 'am-events'), 'dayNameFullSun' => __('Sunday', 'am-events'), 'dayNameShortMon' => __('Mon', 'am-events'), 'dayNameShortTue' => __('Tue', 'am-events'), 'dayNameShortWed' => __('Wed', 'am-events'), 'dayNameShortThu' => __('Thu', 'am-events'), 'dayNameShortFri' => __('Fri', 'am-events'), 'dayNameShortSat' => __('Sat', 'am-events'), 'dayNameShortSun' => __('Sun', 'am-events'), 'dayNameMinMon' => __('Mo', 'am-events'), 'dayNameMinTue' => __('Tu', 'am-events'), 'dayNameMinWed' => __('We', 'am-events'), 'dayNameMinThu' => __('Th', 'am-events'), 'dayNameMinFri' => __('Fr', 'am-events'), 'dayNameMinSat' => __('Sa', 'am-events'), 'dayNameMinSun' => __('Su', 'am-events'), 'dayStatus' => _x('Set DD as first week day', 'date picker', 'am-events'), //Status text for the day of the week selection 'dateStatus' => _x('Select D, M d', 'date picker', 'am-events'), //Status text for the date selection 'dateFormat' => _x('mm/dd/yy', 'date picker, see format options on parseDate', 'am-events'), //See format options on parseDate 'firstDay' => 1, //The first day of the week, Sun = 0, Mon = 1, ... 'initStatus' => _x('Select a date', 'date picker', 'am-events'), //Initial Status text on opening 'isRTL' => false, //True if right-to-left language, false if left-to-right // Time picker 'currentText' => _x('Now', 'time picker', 'am-events'), 'closeText' => _x('Done', 'time picker', 'am-events'), 'amNames' => _x('AM', 'time picker', 'am-events'), 'amNamesShort' => _x('A', 'time picker', 'am-events'), 'pmNames' => _x('PM', 'time picker', 'am-events'), 'pmNamesShort' => _x('P', 'time picker', 'am-events'), 'timeFormat' => _x('HH:mm', 'time picker', 'am-events'), 'timeSuffix' => _x('', 'time picker', 'am-events'), 'timeOnlyTitle' => _x('Choose Time', 'time picker', 'am-events'), 'timeText' => _x('Time', 'time picker', 'am-events'), 'hourText' => _x('Hour', 'time picker', 'am-events'), 'minuteText' => _x('Minute', 'time picker', 'am-events'), 'secondText' => _x('Second', 'time picker', 'am-events'), 'millisecText' => _x('Millisecond', 'time picker', 'am-events'), 'timezoneText' => _x('Time Zone', 'time picker', 'am-events'), 'isRTL' => false ); wp_register_script('jquery-ui-timepicker', plugins_url('/script/jquery-ui-timepicker-addon.js', __FILE__)); wp_localize_script('jquery-ui-timepicker', 'localization', $localization); //pass any values to javascript wp_enqueue_script( 'jquery-ui-timepicker', plugins_url('/script/jquery-ui-timepicker-addon.js', __FILE__), array('jquery-custom') ); // Custom script for assigning jquery to inputs wp_enqueue_script( 'am_custom_script', plugins_url('/script/am-events.js', __FILE__), array('jquery-custom') ); } } function am_custom_css() { // Date picker styles wp_enqueue_style( 'jquery.ui.theme', plugins_url('/css/jquery-ui-1.10.2.custom.css', __FILE__) ); // Time picker styles wp_enqueue_style( 'jquery.ui.timepicker', plugins_url('/css/jquery-ui-timepicker-addon.css', __FILE__)); // Other styles (for metabox etc.) wp_enqueue_style( 'am-events', plugins_url('/css/am-events.css', __FILE__)); } /* * **************************************************************************** * =META BOX * *************************************************************************** */ /** * Custom meta box for events */ function am_add_custom_meta_box() { /* * Add a meta box in event edit * context: normal (display meta box under content) * priority: high * callback: am_meta_box_content() * parameters: null */ add_meta_box('am_metabox', __('Event Details', 'am-events'), 'am_meta_box_content', 'am_event', 'normal', 'high', null); } function am_meta_box_content($post) { // Nonce for verification. if (function_exists('am_nonce')) wp_nonce_field(plugin_basename(__FILE__), 'am_nonce'); // The actual fields for data entry // Use get_post_meta to retrieve an existing value from the database and use the value for the form // DATE FIELDS $metaStartDate = get_post_meta($post->ID, 'am_startdate', true); $metaEndDate = get_post_meta($post->ID, 'am_enddate', true); // Convert dates from 0000-00-00 00:00:00 to 00.00.0000 00:00 $startDate = ''; $endDate = ''; if ($metaStartDate !== '') $startDate = date(_x('m/d/Y H:i','administration', 'am-events'), strtotime($metaStartDate)); if ($metaEndDate !== '') $endDate = date(_x('m/d/Y H:i','administration', 'am-events'), strtotime($metaEndDate)); // Content of the meta box ?>

'; } else { echo '
'; } echo "

$message

"; } /** * Display custom messages */ function am_show_admin_messages() { if(isset($_COOKIE['wp-admin-messages-normal'])) { //setcookie('wp-admin-messages-normal', null); $messages = strtok($_COOKIE['wp-admin-messages-normal'], "@@"); while ($messages !== false) { am_show_message($messages, false); $messages = strtok("@@"); } } if(isset($_COOKIE['wp-admin-messages-error'])) { $messages = strtok($_COOKIE['wp-admin-messages-error'], "@@"); while ($messages !== false) { am_show_message($messages, true); $messages = strtok("@@"); } setcookie('wp-admin-messages-error', null); } } /** * Hook into admin notices */ add_action('admin_notices', 'am_show_admin_messages'); /** * User Wrapper */ function add_admin_message($message, $error = false) { if(empty($message)) return false; if($error) { setcookie('wp-admin-messages-error', $_COOKIE['wp-admin-messages-error'] . '@@' . $message, time()+3); } else { setcookie('wp-admin-messages-normal', $_COOKIE['wp-admin-messages-normal'] . '@@' . $message, time()+3); } } /** * Save event meta and create recurring events. * @return type */ function am_save_event() { // Remove save_post action to avoid infinite loop when calling wp_insert_posts remove_action('save_post', 'am_save_event'); if (!isset($_POST['post_ID'])) return; $post_id = $_POST['post_ID']; $post = get_post($post_id); if ($_POST && get_post_type($post) === 'am_event') { // Determine if the specified post is a not revision or auto-save if (!( wp_is_post_revision($post_id) && wp_is_post_autosave($post_id) )) { // Check if 'Recurrent Event' has been checked $recurrent = $_POST['am_recurrent']; if ($recurrent === 'yes') { // If so, create the events $recurrent_amount = $_POST['am_recurrent_amount']; $recurrenceSelection = $_POST['am_recurrence_type']; // Check if event category and venue have not been selected $taxonomies = get_post_taxonomies($post_id); if (!in_array('am_event_categories', $taxonomies, true) || !in_array('am_venues', $taxonomies, true)) { return; // do not create recurrent events. } if ($recurrent_amount < 2 || $recurrent_amount > 99) { return; } $startdate = get_post_meta($post_id, 'am_startdate', true); $enddate = get_post_meta($post_id, 'am_enddate', true); $start = DateTime::createFromFormat('Y-m-d H:i:s', $startdate); $end = DateTime::createFromFormat('Y-m-d H:i:s', $enddate); for ($i = 1; $i < $recurrent_amount; $i++) { $new_post = array( 'post_title' => $post->post_title, 'post_content' => $post->post_content, 'post_status' => $post->post_status, 'post_date' => $post->post_date, 'post_author' => $post->post_author, 'post_type' => $post->post_type, 'post_category' => $post->post_category, ); $new_post_id = wp_insert_post($new_post); switch ($recurrenceSelection) { case 'am_weekly': $start->modify('+7 days'); $end->modify('+7 days'); break; case 'am_biweekly': $start->modify('+14 days'); $end->modify('+14 days'); break; default: return; } update_post_meta($new_post_id, 'am_startdate', $start->format('Y-m-d H:i:s')); update_post_meta($new_post_id, 'am_enddate', $end->format('Y-m-d H:i:s')); $eventCategories = wp_get_post_terms($post_id, 'am_event_categories'); $venues = wp_get_post_terms($post_id, 'am_venues'); foreach ($eventCategories as $c) { wp_set_post_terms($new_post_id, $c->term_id, 'am_event_categories', true); } foreach ($venues as $v) { wp_set_post_terms($new_post_id, $v->term_id, 'am_venues', true); } } // TODO: Not working // add_admin_message( sprintf(__('Created %d recurrent events.', 'am-events'), $recurrent_amount) ); } } } } /** * Add columns to event list in administration * @param type $columns * @return type */ function am_add_event_columns($columns) { return array_merge($columns, array('am_startdate' => __('Start Date', 'am-events'), 'am_enddate' => __('End Date', 'am-events'))); } add_filter('manage_am_event_posts_columns', 'am_add_event_columns'); function am_custom_event_column($column) { global $post; $post_id = $post->ID; switch ($column) { case 'am_startdate': echo get_post_meta($post_id, 'am_startdate', true); break; case 'am_enddate': echo get_post_meta($post_id, 'am_enddate', true); break; } } /** * Register the column as sortable */ function register_sortable_columns($columns) { $columns['am_startdate'] = 'am_startdate'; return $columns; } add_filter('manage_edit-am_event_sortable_columns', 'register_sortable_columns'); function am_edit_event_load() { add_filter('request', 'am_sort_events'); } /** * Used to sorts the events in the administration. */ function am_sort_events($vars) { /* Check if we're viewing the 'movie' post type. */ if (isset($vars['post_type']) && 'am_event' === $vars['post_type']) { /* Check if 'orderby' is set to 'am_startdate'. */ if (isset($vars['orderby']) && 'am_startdate' === $vars['orderby']) { /* Merge the query vars with our custom variables. */ $vars = array_merge( $vars, array( 'meta_key' => 'am_startdate', 'orderby' => 'meta_value' ) ); } } return $vars; } /* * **************************************************************************** * =LANGUAGE FILES * *************************************************************************** */ /** * Loads the language files */ function am_load_language_files() { load_plugin_textdomain('am-events', false, dirname(plugin_basename(__FILE__)) . '/languages/'); } /* * **************************************************************************** * =CPT, CUSTOM POST TYPE * *************************************************************************** */ /** * Registers new post type 'am_event' */ function am_register_post_type() { $labels = array( 'name' => __('Events', 'am-events'), 'singular_name' => __('Event', 'am-events'), 'menu_name' => __('Events', 'am-events'), 'all_items' => __('All Events', 'am-events'), 'add_new' => __('Add New Event', 'am-events'), 'add_new_item' => __('Event', 'am-events'), 'edit_item' => __('Edit Event', 'am-events'), 'new_item' => __('New Event', 'am-events'), 'view_item' => __('View Events', 'am-events'), 'search_items' => __('Search Events', 'am-events'), 'not_found' => __('No Events Found', 'am-events'), 'not_found_in_trash' => __('No Events Found', 'am-events'), ); $args = array( 'label' => __('Event', 'am-events'), 'public' => true, 'publicly_queryable' => true, 'show_ui' => true, 'show_in_menu' => true, 'menu_position' => 5, //Below Posts 'has_archive' => true, 'category_name' => 'etusivu', 'labels' => $labels, 'description' => __('Type for events', 'am-events'), 'supports' => array('title', 'editor'), 'taxonomies' => array('am_event_category', 'am_venue'), ); register_post_type('am_event', $args); } /* * Register custom taxonomy 'am_venues' */ function am_register_taxonomy_venues() { $labels = array( 'name' => __('Venues', 'am-events'), 'singular_name' => __('Venue', 'am-events'), 'search_items' => __('Search Venues', 'am-events'), 'popular_items' => __('Popular Venues', 'am-events'), 'all_items' => __('All Venues', 'am-events'), 'parent_item' => __('Parent Venue', 'am-events'), 'parent_item_colon' => __('Parent Venue:', 'am-events'), 'edit_item' => __('Edit Venue', 'am-events'), 'update_item' => __('Update Venue', 'am-events'), 'add_new_item' => __('Add New Venue', 'am-events'), 'new_item_name' => __('New Venue', 'am-events'), 'separate_items_with_commas' => __('Separate venues with commas', 'am-events'), 'add_or_remove_items' => __('Add or remove venues', 'am-events'), 'choose_from_most_used' => __('Choose from the most used venues', 'am-events'), 'menu_name' => __('Venues', 'am-events'), ); $args = array( 'labels' => $labels, 'public' => true, 'show_in_nav_menus' => true, 'show_ui' => true, 'show_tagcloud' => true, 'show_admin_column' => false, 'hierarchical' => true, 'rewrite' => true, 'query_var' => true ); register_taxonomy('am_venues', array('am_event'), $args); } /** * Registers custom taxonomy 'am_event_categories' */ function am_register_taxonomy_event_categories() { $labels = array( 'name' => __('Event Categories', 'am-events'), 'singular_name' => __('Event Category', 'am-events'), 'search_items' => __('Search Event Categories', 'am-events'), 'popular_items' => __('Popular Event Categories', 'am-events'), 'all_items' => __('All Event Categories', 'am-events'), 'parent_item' => __('Parent Event Category', 'am-events'), 'parent_item_colon' => __('Parent Event Category:', 'am-events'), 'edit_item' => __('Edit Event Category', 'am-events'), 'update_item' => __('Update Event Category', 'am-events'), 'add_new_item' => __('Add New Event Category', 'am-events'), 'new_item_name' => __('New Event Category', 'am-events'), 'separate_items_with_commas' => __('Separate event categories with commas', 'am-events'), 'add_or_remove_items' => __('Add or remove event categories', 'am-events'), 'choose_from_most_used' => __('Choose from the most used event categories', 'am-events'), 'menu_name' => __('Event Categories', 'am-events'), ); $args = array( 'labels' => $labels, 'public' => true, 'show_in_nav_menus' => true, 'show_ui' => true, 'show_tagcloud' => true, 'show_admin_column' => false, 'hierarchical' => true, 'rewrite' => true, 'query_var' => true ); register_taxonomy('am_event_categories', array('am_event'), $args); } /** * Add filter to ensure the text Event, or event, is displayed when user updates an event. */ function am_event_updated_messages($messages) { global $post, $post_ID; $messages['am_event'] = array( 0 => '', // Unused. Messages start at index 1. 1 => sprintf(__('Event updated. View event', 'am-events'), esc_url(get_permalink($post_ID))), 2 => __('Custom field updated.', 'am-events'), 3 => __('Custom field deleted.', 'am-events'), 4 => __('Event updated.', 'am-events'), /* translators: %s: date and time of the revision */ 5 => isset($_GET['revision']) ? sprintf(__('Event restored to revision from %s', 'am-events'), wp_post_revision_title((int) $_GET['revision'], false)) : false, 6 => sprintf(__('Event published. View event', 'am-events'), esc_url(get_permalink($post_ID))), 7 => __('Event saved.', 'am-events'), 8 => sprintf(__('Event submitted. Preview event', 'am-events'), esc_url(add_query_arg('preview', 'true', get_permalink($post_ID)))), 9 => sprintf(__('Event scheduled for: %1$s. Preview event', 'am-events'), // translators: Publish box date format, see http://php.net/date date_i18n(_x('d.m.Y G:i', 'Publish box, see http://php.net/date', 'am-events'), strtotime($post->post_date)), esc_url(get_permalink($post_ID))), 10 => sprintf(__('Event draft updated. Preview event', 'am-events'), esc_url(add_query_arg('preview', 'true', get_permalink($post_ID)))), ); return $messages; } add_filter('post_updated_messages', 'am_event_updated_messages'); /** * Init custom post type (CPT) */ function am_cpt_init() { am_register_post_type(); am_register_taxonomy_venues(); am_register_taxonomy_event_categories(); } /** * Function used to get permalinks to work when you activate the plugin. * Pay attention to how am_cpt_init is called in the register_activation_hook callback: */ function am_rewrite_flush() { // First, we "add" the custom post type via the above written function. // Note: "add" is written with quotes, as CPTs don't get added to the DB, // They are only referenced in the post_type column with a post entry, // when you add a post of this CPT. am_cpt_init(); // ATTENTION: This is *only* done during plugin activation hook in this example! // You should *NEVER EVER* do this on every page load!! flush_rewrite_rules(); } register_activation_hook(__FILE__, 'am_rewrite_flush'); /* * **************************************************************************** * =TAXONOMY FILTER * *************************************************************************** */ /** * Add event category filtering to the event listing in administration. */ function am_restrict_events_by_category() { remove_action('save_post', 'my_metabox_save'); global $typenow; $post_type = 'am_event'; $taxonomy = 'am_event_categories'; if ($typenow == $post_type) { $selected = isset($_GET[$taxonomy]) ? $_GET[$taxonomy] : ''; $info_taxonomy = get_taxonomy($taxonomy); wp_dropdown_categories(array( 'show_option_all' => __("Show All {$info_taxonomy->label}", 'am-events'), 'taxonomy' => $taxonomy, 'name' => $taxonomy, 'orderby' => 'name', 'selected' => $selected, 'show_count' => true, 'hide_empty' => false, )); }; } function am_convert_id_to_term_in_query($query) { global $pagenow; $post_type = 'am_event'; $taxonomy = 'am_event_categories'; $q_vars = &$query->query_vars; if ($pagenow == 'edit.php' && isset($q_vars['post_type']) && $q_vars['post_type'] == $post_type && isset($q_vars[$taxonomy]) && is_numeric($q_vars[$taxonomy]) && $q_vars[$taxonomy] != 0) { $term = get_term_by('id', $q_vars[$taxonomy], $taxonomy); $q_vars[$taxonomy] = $term->slug; } } add_filter('parse_query', 'am_convert_id_to_term_in_query'); /* * **************************************************************************** * = TEMPLATE TAGS * *************************************************************************** */ /** * Display or retrieve the current event start date. * * @since 1.3.0 * * @param string $before Optional. Content to prepend to the title. * @param string $after Optional. Content to append to the title. * @param string $format Optional. See PHP date() for formatting options. * @param bool $echo Optional, default to true. Whether to display or return. * @return null|string Null on no title. String if $echo parameter is false. */ function am_the_startdate($format = 'Y-m-d H:i:s', $before = '', $after = '', $echo = true) { $date = am_get_the_startdate(); if ( strlen($date) == 0 ) return; $date = $before . $date . $after; if ( $echo ) echo $date; else return $date; } /** * Retrieve event start date. * * @since 1.3.0 * * @param mixed $post Optional. Post ID or object. * @param string $format Optional. See PHP date() for formatting options. * @return string */ function am_get_the_startdate( $format = 'Y-m-d H:i:s', $post = 0 ) { $post = get_post( $post ); $id = isset( $post->ID ) ? $post->ID : 0; $date = get_post_meta($id, 'am_startdate', true); if ( strlen($format) != 0) $date = date($format, strtotime($date)); return $date; } /** * Display or retrieve the current event start date. * * @since 1.3.0 * * @param string $before Optional. Content to prepend to the title. * @param string $after Optional. Content to append to the title. * @param string $format Optional. See PHP date() for formatting options. * @param bool $echo Optional, default to true. Whether to display or return. * @return null|string Null on no title. String if $echo parameter is false. */ function am_the_enddate($format = 'Y-m-d H:i:s', $before = '', $after = '', $echo = true) { $date = am_get_the_enddate(); if ( strlen($date) == 0 ) return; $date = $before . $date . $after; if ( $echo ) echo $date; else return $date; } /** * Retrieve event start date. * * @since 1.3.0 * * @param mixed $post Optional. Post ID or object. * @param string $format Optional. See PHP date() for formatting options. * @return string */ function am_get_the_enddate( $format = 'Y-m-d H:i:s', $post = 0 ) { $post = get_post( $post ); $id = isset( $post->ID ) ? $post->ID : 0; $date = get_post_meta($id, 'am_enddate', true); if ( strlen($format) != 0) $date = date($format, strtotime($date)); return $date; } /** * Retrieve event venues. * * @since 1.3.0 * @uses $post * * @param int $id Optional, default to current post ID. The post ID. * @return array */ function am_get_the_venue( $id = false ) { $venues = get_the_terms( $id, 'am_venues' ); if ( ! $venues || is_wp_error( $venues ) ) $venues = array(); $venues = array_values( $venues ); foreach ( array_keys( $venues ) as $key ) { _make_cat_compat( $venues[$key] ); } // Filter name is plural because we return alot of categories (possibly more than #13237) not just one return apply_filters( 'am_get_the_venues', $venues ); } /** * Check if the current event in within any of the given venues. * * The given venues are checked against the event's venues' term_ids, names and slugs. * Venues given as integers will only be checked against the post's venues' term_ids. * * @since 1.3.0 * * @param int|string|array $venue Venue ID, name or slug, or array of said. * @param int|object $post Optional. Event post to check instead of the current post. * @return bool True if the current post is in any of the given venues. */ function am_in_venue( $venue, $post = null ) { if ( empty( $venue ) ) return false; return has_term( $venue, 'am_venues', $post ); } /** * Retrieve venue list in either HTML list or custom format. * * @since 1.3.0 * * @param string $separator Optional, default is empty string. Separator for between the venues. * @param string $parents Optional. How to display the parents. * @param int $post_id Optional. Post ID to retrieve venues. * @return string */ function am_get_the_venue_list( $separator = '', $parents='', $post_id = false ) { global $wp_rewrite; if ( ! is_object_in_taxonomy( get_post_type( $post_id ), 'am_venues' ) ) return apply_filters( 'am_the_venue', '', $separator, $parents ); $venues = am_get_the_venue( $post_id ); if ( empty( $venues ) ) return apply_filters( 'am_the_venue', _x( 'Unspecified', 'Venue', 'am-events' ), $separator, $parents ); $rel = ( is_object( $wp_rewrite ) && $wp_rewrite->using_permalinks() ) ? 'rel="venue tag"' : 'rel="venue"'; $thelist = ''; if ( '' == $separator ) { $thelist .= ''; } else { $i = 0; foreach ( $venues as $venue ) { if ( 0 < $i ) $thelist .= $separator; switch ( strtolower( $parents ) ) { case 'multiple': if ( $venue->parent ) $thelist .= get_category_parents( $venue->parent, true, $separator ); $thelist .= 'name ) ) . '" ' . $rel . '>' . $venue->name.''; break; case 'single': $thelist .= 'name ) ) . '" ' . $rel . '>'; if ( $venue->parent ) $thelist .= get_category_parents( $venue->parent, false, $separator ); $thelist .= "$venue->name"; break; case '': default: $thelist .= 'name ) ) . '" ' . $rel . '>' . $venue->name.''; } ++$i; } } return apply_filters( 'am_the_venue', $thelist, $separator, $parents ); } /** * Display the venue list for the event post. * * @since 1.3.0 * * @param string $separator Optional, default is empty string. Separator for between the venues. * @param string $parents Optional. How to display the parents. * @param int $post_id Optional. Post ID to retrieve categories. */ function am_the_venue( $separator = '', $parents='', $post_id = false ) { echo am_get_the_venue_list( $separator, $parents, $post_id ); } /** * Retrieve event categories. * * @since 1.3.0 * @uses $post * * @param int $id Optional, default to current event post ID. The event post ID. * @return array */ function am_get_the_event_category( $id = false ) { $categories = get_the_terms( $id, 'am_event_categories' ); if ( ! $categories || is_wp_error( $categories ) ) $categories = array(); $categories = array_values( $categories ); foreach ( array_keys( $categories ) as $key ) { _make_cat_compat( $categories[$key] ); } // Filter name is plural because we return alot of categories (possibly more than #13237) not just one return apply_filters( 'am_get_the_event_categories', $categories ); } /** * Retrieve event category list in either HTML list or custom format. * * @since 1.3.0 * * @param string $separator Optional, default is empty string. Separator for between the categories. * @param string $parents Optional. How to display the parents. * @param int $post_id Optional. Event post ID to retrieve categories. * @return string */ function am_get_the_event_category_list( $separator = '', $parents='', $post_id = false ) { global $wp_rewrite; if ( ! is_object_in_taxonomy( get_post_type( $post_id ), 'am_event_categories' ) ) return apply_filters( 'am_the_event_category', '', $separator, $parents ); $categories = am_get_the_event_category( $post_id ); if ( empty( $categories ) ) return apply_filters( 'am_the_event_category', __( 'Uncategorized' ), $separator, $parents ); $rel = ( is_object( $wp_rewrite ) && $wp_rewrite->using_permalinks() ) ? 'rel="category tag"' : 'rel="category"'; $thelist = ''; if ( '' == $separator ) { $thelist .= ''; } else { $i = 0; foreach ( $categories as $category ) { if ( 0 < $i ) $thelist .= $separator; switch ( strtolower( $parents ) ) { case 'multiple': if ( $category->parent ) $thelist .= get_category_parents( $category->parent, true, $separator ); $thelist .= 'name ) ) . '" ' . $rel . '>' . $category->name.''; break; case 'single': $thelist .= 'name ) ) . '" ' . $rel . '>'; if ( $category->parent ) $thelist .= get_category_parents( $category->parent, false, $separator ); $thelist .= "$category->name"; break; case '': default: $thelist .= 'name ) ) . '" ' . $rel . '>' . $category->name.''; } ++$i; } } return apply_filters( 'am_the_event_category', $thelist, $separator, $parents ); } /** * Check if the current event in within any of the given event categories. * * The given categories are checked against the post's categories' term_ids, names and slugs. * Categories given as integers will only be checked against the post's categories' term_ids. * * * @since 1.3.0 * * @param int|string|array $eventCategory Event category ID, name or slug, or array of said. * @param int|object $post Optional. Post to check instead of the current post. (since 2.7.0) * @return bool True if the current post is in any of the given categories. */ function am_in_event_category( $eventCategory, $post = null ) { if ( empty( $eventCategory ) ) return false; return has_term( $category, 'am_event_categories', $post ); } /** * Display the event category list for the event. * * @since 1.3.0 * * @param string $separator Optional, default is empty string. Separator for between the event categories. * @param string $parents Optional. How to display the parents. * @param int $post_id Optional. Post ID to retrieve event categories. */ function am_the_event_category( $separator = '', $parents='', $post_id = false ) { echo am_get_the_event_category_list( $separator, $parents, $post_id ); } ?>