Subscriptions to comments added for custom post types in WordPress

3.30K viewsThemes
0

I am using WooCommerce along AnsPress.

I noticed that when users post reviews (which are WP comments) for products (which are WP custom post type) and when I approve them, these users get subscribed to AnsPress table wp_ap_subscribers and they get notifications about new reviews by the AnsPress Email plugin.

This is not an expected behavior. Subscriptions should only work for comments made within AnsPress.

I found that this is done by this function:

    /**
* Subscribe user for post comments
*@param   object $comment Comment object.
*/
public static function after_new_comment($comment) {
$post = get_post( $comment->comment_post_ID );

$type = ‘q_post’;
$question_id = $post->ID;

if ( ‘answer’ == $post->post_type ) {
$type = ‘a_all’;
$question_id = $post->post_parent;
}

if ( ! ap_is_user_subscribed( $comment->comment_post_ID, $type, $comment->user_id ) ) {
ap_new_subscriber( $comment->user_id, $comment->comment_post_ID, $type, $question_id );
}
}

edited question