I've added a custom column to the edit-comments.php page called "Tips". This column includes a checkbox.
My question is when you click on the checkbox, how do you trigger the "update_comment_meta" function?
This is what I have done, and all I receive is a "function comment_edit_tip is not defined" error.
Any ideas?
functions.php file :
// create the tips column in the admin comments section
function tips_add_comments_columns( $my_cols ) {
$tip_columns = array(
'comment_tip' => 'Tip',
);
// set the column so it displays in the third spot
$my_cols = array_slice( $my_cols, 0, 3, true ) + $tip_columns + array_slice( $my_cols, 3, NULL, true );
// return the result
return $my_cols;
}
add_filter('manage_edit-comments_columns', 'tips_add_comments_columns');
// display if comment is a tip or not in the column
function tips_add_comment_columns_content( $column, $comment_id ) {
if ($column == 'comment_tip')
{
$tip = get_comment_meta($comment_id, 'tip', true);
if ($tip == 'yes')
{
echo '<div><input type="checkbox" id="' . $comment_id . '" onclick="comment_edit_tip(' . $comment_id . ', \'yes\')" checked /> <span class="message">Yes</span></div>';
}
else
{
echo '<div><input type="checkbox" id="' . $comment_id . '" onclick="comment_edit_tip(' . $comment_id . ', \'no\')" /> <span class="message">No</span></div>';
}
}
}
add_action('manage_comments_custom_column', 'tips_add_comment_columns_content', 10, 2);
// update the comment meta
function comment_edit_tip($comment_id, $value) {
if ($value == 'yes')
{
update_comment_meta($comment_id, 'tip', 'yes');
}
if ($value == 'no')
{
update_comment_meta($comment_id, 'tip', 'no');
}
}