Last active
September 22, 2016 02:56
-
-
Save harisrozak/f390f50288a599830bb29c89c00bb70d to your computer and use it in GitHub Desktop.
WordPress :: Custom comment admin column
This file contains hidden or 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 | |
// Modify which columns display in the admin views | |
add_filter('manage_edit-comments_columns', 'harisrozak_comments_add_columns'); | |
function harisrozak_comments_add_columns($columns) { | |
$columns['rating'] = "Rating"; | |
return $columns; | |
} | |
// Custom column output when admin is viewing the comment | |
add_action('manage_comments_custom_column', 'harisrozak_comments_columns', 10, 2); | |
function harisrozak_comments_columns($column, $comment_ID) { | |
if($column == 'rating') { | |
$rating = get_field('rating', 'comment_' . $comment_ID); | |
if($rating != '') { | |
for ($i=0; $i < $rating; $i++) { | |
echo "★"; | |
} | |
} | |
else { | |
echo "<i>empty</i>"; | |
} | |
} | |
} | |
// edit column width | |
add_action('admin_head', 'harisrozak_comments_columns_width'); | |
function harisrozak_comments_columns_width() { | |
$screen = get_current_screen(); | |
if($screen->id == 'edit-comments') { | |
echo '<style type="text/css">'; | |
echo '.manage-column.column-rating#rating { width: 100px }'; | |
echo '.rating.column-rating { font-size: 21px }'; | |
echo '</style>'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment