$label ) { $updated[ $key ] = $label; if ( 'sp_team' === $key ) { $updated['tony_sp_officials'] = esc_html__( 'Officials', 'tonys-sportspress-enhancements' ); } } if ( ! isset( $updated['tony_sp_officials'] ) ) { $updated['tony_sp_officials'] = esc_html__( 'Officials', 'tonys-sportspress-enhancements' ); } return $updated; } add_filter( 'manage_edit-sp_event_columns', 'tony_sportspress_event_add_officials_column', 20 ); /** * Build a display-ready officials map for an event. * * @param int $post_id Post ID. * @return array */ function tony_sportspress_event_get_officials_display( $post_id ) { $officials_by_duty = get_post_meta( $post_id, 'sp_officials', true ); if ( ! is_array( $officials_by_duty ) || empty( $officials_by_duty ) ) { return array(); } $duties = get_terms( array( 'taxonomy' => 'sp_duty', 'hide_empty' => false, ) ); $duty_names = array(); if ( is_array( $duties ) ) { foreach ( $duties as $duty ) { if ( isset( $duty->term_id, $duty->name ) ) { $duty_names[ (int) $duty->term_id ] = $duty->name; } } } $rows = array(); foreach ( $officials_by_duty as $duty_id => $official_ids ) { $duty_id = absint( $duty_id ); $official_ids = array_filter( array_map( 'absint', (array) $official_ids ) ); if ( $duty_id <= 0 || empty( $official_ids ) ) { continue; } $names = array(); foreach ( $official_ids as $official_id ) { $title = get_the_title( $official_id ); if ( is_string( $title ) && '' !== $title ) { $names[] = $title; } } if ( empty( $names ) ) { continue; } $rows[] = array( 'name' => isset( $duty_names[ $duty_id ] ) ? $duty_names[ $duty_id ] : (string) $duty_id, 'officials' => $names, ); } return $rows; } /** * Print hidden officials data on each event row for quick edit prefill. * * @param string $column Column key. * @param int $post_id Post ID. */ function tony_sportspress_event_quick_edit_officials_row_data( $column, $post_id ) { if ( 'tony_sp_officials' !== $column ) { return; } $officials = get_post_meta( $post_id, 'sp_officials', true ); if ( ! is_array( $officials ) ) { $officials = array(); } $serialized = wp_json_encode( $officials ); if ( ! is_string( $serialized ) ) { $serialized = '{}'; } $rows = tony_sportspress_event_get_officials_display( $post_id ); if ( empty( $rows ) ) { echo '—'; } else { foreach ( $rows as $row ) { echo '
'; echo '' . esc_html( $row['name'] ) . ': '; echo esc_html( implode( ', ', $row['officials'] ) ); echo '
'; } } echo ''; } add_action( 'manage_sp_event_posts_custom_column', 'tony_sportspress_event_quick_edit_officials_row_data', 20, 2 ); /** * Render quick edit UI for officials. * * @param string $column_name Column key. * @param string $post_type Post type key. */ function tony_sportspress_event_quick_edit_officials_field( $column_name, $post_type ) { if ( 'sp_event' !== $post_type || 'tony_sp_officials' !== $column_name ) { return; } static $printed = false; if ( $printed ) { return; } $printed = true; wp_nonce_field( 'tony_sp_event_officials_quick_edit', 'tony_sp_event_officials_quick_edit_nonce' ); $duties = get_terms( array( 'taxonomy' => 'sp_duty', 'hide_empty' => false, 'orderby' => 'meta_value_num', 'meta_query' => array( 'relation' => 'OR', array( 'key' => 'sp_order', 'compare' => 'NOT EXISTS', ), array( 'key' => 'sp_order', 'compare' => 'EXISTS', ), ), ) ); if ( ! is_array( $duties ) || empty( $duties ) ) { return; } $officials = get_posts( array( 'post_type' => 'sp_official', 'post_status' => 'publish', 'posts_per_page' => -1, 'orderby' => 'title', 'order' => 'ASC', ) ); if ( ! is_array( $officials ) || empty( $officials ) ) { return; } ?>
name ); ?>
$official_ids ) { $duty_id = absint( $duty_id ); if ( $duty_id <= 0 || ! is_array( $official_ids ) ) { continue; } $official_ids = array_map( 'absint', $official_ids ); $official_ids = array_filter( $official_ids ); $official_ids = array_values( array_unique( $official_ids ) ); if ( ! empty( $official_ids ) ) { $clean_officials[ $duty_id ] = $official_ids; } } update_post_meta( $post_id, 'sp_officials', $clean_officials ); } add_action( 'save_post', 'tony_sportspress_event_quick_edit_officials_save' ); /** * Prefill quick edit checkboxes with existing officials. */ function tony_sportspress_event_quick_edit_officials_script() { $screen = get_current_screen(); if ( ! $screen || 'edit-sp_event' !== $screen->id ) { return; } ?>