Skip to:
Content
Pages
Categories
Search
Top
Bottom

Forum Replies Created

Viewing 4 replies - 1 through 4 (of 4 total)

  • wspencer
    Participant

    @wspencer

    Thanks for your help!


    wspencer
    Participant

    @wspencer

    Thanks. But if I do that, will those comments not show up in activity streams, then?


    wspencer
    Participant

    @wspencer

    I’m not using the do_action…that’s built into WordPress core in wp-includes/comment.php. The do_action is called during the wp_update_comment() function, which my custom comment editor uses. I could avoid it all together by doing a direct database insert using WP’s $wpdb class, but I prefer to use their built in functionality whenever possible.


    wspencer
    Participant

    @wspencer

    I’m not using a purchased theme. It’s a custom WP theme I created. There is also no BuddyPress theme, so it’s using bp-default. I only use BuddyPress to set up some core features I was looking to introduce. Here is the code from my custom comment editor. Please note that all data from $_POST checks out and is passing properly to the function (the variables $comment_ID and $comment_content are populated via the $_POST object. The wp_update_comment() function returns 1, which means it was successful.

    $commentarr = array();
     $commentarr['comment_ID'] = $comment_ID;
     $commentarr['comment_content'] = $commentContent;
     $update_success = wp_update_comment($commentarr);
    
     if ($update_success == 1) {
         $comment = get_comment($comment_ID);
    
         $article_link = get_permalink($comment->comment_post_ID);
    
         wp_redirect( $article_link );
      }
    
      else {
         $commentError = 'Something went wrong while updating your comment.';
         $hasError = true;
      }

    Then digging into the core, here’s where wp_update_comment() function is called….

    function wp_update_comment($commentarr) {
    ...
    	do_action('edit_comment', $comment_ID);
    ...
    }

    I tested this entire function and everything works fine except for do_action(‘edit_comment’, $comment_ID), which of course is only a hook for other plugins, etc to attach to. If I commented out the do_action, my comments are updated properly.

    So then I started turning off all plugins and trying again. Turns out it was BuddyPress causing the issue. After sorting through the BP code, I found that in the file bp-blogs/bp-blogs-functions.php, the function that is added to the ‘edit_comment’ hook is called bp_blogs_record_comment(), which is found around line 542. This function has some BP specific functions being called within it, which I’m not familiar with. At the end of the day, I’ve found that if I comment out the action hook in the last line, the comment editing works 100%. Here’s the code from bp_blogs_record_comment()

    function bp_blogs_record_comment( $comment_id, $is_approved = true ) {
    ...
    }
    add_action( 'comment_post', 'bp_blogs_record_comment', 10, 2 );
    //add_action( 'edit_comment', 'bp_blogs_record_comment', 10    );
Viewing 4 replies - 1 through 4 (of 4 total)
Skip to toolbar