src/class-extended-cpt-admin.php
public function cols( array $cols ) : array {

		// This function gets called multiple times, so let's cache it for efficiency:
		if ( isset( $this->the_cols ) ) {
			return $this->the_cols;
		}

		$new_cols = [];
		$keep = [
			'cb',
			'title',
		];

		# Add existing columns we want to keep:
		foreach ( $cols as $id => $title ) {
			if ( in_array( $id, $keep, true ) && ! isset( $this->args['admin_cols'][ $id ] ) ) {
				$new_cols[ $id ] = $title;
			}
		}

		# Add our custom columns:
		foreach ( array_filter( $this->args['admin_cols'] ) as $id => $col ) {
			if ( is_string( $col ) && isset( $cols[ $col ] ) ) {
				# Existing (ie. built-in) column with id as the value
				$new_cols[ $col ] = $cols[ $col ];
			} elseif ( is_string( $col ) && isset( $cols[ $id ] ) ) {
				# Existing (ie. built-in) column with id as the key and title as the value
				$new_cols[ $id ] = esc_html( $col );
			} elseif ( 'author' === $col ) {
				# Automatic support for Co-Authors Plus plugin and special case for
				# displaying author column when the post type doesn't support 'author'
				if ( class_exists( 'coauthors_plus' ) ) {
					$k = 'coauthors';
				} else {
					$k = 'author';
				}
				$new_cols[ $k ] = esc_html__( 'Author', 'extended-cpts' );
			} elseif ( is_array( $col ) ) {
				if ( isset( $col['cap'] ) && ! current_user_can( $col['cap'] ) ) {
					continue;
				}
				if ( isset( $col['connection'] ) && ! function_exists( 'p2p_type' ) ) {
					continue;
				}
				if ( ! isset( $col['title'] ) ) {
					$col['title'] = $this->get_item_title( $col ) ?? $id;
				}
				$new_cols[ $id ] = esc_html( $col['title'] );
			}
		}

		# Re-add any custom columns:
		$custom   = array_diff_key( $cols, $this->_cols );
		$new_cols = array_merge( $new_cols, $custom );

		$this->the_cols = $new_cols;
		return $this->the_cols;

	}
public function cols( array $cols ) : array {

		// This function gets called multiple times, so let's cache it for efficiency:
		if ( isset( $this->the_cols ) ) {
			return $this->the_cols;
		}

		$new_cols = [];
		$keep = [
			'cb',
			'title',
		];

		# Add existing columns we want to keep:
		foreach ( $cols as $id => $title ) {
			if ( in_array( $id, $keep, true ) && ! isset( $this->args['admin_cols'][ $id ] ) ) {
				$new_cols[ $id ] = $title;
			}
		}

		# Add our custom columns:
		foreach ( array_filter( $this->args['admin_cols'] ) as $id => $col ) {
			if ( is_string( $col ) && isset( $cols[ $col ] ) ) {
				# Existing (ie. built-in) column with id as the value
				$new_cols[ $col ] = $cols[ $col ];
			} elseif ( is_string( $col ) && isset( $cols[ $id ] ) ) {
				# Existing (ie. built-in) column with id as the key and title as the value
				$new_cols[ $id ] = esc_html( $col );
			} elseif ( 'author' === $col ) {
				# Automatic support for Co-Authors Plus plugin and special case for
				# displaying author column when the post type doesn't support 'author'
				if ( class_exists( 'coauthors_plus' ) ) {
					$k = 'coauthors';
				} else {
					$k = 'author';
				}
				$new_cols[ $k ] = esc_html__( 'Author', 'extended-cpts' );
			} elseif ( is_array( $col ) ) {
				if ( isset( $col['cap'] ) && ! current_user_can( $col['cap'] ) ) {
					continue;
				}
				if ( isset( $col['connection'] ) && ! function_exists( 'p2p_type' ) ) {
					continue;
				}
				if ( ! isset( $col['title'] ) ) {
					$col['title'] = $this->get_item_title( $col ) ?? $id;
				}
				$new_cols[ $id ] = esc_html( $col['title'] );
			}
		}

		# Re-add any custom columns:
		$custom   = array_diff_key( $cols, $this->_cols );
		$new_cols = array_merge( $new_cols, $custom );

		$this->the_cols = $new_cols;
		return $this->the_cols;

	}
public function cols ( array $ cols ) : array { // This function gets called multiple times, so let's cache it for efficiency: if ( isset ( $ this -> the_cols ) ) { return $ this -> the_cols ; } $ new_cols = [ ] ; $ keep = [ 'cb' , 'title' , ] ; # Add existing columns we want to keep: foreach ( $ cols as $ id => $ title ) { if ( in_array ( $ id , $ keep , true ) && ! isset ( $ this -> args [ 'admin_cols' ] [ $ id ] ) ) { $ new_cols [ $ id ] = $ title ; } } # Add our custom columns: foreach ( array_filter ( $ this -> args [ 'admin_cols' ] ) as $ id => $ col ) { if ( is_string ( $ col ) && isset ( $ cols [ $ col ] ) ) { # Existing (ie. built-in) column with id as the value $ new_cols [ $ col ] = $ cols [ $ col ] ; } elseif ( is_string ( $ col ) && isset ( $ cols [ $ id ] ) ) { # Existing (ie. built-in) column with id as the key and title as the value $ new_cols [ $ id ] = esc_html ( $ col ) ; } elseif ( 'author' === $ col ) { # Automatic support for Co-Authors Plus plugin and special case for # displaying author column when the post type doesn't support 'author' if ( class_exists ( 'coauthors_plus' ) ) { $ k = 'coauthors' ; } else { $ k = 'author' ; } $ new_cols [ $ k ] = esc_html__ ( 'Author' , 'extended-cpts' ) ; } elseif ( is_array ( $ col ) ) { if ( isset ( $ col [ 'cap' ] ) && ! current_user_can ( $ col [ 'cap' ] ) ) { continue ; } if ( isset ( $ col [ 'connection' ] ) && ! function_exists ( 'p2p_type' ) ) { continue ; } if ( ! isset ( $ col [ 'title' ] ) ) { $ col [ 'title' ] = $ this -> get_item_title ( $ col ) ?? $ id ; } $ new_cols [ $ id ] = esc_html ( $ col [ 'title' ] ) ; } } # Re-add any custom columns: $ custom = array_diff_key ( $ cols , $ this -> _cols ) ; $ new_cols = array_merge ( $ new_cols , $ custom ) ; $ this -> the_cols = $ new_cols ; return $ this -> the_cols ; }
Add columns to the admin screen for this post type.

@link https://github.com/johnbillion/extended-cpts/wiki/Admin-columns

@param  array $cols Associative array of columns
@return array       Updated array of columns
Add columns to the admin screen for this post type .