diff --git a/includes/sp-event-quick-edit-officials.php b/includes/sp-event-quick-edit-officials.php new file mode 100644 index 0000000..14c11f3 --- /dev/null +++ b/includes/sp-event-quick-edit-officials.php @@ -0,0 +1,234 @@ +'; +} +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 || 'sp_team' !== $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; + } + ?> +
+ $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; + } + ?> + +