Skip to content

Instantly share code, notes, and snippets.

@timelsass
Created January 15, 2020 22:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timelsass/cb4ed1497f562ff5b716fceb4e6b2ec0 to your computer and use it in GitHub Desktop.
Save timelsass/cb4ed1497f562ff5b716fceb4e6b2ec0 to your computer and use it in GitHub Desktop.
Adds screen option for toggle the display of the comment column in WP Dashboard comments list.
<?php
/**
* Plugin Name: WPSE356451 Toggle Comment Column
* Description: Adds screen option for toggle the display of the comment column in WP Dashboard comments list.
* Plugin URI: https://wordpress.stackexchange.com/questions/356451/add-a-comment-on-off-option-in-screen-options-for-comments
* Author: Tim Elsass
* Author URI: tim.ph
*/
/**
* Removes core's comment column and adds a screen option for toggling "Comment" column display.
*/
add_filter( 'manage_edit-comments_columns', function( $columns ) {
// Remove core comment column.
unset( $columns['comment'] );
// Custom "Comment" column to add to screen options and output.
$custom_column = [ 'WPSE356451_add_comment' => 'Comment' ];
$columns = array_slice( $columns, 0, 2, true ) + $custom_column + array_slice( $columns, 2, NULL, true );
return $columns;
} );
/**
* Handles output of "Comment" column in WP Dashboard comments list.
*/
add_action( 'manage_comments_custom_column', function( $column, $comment_ID ) {
global $comment;
// Check for custom comment column and handle output.
if ( 'WPSE356451_add_comment' === $column ) {
echo $comment->comment_content;
}
}, 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment