AnsPress_Hooks::publish_comment( object|array $comment )

Description #

Actions to run after posting a comment

Parameters #

  • $comment
    object | array (Required) Comment object.

Changelog #

VersionDescription
unknownunknown
4.1.2Introduced.

Source #

File: includes/hooks.php

	public static function publish_comment( $comment ) {
		$comment = (object) $comment;

		$post = ap_get_post( $comment->comment_post_ID );

		if ( ! in_array( $post->post_type, [ 'question', 'answer' ], true ) ) {
			return false;
		}

		$count = get_comment_count( $comment->comment_post_ID );
		ap_insert_qameta( $comment->comment_post_ID, array(
			'fields'       => [ 'unapproved_comments' => $count['awaiting_moderation'] ],
			'last_updated' => current_time( 'mysql' ),
		) );


		// Log to activity table.
		ap_activity_add( array(
			'q_id'    => 'answer' === $post->post_type ? $post->post_parent: $post->ID,
			'action'  => 'new_c',
			'a_id'    => 'answer' === $post->post_type ? $post->ID: 0,
			'c_id'    => $comment->comment_ID,
			'user_id' => $comment->user_id,
		) );
	}

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Add your comment