Email::ap_after_new_answer( integer $answer_id )

Description #

Send email after new answer.

Parameters #

  • $answer_id
    integer (Required) Answer ID.

Changelog #

VersionDescription
4.1.0Introduced.

Source #

File: addons/email/email.php

	public function ap_after_new_answer( $answer_id ) {
		$current_user = wp_get_current_user();
		$args         = array(
			'users' => array(),
		);

		$admin_emails = $this->get_admin_emails( 'email_admin_new_answer' );
		if ( ! empty( $admin_emails ) ) {
			$args['users'] = $admin_emails;
		}

		$answer = ap_get_post( $answer_id );

		if ( ap_opt( 'email_user_new_answer' ) && 'private_post' !== $answer->post_status && 'moderate' !== $answer->post_status ) {
			$subscribers = ap_get_subscribers(
				array(
					'subs_event'  => 'question',
					'subs_ref_id' => $answer->post_parent,
				)
			);

			foreach ( (array) $subscribers as $s ) {
				if ( ap_user_can_view_post( $answer ) && $s->user_email !== $current_user->user_email ) {
					$args['users'][] = $s->user_email;
				}
			}
		}

		$args['tags'] = array(
			'{answerer}'       => ap_user_display_name( $answer->post_author ),
			'{question_title}' => esc_html( get_the_title( $answer->post_parent ) ),
			'{answer_link}'    => wp_get_shortlink( $answer->ID ),
			'{answer_content}' => $answer->post_content,
			'{answer_excerpt}' => ap_truncate_chars( wp_strip_all_tags( $answer->post_content ), 100 ),
		);

		$email = new EmailHelper( 'new_answer', $args );
		$email->send_emails();
	}

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