AnsPress_Post_Table_Hooks::custom_columns_value( string $column )
Description #
Custom post table column values.
Parameters #
- $columnstring (Required) Columns name.
Source #
File: admin/class-list-table-hooks.php
public static function custom_columns_value( $column ) {
global $post;
if ( ! in_array( $post->post_type, array( 'question', 'answer' ), true ) ) {
return $column;
}
if ( 'ap_author' === $column ) {
echo '<a class="ap-author-col" href="' . esc_url( ap_user_link( $post->post_author ) ) . '">';
ap_author_avatar( 28 );
echo '<span>' . esc_attr( ap_user_display_name() ) . '</span>';
echo '</a>';
} elseif ( 'status' === $column ) {
global $wp_post_statuses;
echo '<span class="post-status">';
if ( isset( $wp_post_statuses[ $post->post_status ] ) ) {
echo esc_attr( $wp_post_statuses[ $post->post_status ]->label );
}
echo '</span>';
} elseif ( 'question_category' === $column && taxonomy_exists( 'question_category' ) ) {
$category = get_the_terms( $post->ID, 'question_category' );
if ( ! empty( $category ) ) {
$out = array();
foreach ( (array) $category as $cat ) {
$out[] = edit_term_link( $cat->name, '', '', $cat, false );
}
echo join( ', ', $out ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
} else {
esc_html_e( '--', 'anspress-question-answer' );
}
} elseif ( 'question_tag' === $column && taxonomy_exists( 'question_tag' ) ) {
$terms = get_the_terms( $post->ID, 'question_tag' );
if ( ! empty( $terms ) ) {
$out = array();
foreach ( (array) $terms as $term ) {
$url = esc_url(
add_query_arg(
array(
'post_type' => $post->post_type,
'question_tag' => $term->slug,
),
'edit.php'
)
);
$out[] = sprintf( '<a href="%s">%s</a>', $url, esc_html( sanitize_term_field( 'name', $term->name, $term->term_id, 'question_tag', 'display' ) ) );
}
echo join( ', ', $out ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
} else {
esc_attr_e( '--', 'anspress-question-answer' );
}
} elseif ( 'answers' === $column ) {
$url = add_query_arg(
array(
'post_type' => 'answer',
'post_parent' => $post->ID,
),
'edit.php'
);
// translators: %d is total numbers of answer.
$anchor_title = sprintf( _n( '%d Answer', '%d Answers', $post->answers, 'anspress-question-answer' ), $post->answers );
echo '<a class="ans-count" title="' . esc_html( $anchor_title ) . '" href="' . esc_url( $url ) . '">' . esc_attr( $post->answers ) . '</a>';
} elseif ( 'parent_question' === $column ) {
$url = add_query_arg(
array(
'post' => $post->post_parent,
'action' => 'edit',
),
'post.php'
);
echo '<a class="parent_question" href="' . esc_url( $url ) . '"><strong>' . esc_html( get_the_title( $post->post_parent ) ) . '</strong></a>';
} elseif ( 'votes' === $column ) {
echo '<span class="vote-count">' . esc_attr( $post->votes_net ) . '</span>';
} elseif ( 'flags' === $column ) {
echo '<span class="flag-count' . ( $post->flags ? ' flagged' : '' ) . '">' . esc_attr( $post->flags ) . '</span>';
}
}
Expand full source code Collapse full source code View on GitHub: admin/class-list-table-hooks.php:221
Add your comment