I wrote a function to update the comment time when a comment goes form unapproved to approved:
function ji_update_comment_date($comment){
$commentarr = array(
'comment_ID'=>comment_ID(),
//this is where it fails me,I can't get the ID
'comment_date'=>date("Y-m-d H:i:s"),
'comment_date_gmt'=> date("Y-m-d H:i:s")
);
wp_update_comment( $commentarr );}
add_action('comment_unapproved_to_approved','ji_update_comment_date');
SO the comment_ID() is not working ,I can't seem to get it otherwise my code works perfectly.
get_comment_ID()
instead becausecomment_ID()
must be within a loop.get_comment_ID()
worked for me with JS disabled. Using the suggestion from @JackJohansson ( adding$comment = get_comment( $comment );
see wordpress.stackexchange.com/a/45195/2807 ) and using'comment_ID' => $comment->comment_ID,
ended up being the real solution.$comment->comment_ID
should absolutely work.