nauman
nauman

Reputation: 11

How to customize comment functionality in wordpress?

I am new to wordpress and i want to approve the comment programmatically whenever any user comment on blog post,so i have created plugin and i am using this code:

add_filter('wp_insert_comment','sandy_approve_comment');

function sandy_approve_comment($comment_id) {

    // Get the comment based on the incoming ID
    $comment = get_comment( $comment_id );

    // Set its approved comment to 1
    $comment->comment_approved = 1;

    // Save this value to the database
    wp_update_comment( $comment );

}

but i am getting this error: Cannot use object of type stdClass as array in /var/www/html/SandyBlog/wp-includes/comment.php on line 1915

I know we can do this from admin panel but i want to do it programmatically.Please suggest me what to do. Thanks in advance

Upvotes: 0

Views: 331

Answers (2)

laurent avril
laurent avril

Reputation: 21

Try this code :

// Get the comment object
$comment = get_comment( $comment_id );

// Get the comment object
$comment_id = $_comment->comment_ID;

// Set its to not approve comment
wp_set_comment_status($comment_id, '0');

Upvotes: 0

KayakJosh
KayakJosh

Reputation: 48

Are you try to automatically approve every comment without moderating them? If so just uncheck the following settings under Settings > Discussion

  • Comment must be manually approved
  • Comment author must have a previously approved comment

Upvotes: 1

Related Questions