$label ) {
if ( 'date' === $key ) {
continue;
}
$out[ $key ] = $label;
if ( 'title' === $key ) {
$out['bcal_when'] = __( 'Event date', 'bearius-calendar' );
$out['bcal_venue'] = __( 'Place', 'bearius-calendar' );
}
}
$out['bcal_status'] = __( 'Status', 'bearius-calendar' );
$out['date'] = __( 'Published', 'bearius-calendar' );
return $out;
}
);
add_action(
'manage_' . BCAL_PT . '_posts_custom_column',
function ( $column, $post_id ) {
$event = bcal_get_event( $post_id );
switch ( $column ) {
case 'bcal_when':
if ( ! $event['start'] ) {
echo '-' . esc_html__( 'No date', 'bearius-calendar' ) . '';
break;
}
$ts = bcal_ts( $event['start'] );
$past = ! bcal_is_recurring( $event ) && ( $event['end_effective'] ? $event['end_effective'] : substr( $event['start'], 0, 10 ) . ' 23:59:59' ) < bcal_now();
$time = $event['all_day'] ? __( 'All day', 'bearius-calendar' ) : wp_date( (string) get_option( 'time_format' ), $ts );
if ( ! $event['all_day'] && $event['end_effective'] ) {
$time .= ' - ' . bcal_date( (string) get_option( 'time_format' ), $event['end_effective'] );
}
echo '
';
echo '' . esc_html( wp_date( 'j', $ts ) ) . '' . esc_html( wp_date( 'M', $ts ) ) . '';
echo '' . esc_html( bcal_ucfirst( wp_date( 'D', $ts ) ) . ' ' . wp_date( 'Y', $ts ) ) . '' . esc_html( $time ) . '';
echo '';
if ( bcal_is_recurring( $event ) ) {
echo wp_kses( '' . bcal_admin_icon( 'repeat' ) . '' . esc_html__( 'Repeats', 'bearius-calendar' ) . '', bcal_kses_html() );
}
if ( $event['featured'] ) {
echo wp_kses( '' . bcal_admin_icon( 'star' ) . '' . esc_html__( 'Featured', 'bearius-calendar' ) . '', bcal_kses_html() );
}
echo '
';
break;
case 'bcal_venue':
$venue = bcal_first_term( $post_id, 'bcal_venue' );
$city = bcal_first_term( $post_id, 'bcal_city' );
if ( ! $city ) {
$city = bcal_venue_city( $venue );
}
if ( ! $venue && ! $city ) {
echo $event['online'] ? esc_html__( 'Online', 'bearius-calendar' ) : '-';
break;
}
echo '';
if ( $venue ) {
echo '' . esc_html( $venue->name ) . '';
}
if ( $city ) {
echo '' . esc_html( $city->name ) . '';
}
echo '
';
break;
case 'bcal_status':
if ( 'scheduled' !== $event['status'] ) {
echo '' . esc_html( bcal_status_label( $event['status'] ) ) . '';
}
break;
}
},
10,
2
);
add_filter(
'manage_edit-' . BCAL_PT . '_sortable_columns',
function ( $columns ) {
$columns['bcal_when'] = 'bcal_when';
return $columns;
}
);
add_action(
'restrict_manage_posts',
function ( $post_type ) {
if ( BCAL_PT !== $post_type ) {
return;
}
$current = isset( $_GET['bcal_scope'] ) ? sanitize_key( wp_unslash( $_GET['bcal_scope'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended
echo '';
echo '';
}
);
add_action(
'pre_get_posts',
function ( $query ) {
if ( ! is_admin() || ! $query->is_main_query() || BCAL_PT !== $query->get( 'post_type' ) ) {
return;
}
if ( 'bcal_when' === $query->get( 'orderby' ) ) {
$query->set( 'meta_key', '_bcal_start' );
$query->set( 'orderby', 'meta_value' );
}
$scope = isset( $_GET['bcal_scope'] ) ? sanitize_key( wp_unslash( $_GET['bcal_scope'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended
if ( in_array( $scope, array( 'upcoming', 'past' ), true ) ) {
$query->set(
'meta_query',
array(
array(
'key' => '_bcal_start',
'value' => bcal_now(),
'compare' => 'upcoming' === $scope ? '>=' : '<',
'type' => 'DATETIME',
),
)
);
if ( ! $query->get( 'orderby' ) ) {
$query->set( 'meta_key', '_bcal_start' );
$query->set( 'orderby', 'meta_value' );
$query->set( 'order', 'upcoming' === $scope ? 'ASC' : 'DESC' );
}
}
}
);