agile_tix = $agile_tix; $this->version = $version; } function register_agile_custom_post_type() { register_post_type( 'agile_post', array( 'labels' => array( 'name' => __( 'AgileTix Shows', 'agiletix-site-sync' ), 'singular_name' => __( 'AgileTix Show', 'agiletix-site-sync' ), 'add_new' => 'Add New', ), 'public' => true, 'has_archive' => true, 'menu_icon' => 'dashicons-tickets-alt', 'rewrite' => array( 'slug' => 'custom-posts' ), 'supports' => array( 'title', 'editor', 'custom-fields', // 'author', 'thumbnail', // 'excerpt', // 'trackbacks', // 'comments', // 'revisions', 'page-attributes', 'post-formats', ), // 'taxonomies' => array( 'post_tag', 'Genre'), // 'rewrite' => array( 'slug' => 'AgileTix' ), // my custom slug ) ); register_taxonomy( 'agile_genre', 'agile_post', array( 'label' => 'Genre', 'hierarchical' => true, 'capabilities' => array( 'manage_terms' => 'manage_agile_genre', 'edit_terms' => 'edit_agile_genre', 'delete_terms' => 'delete_agile_genre', 'assign_terms' => 'assign_agile_genre', ), ) ); self::migrate_genre_taxonomy_to_agile_genre(); // Register coming soon feed add_feed( 'agile_coming_soon', array( $this, 'ats_coming_soon_feed' ) ); // Add admin columns and filters for coming soon posts // Use admin_init to ensure post type is configured add_action( 'admin_init', array( $this, 'ats_register_coming_soon_admin_features' ) ); } /** * One-time rename of legacy unprefixed genre taxonomy to agile_genre. */ public static function migrate_genre_taxonomy_to_agile_genre() { if ( get_option( 'agile_tix_migrated_genre_taxonomy' ) ) { return; } global $wpdb; $updated = $wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->term_taxonomy} SET taxonomy = %s WHERE taxonomy = %s", 'agile_genre', 'genre' ) ); if ( false !== $updated ) { update_option( 'agile_tix_migrated_genre_taxonomy', 1, false ); clean_term_cache( array(), 'genre' ); clean_term_cache( array(), 'agile_genre' ); } } /** * Register admin columns and filters for coming soon posts * Called on admin_init to ensure post type is configured */ function ats_register_coming_soon_admin_features() { $postType = self::get_configured_post_type(); if ( empty( $postType ) ) { return; } add_filter( 'manage_' . $postType . '_posts_columns', array( $this, 'ats_add_coming_soon_column' ) ); add_action( 'manage_' . $postType . '_posts_custom_column', array( $this, 'ats_render_coming_soon_column' ), 10, 2 ); add_filter( 'manage_edit-' . $postType . '_sortable_columns', array( $this, 'ats_coming_soon_column_sortable' ) ); add_action( 'restrict_manage_posts', array( $this, 'ats_add_coming_soon_filter' ) ); add_action( 'pre_get_posts', array( $this, 'ats_filter_coming_soon_posts' ) ); add_filter( 'posts_clauses', array( $this, 'ats_modify_query_for_coming_soon_ordering' ), 10, 2 ); // Add visual indicator in post edit screen add_action( 'edit_form_after_title', array( $this, 'ats_show_coming_soon_indicator' ) ); } function ats_add_custom_post_type_to_rss_feed( $query ) { if ( ( $query->is_feed() || $query->is_home() ) && $query->is_main_query() ) { $post_types = $query->get( 'post_type' ); if ( empty( $post_types ) ) { $post_types = array( 'post' ); } if ( is_array( $post_types ) ) { $post_types[] = 'agile_post'; } else { $post_types = array( 'post', 'agile_post' ); } $query->set( 'post_type', $post_types ); } } function ats_add_metaboxes() { add_meta_box( 'agile_eventID_meta', 'Agile Event ID', 'agile_tix_post_type::ats_meta_eventID_callback', 'agile_post', 'normal', 'default', null ); add_meta_box( 'agile_CorpOrgName_meta', 'Agile CorpOrgName', 'agile_tix_post_type::ats_meta_CorpOrgName_callback', 'agile_post', 'normal', 'default', null ); add_meta_box( 'agile_Name_meta', 'Agile Name', 'agile_tix_post_type::ats_meta_Name_callback', 'agile_post', 'normal', 'default', null ); add_meta_box( 'agile_StartDate_meta', 'Agile Start Date', 'agile_tix_post_type::ats_meta_StartDate_callback', 'agile_post', 'normal', 'default', null ); add_meta_box( 'agile_EndDate_meta', 'Agile End Date', 'agile_tix_post_type::ats_meta_EndDate_callback', 'agile_post', 'normal', 'default', null ); add_meta_box( 'agile_Distributor_meta', 'Agile Distributor', 'agile_tix_post_type::ats_meta_Distributor_callback', 'agile_post', 'normal', 'default', null ); } static function ats_meta_eventID_callback( $post ) { $event = get_post_meta( $post->ID, 'ATS_Event', true ); $value = $event['EventID']; echo ''; } static function ats_meta_CorpOrgName_callback( $post ) { $event = get_post_meta( $post->ID, 'ATS_Event', true ); $value = $event['CorpOrgName']; echo ''; } static function ats_meta_Name_callback( $post ) { $event = get_post_meta( $post->ID, 'ATS_Event', true ); $value = $event['Name']; echo ''; } static function ats_meta_StartDate_callback( $post ) { $event = get_post_meta( $post->ID, 'ATS_Event', true ); $value = $event['StartDate']; echo ''; } static function ats_meta_EndDate_callback( $post ) { $event = get_post_meta( $post->ID, 'ATS_Event', true ); $value = $event['EndDate']; echo ''; } static function ats_meta_Distributor_callback( $post ) { $event = get_post_meta( $post->ID, 'ATS_Event', true ); $value = $event['Distributor']; echo ''; } static function agile_post_adjust_queries( $query ) { if ( ! is_admin() && is_post_type_archive( 'agile_post' ) && $query->is_main_query() ) { $query->set( 'meta_key', 'event_date' ); $query->set( 'orderby', 'meta_value_num' ); $query->set( 'order', 'ASC' ); $query->set( 'meta_query', array( array( 'key' => 'event_date', 'compare' => '>=', 'value' => wp_date( 'Ymd' ), 'type' => 'numeric', ), ) ); } } /** * Get the configured post type based on theme integration settings * * @return string The post type to use */ static function get_configured_post_type() { $themeType = get_option( 'agile_field_config_integration_type' ) ?? 'none'; switch ( $themeType ) { case 'none': return 'agile_post'; case 'event_champ': return 'event'; case 'custom': $customPostType = agile_tix_Options::sanitize_theme_custom_map_post_type( get_option( 'agile_field_theme_custom_map_post_type' ) ); return '' !== $customPostType ? $customPostType : 'agile_post'; case 'amy_movie': return 'amy_movie'; default: return 'agile_post'; } } /** * Handle the coming soon feed query * Filters posts to only show those with ATS_ComingSoonDate meta */ function ats_coming_soon_feed_query( $query ) { if ( $query->is_feed( 'agile_coming_soon' ) && $query->is_main_query() ) { // Get the configured post type from theme settings $postType = self::get_configured_post_type(); $query->set( 'post_type', $postType ); $meta_query = array( 'relation' => 'AND', array( 'key' => 'ATS_ComingSoonDate', 'compare' => 'EXISTS', ), ); $query->set( 'meta_query', $meta_query ); } } /** * Render the coming soon feed */ function ats_coming_soon_feed() { // Load the default WordPress RSS template load_template( ABSPATH . WPINC . '/feed-rss2.php' ); } /** * Add Coming Soon column to post list */ function ats_add_coming_soon_column( $columns ) { $new_columns = array(); foreach ( $columns as $key => $value ) { if ( $key === 'date' ) { $new_columns['agile_coming_soon'] = __( 'Coming Soon', 'agiletix-site-sync' ); } $new_columns[ $key ] = $value; } // If date column doesn't exist, add it at the end if ( ! isset( $new_columns['agile_coming_soon'] ) ) { $new_columns['agile_coming_soon'] = __( 'Coming Soon', 'agiletix-site-sync' ); } return $new_columns; } /** * Render Coming Soon column content */ function ats_render_coming_soon_column( $column, $post_id ) { if ( $column === 'agile_coming_soon' ) { $comingSoonDate = get_post_meta( $post_id, 'ATS_ComingSoonDate', true ); if ( ! empty( $comingSoonDate ) ) { echo 'Coming Soon'; echo '
' . esc_html( $comingSoonDate ) . ''; } else { echo 'Now Showing'; } } } /** * Make Coming Soon column sortable */ function ats_coming_soon_column_sortable( $columns ) { $columns['agile_coming_soon'] = 'agile_coming_soon'; return $columns; } /** * Add Coming Soon filter dropdown */ function ats_add_coming_soon_filter() { global $typenow; $postType = self::get_configured_post_type(); if ( $typenow === $postType ) { $filter_value = isset( $_GET['agile_coming_soon_filter'] ) ? sanitize_key( wp_unslash( $_GET['agile_coming_soon_filter'] ) ) : ''; if ( ! in_array( $filter_value, array( '', 'yes', 'no' ), true ) ) { $filter_value = ''; } ?> get( 'meta_query' ); if ( ! is_array( $meta_query ) ) { $meta_query = array(); } $meta_query[] = array( 'key' => 'ATS_ComingSoonDate', 'compare' => 'NOT EXISTS', ); $query->set( 'meta_query', $meta_query ); } } // Don't set meta_key/orderby here, let the posts_clauses filter handle it } } function ats_modify_query_for_coming_soon_ordering( $clauses, $query ) { global $pagenow, $typenow, $wpdb; $postType = self::get_configured_post_type(); if ( is_admin() && $pagenow === 'edit.php' && $typenow === $postType ) { $coming_soon_filter = isset( $_GET['agile_coming_soon_filter'] ) ? sanitize_key( wp_unslash( $_GET['agile_coming_soon_filter'] ) ) : ''; $orderby = isset( $_GET['orderby'] ) ? sanitize_key( wp_unslash( $_GET['orderby'] ) ) : ''; $is_filter_active = $coming_soon_filter === 'yes'; $is_sorting_by_coming_soon = $orderby === 'agile_coming_soon'; // Check if we should order coming soon first (either filter or sort) if ( $is_filter_active || $is_sorting_by_coming_soon ) { // Add LEFT JOIN for ComingSoonDate meta $join_alias = 'agile_coming_soon_meta'; $meta_key = 'ATS_ComingSoonDate'; // Check if join already exists if ( strpos( $clauses['join'], $join_alias ) === false ) { $clauses['join'] .= " LEFT JOIN {$wpdb->postmeta} AS {$join_alias} ON ({$wpdb->posts}.ID = {$join_alias}.post_id AND {$join_alias}.meta_key = '{$meta_key}')"; } if ( $is_sorting_by_coming_soon ) { // Get the sort order (ASC or DESC) $order_param = isset( $_GET['order'] ) ? sanitize_key( wp_unslash( $_GET['order'] ) ) : ''; $order = strtoupper( $order_param ) === 'DESC' ? 'DESC' : 'ASC'; if ( $order === 'ASC' ) { // ASC: Coming soon posts first (sorted by date ASC), then now showing posts $clauses['orderby'] = "CASE WHEN {$join_alias}.meta_value IS NOT NULL THEN 0 ELSE 1 END ASC, CASE WHEN {$join_alias}.meta_value IS NOT NULL THEN {$join_alias}.meta_value END ASC, " . $clauses['orderby']; } else { // DESC: Coming soon posts first (sorted by date DESC), then now showing posts $clauses['orderby'] = "CASE WHEN {$join_alias}.meta_value IS NOT NULL THEN 0 ELSE 1 END ASC, CASE WHEN {$join_alias}.meta_value IS NOT NULL THEN {$join_alias}.meta_value END DESC, " . $clauses['orderby']; } } else { // When filtering: just put coming soon posts first $clauses['orderby'] = "CASE WHEN {$join_alias}.meta_value IS NOT NULL THEN 0 ELSE 1 END ASC, " . $clauses['orderby']; } } } return $clauses; } /** * Show Coming Soon indicator in post edit screen */ function ats_show_coming_soon_indicator( $post ) { $postType = self::get_configured_post_type(); if ( $post->post_type !== $postType ) { return; } $comingSoonDate = get_post_meta( $post->ID, 'ATS_ComingSoonDate', true ); if ( ! empty( $comingSoonDate ) ) { ?>

Coming Soon Event
Coming Soon Date: