post_type, array( Post_Types::EVENT, Post_Types::VENUE, Post_Types::ORGANIZER, Post_Types::ATTENDEE ), true ) || false !== strpos( $hook, 'eventwright' ) ) ) { wp_enqueue_style( 'eventwright-admin', EVWR_URL . 'assets/css/admin.css', array(), EVWR_VERSION ); } } /** * Event list columns. * * @param array $cols Columns. * @return array */ public static function columns( $cols ) { $out = array(); foreach ( $cols as $key => $label ) { if ( 'date' === $key ) { continue; } $out[ $key ] = $label; if ( 'title' === $key ) { $out['evwr_when'] = __( 'When', 'eventwright' ); $out['evwr_venue'] = __( 'Venue', 'eventwright' ); $out['evwr_rsvp'] = __( 'RSVPs', 'eventwright' ); } } $out['date'] = __( 'Published', 'eventwright' ); return $out; } /** * Column content. * * @param string $col Column. * @param int $post_id Post. */ public static function column( $col, $post_id ) { switch ( $col ) { case 'evwr_when': $occ = Occurrences::pick( $post_id ); if ( ! $occ ) { echo '' . esc_html__( 'No date set', 'eventwright' ) . ''; break; } echo esc_html( eventwright_format_when( $occ['start_local'], $occ['end_local'], (bool) $occ['all_day'], eventwright_event_timezone( $post_id ) ) ); if ( Recurrence::is_recurring( $post_id ) ) { $rule = Recurrence::get_rule( $post_id ); $text = Recurrence::describe( $rule, get_post_meta( $post_id, '_evwr_start', true ) ); echo '
↻ ' . esc_html( $text ) . ''; } $status = get_post_meta( $post_id, '_evwr_status', true ); if ( $status && 'scheduled' !== $status ) { echo '
' . esc_html( eventwright_status_label( $status ) ) . ''; } break; case 'evwr_venue': $venue = eventwright_get_venue( (int) get_post_meta( $post_id, '_evwr_venue_id', true ) ); echo $venue ? esc_html( $venue['name'] ) : '—'; break; case 'evwr_rsvp': if ( ! RSVP::enabled( $post_id ) ) { echo '—'; break; } $going = RSVP::going_count( $post_id, RSVP::occurrence_key( $post_id, Occurrences::pick( $post_id ) ) ); $cap = (int) get_post_meta( $post_id, '_evwr_rsvp_capacity', true ); $url = admin_url( 'edit.php?post_type=' . Post_Types::ATTENDEE . '&evwr_event=' . $post_id ); echo '' . esc_html( $cap ? $going . ' / ' . $cap : (string) $going ) . ''; $waiting = RSVP::count_status( $post_id, RSVP::occurrence_key( $post_id, Occurrences::pick( $post_id ) ), 'waitlist' ); if ( $waiting ) { /* translators: %d: people on the waitlist */ echo '
' . esc_html( sprintf( __( '+%d waiting', 'eventwright' ), $waiting ) ) . ''; } break; } } /** * Sortable columns. * * @param array $cols Columns. * @return array */ public static function sortable( $cols ) { $cols['evwr_when'] = 'evwr_start'; return $cols; } /** * Sort and filter the admin event list. * * @param \WP_Query $q Query. */ public static function admin_order( $q ) { if ( ! is_admin() || ! $q->is_main_query() || Post_Types::EVENT !== $q->get( 'post_type' ) ) { return; } if ( 'evwr_start' === $q->get( 'orderby' ) ) { $q->set( 'meta_key', '_evwr_start' ); $q->set( 'orderby', 'meta_value' ); } // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- List filter. $when = isset( $_GET['evwr_when'] ) ? sanitize_key( wp_unslash( $_GET['evwr_when'] ) ) : ''; if ( in_array( $when, array( 'upcoming', 'past' ), true ) ) { global $wpdb; $table = Occurrences::table(); $now = eventwright_now_utc(); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- Custom table. $upcoming = $wpdb->get_col( $wpdb->prepare( 'SELECT DISTINCT event_id FROM %i WHERE end_utc >= %s', $table, $now ) ); $upcoming = array_map( 'intval', $upcoming ); if ( 'upcoming' === $when ) { $q->set( 'post__in', $upcoming ? $upcoming : array( 0 ) ); if ( ! $q->get( 'orderby' ) ) { $q->set( 'meta_key', '_evwr_start' ); $q->set( 'orderby', 'meta_value' ); $q->set( 'order', 'ASC' ); } } else { $q->set( 'post__not_in', $upcoming ); } } } /** * Upcoming / past filter above the event list. * * @param string $post_type Post type. */ public static function when_filter( $post_type ) { if ( Post_Types::EVENT !== $post_type ) { return; } // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- List filter. $when = isset( $_GET['evwr_when'] ) ? sanitize_key( wp_unslash( $_GET['evwr_when'] ) ) : ''; echo ''; echo ''; } /** * Venue list columns. * * @param array $cols Columns. * @return array */ public static function venue_columns( $cols ) { $date = isset( $cols['date'] ) ? $cols['date'] : null; unset( $cols['date'] ); $cols['evwr_address'] = __( 'Address', 'eventwright' ); if ( $date ) { $cols['date'] = $date; } return $cols; } /** * Venue column content. * * @param string $col Column. * @param int $post_id Post. */ public static function venue_column( $col, $post_id ) { if ( 'evwr_address' === $col ) { $v = eventwright_get_venue( $post_id ); echo $v && $v['full_address'] ? esc_html( $v['full_address'] ) : '—'; } } /** * Settings link on the Plugins screen. * * @param array $links Links. * @return array */ public static function action_links( $links ) { array_unshift( $links, '' . esc_html__( 'Settings', 'eventwright' ) . '' ); return $links; } /** * Mark the events page in the Pages list. * * @param array $states States. * @param \WP_Post $post Post. * @return array */ public static function post_states( $states, $post ) { if ( (int) \Eventwright\Settings::get( 'events_page_id' ) === (int) $post->ID ) { $states['eventwright'] = __( 'Events Page', 'eventwright' ); } return $states; } /** * Notice while TEC is still active. */ public static function tec_active_notice() { if ( ! Compat_TEC::tec_active() || ! current_user_can( 'activate_plugins' ) ) { return; } $screen = get_current_screen(); if ( ! $screen || ! in_array( $screen->post_type, array( Post_Types::EVENT, Post_Types::VENUE, Post_Types::ORGANIZER ), true ) ) { return; } echo '

'; echo esc_html__( 'The Events Calendar is still active, so it keeps your /events/ and /event/ links for now. Import your events, check them, then deactivate The Events Calendar: Eventwright will take over the same links automatically.', 'eventwright' ); echo '

'; } /** * Order the Events submenu sensibly. */ public static function menu_order() { global $submenu; $parent = 'edit.php?post_type=' . Post_Types::EVENT; if ( empty( $submenu[ $parent ] ) ) { return; } $order = array( $parent => 1, 'post-new.php?post_type=' . Post_Types::EVENT => 2, 'edit.php?post_type=' . Post_Types::ATTENDEE => 3, 'edit.php?post_type=' . Post_Types::VENUE => 4, 'edit.php?post_type=' . Post_Types::ORGANIZER => 5, 'edit-tags.php?taxonomy=' . Post_Types::CATEGORY . '&post_type=' . Post_Types::EVENT => 6, 'edit-tags.php?taxonomy=post_tag&post_type=' . Post_Types::EVENT => 7, 'eventwright-import' => 8, 'eventwright-settings' => 9, ); usort( $submenu[ $parent ], function ( $a, $b ) use ( $order ) { $oa = isset( $order[ $a[2] ] ) ? $order[ $a[2] ] : 50; $ob = isset( $order[ $b[2] ] ) ? $order[ $b[2] ] : 50; return $oa - $ob; } ); } }