Created
January 15, 2020 22:00
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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