$config ) { $post_type = CPT::post_type_slug( $slug ); if ( ! empty( $config['fields']['photo'] ) ) { $this->with_thumbnail[] = $post_type; } add_filter( "manage_{$post_type}_posts_columns", array( $this, 'add_columns' ) ); add_action( "manage_{$post_type}_posts_custom_column", array( $this, 'render_column' ), 10, 2 ); } } public function add_columns( array $columns ): array { $post_type = get_current_screen()->post_type ?? ''; if ( in_array( $post_type, $this->with_thumbnail, true ) ) { // Rebuilt so the column lands right after Title. $with_image = array(); foreach ( $columns as $key => $label ) { $with_image[ $key ] = $label; if ( 'title' === $key ) { $with_image['mapfield_spots_thumbnail'] = __( 'Image', 'mapfield-spots' ); } } $columns = $with_image; } $columns['mapfield_spots_location'] = __( 'Location', 'mapfield-spots' ); return $columns; } public function render_column( string $column, int $post_id ): void { if ( 'mapfield_spots_thumbnail' === $column ) { if ( has_post_thumbnail( $post_id ) ) { echo get_the_post_thumbnail( $post_id, 'thumbnail', array( 'class' => 'mapfield_spots-column-thumb' ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- core function, already escapes its own output } else { echo ''; } return; } if ( 'mapfield_spots_location' !== $column ) { return; } $lat = get_post_meta( $post_id, '_mapfield_spots_lat', true ); $lng = get_post_meta( $post_id, '_mapfield_spots_lng', true ); if ( '' === $lat || '' === $lng ) { echo '' . esc_html__( 'No location', 'mapfield-spots' ) . ''; } else { echo '' . esc_html__( 'Location set', 'mapfield-spots' ) . ''; } } }