WordPress unresponsive after calling wp_update_comment()

In the admin panel’s “Edit Comment” page, for some reason after I click “Update” the Edit page goes into infinite loop/loading (the spinner icon in the Google Chrome tab never stops spinning). My computer goes into “deep think” for 10-20 minutes, even after I close WordPress, the web browser, and my IDE (I’m working locally on Microsoft WebMatrix 3).

Calling wp_update_comment() seems to be the problem, because when I remove it everything works fine. When I check the database I can see that the ‘comment_type’ column does get updated though, but my computer still goes into a deep think consuming resources and the Edit page goes into infinite loading.

function update_product_comment($comment_ID) {
    $commentarr = [];
    $commentarr['comment_ID'] = $comment_ID;
    $commentarr['comment_type'] = 'test';

    //wp_die(var_dump($commentarr['comment_type'])); <-- COMMENT_TYPE = 'TEST', SO FAR SO GOOD!
    wp_update_comment($commentarr); // <--- THE CULPRIT
}
add_action('edit_comment', 'update_product_comment');

I don’t know what could be causing wp_update_comment() to do this, I have no plugins installed and a basically fresh WordPress install, default wordpress theme, and no custom code. But the same problem applies no matter what theme I use. Maybe it’s WebMatrix I don’t know, can someone test the code and tell me if it works?

2 Answers
2

wp_update_comment triggers the edit_comment action (source), you’re creating an infinite loop.

Leave a Comment