$trustbio_cols Existing columns. * @return array */ public function add_column( array $trustbio_cols ): array { $trustbio_cols['trustbio_authors'] = __( 'Authors', 'trustbio' ); return $trustbio_cols; } /** * Render the TrustBio authors column cell. * * @param string $trustbio_col_name Column name. * @param int $trustbio_post_id Post ID. */ public function render_column( string $trustbio_col_name, int $trustbio_post_id ): void { if ( 'trustbio_authors' !== $trustbio_col_name ) { return; } $trustbio_authors = trustbio_get_post_authors( $trustbio_post_id ); if ( empty( $trustbio_authors ) ) { echo '—'; return; } $trustbio_names = array_map( static function ( $trustbio_entry ) { return esc_html( $trustbio_entry['author']->display_name ); }, $trustbio_authors ); echo '' . implode( ', ', $trustbio_names ) . ''; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped } /** * Render the Quick Edit box fields. * * @param string $trustbio_col_name Column name that triggered this. * @param string $trustbio_post_type Post type. */ public function render_quick_edit( string $trustbio_col_name, string $trustbio_post_type ): void { if ( 'trustbio_authors' !== $trustbio_col_name ) { return; } if ( ! trustbio_is_enabled_for_post_type( $trustbio_post_type ) ) { return; } wp_nonce_field( 'trustbio_quick_edit', 'trustbio_quick_edit_nonce' ); $trustbio_categories = trustbio_get_categories( true ); $trustbio_box_class = new TrustBio_Author_Box(); $trustbio_all_boxes = $trustbio_box_class->get_all(); ?>

absint( $trustbio_e['author_id'] ?? 0 ), 'category_id' => absint( $trustbio_e['category_id'] ?? 0 ) ?: null, 'sort_order' => absint( $trustbio_e['sort_order'] ?? 0 ), ); }, $trustbio_assignments ); update_post_meta( $trustbio_post_id, '_trustbio_authors', $trustbio_sanitized ); } } /** * AJAX: Save bulk edit author assignments. */ public function ajax_bulk_save(): void { check_ajax_referer( 'trustbio_bulk_edit_save', 'nonce' ); if ( ! current_user_can( 'edit_posts' ) ) { wp_send_json_error( array( 'message' => __( 'Permission denied.', 'trustbio' ) ), 403 ); } $trustbio_post_ids = isset( $_POST['post_ids'] ) && is_array( $_POST['post_ids'] ) ? array_map( 'absint', wp_unslash( $_POST['post_ids'] ) ) : array(); $trustbio_json = sanitize_text_field( wp_unslash( $_POST['authors_json'] ?? '[]' ) ); $trustbio_add = json_decode( $trustbio_json, true ); if ( ! is_array( $trustbio_add ) || empty( $trustbio_add ) ) { wp_send_json_error( array( 'message' => __( 'No authors to add.', 'trustbio' ) ) ); } $trustbio_updated = 0; foreach ( $trustbio_post_ids as $trustbio_post_id ) { if ( ! current_user_can( 'edit_post', $trustbio_post_id ) ) { continue; } $trustbio_existing = get_post_meta( $trustbio_post_id, '_trustbio_authors', true ); $trustbio_existing = is_array( $trustbio_existing ) ? $trustbio_existing : array(); // Merge — don't duplicate. $trustbio_existing_ids = array_column( $trustbio_existing, 'author_id' ); foreach ( $trustbio_add as $trustbio_new ) { $trustbio_aid = absint( $trustbio_new['author_id'] ?? 0 ); if ( ! $trustbio_aid || in_array( $trustbio_aid, $trustbio_existing_ids, true ) ) { continue; } $trustbio_existing[] = array( 'author_id' => $trustbio_aid, 'category_id' => absint( $trustbio_new['category_id'] ?? 0 ) ?: null, 'sort_order' => count( $trustbio_existing ), ); $trustbio_existing_ids[] = $trustbio_aid; } update_post_meta( $trustbio_post_id, '_trustbio_authors', $trustbio_existing ); ++$trustbio_updated; } wp_send_json_success( array( /* translators: %d: number of posts updated */ 'message' => sprintf( __( 'Authors added to %d post(s).', 'trustbio' ), $trustbio_updated ), ) ); } /** * Enqueue scripts for Quick/Bulk Edit on the post list screen. * * @param string $trustbio_hook Current admin hook. */ public function enqueue_assets( string $trustbio_hook ): void { if ( 'edit.php' !== $trustbio_hook ) { return; } // Enqueue as a proper WP-registered file — no inline