AnsPress_Email_Hooks::ap_after_update_question( $post_id, object $question )

Description #

Notify after question get updated.

Parameters #

  • $question
    object (Required) Question object.

Changelog #

VersionDescription
4.1.0Introduced.

Source #

File: addons/free/email.php

	public static function ap_after_update_question( $post_id, $question ) {
		if ( in_array( $question->post_status, [ 'trash', 'draft' ] ) ) {
			return;
		}

		$args = [];

		$admin_emails = self::get_admin_emails( 'email_admin_edit_question' );
		if ( ! empty( $admin_emails ) ) {
			$args['users'] = $admin_emails;
		}

		$email = new Email( 'edit_question', $args );

		$current_user = wp_get_current_user();
		$subscribers = ap_get_subscribers( [ 'subs_event' => 'question', $question->ID ] );
		$post_author  = get_user_by( 'id', $question->post_author );

		if ( $subscribers && ! ap_in_array_r( $post_author->data->user_email, $subscribers ) &&
			$post_author->data->user_email !== $current_user->user_email ) {
			$email->add_email( $post_author->data->user_email );
		}

		foreach ( (array) $subscribers as $s ) {
			if ( ap_user_can_view_post( $question ) && ! empty( $s->user_email ) &&
				$s->user_email !== $current_user->user_email ) {
				$email->add_email( $s->user_email );
			}
		}

		$email->add_template_tags( array(
			'asker'             => ap_user_display_name( $question->post_author ),
			'editor'            => ap_user_display_name( get_current_user_id() ),
			'question_title'    => $question->post_title,
			'question_link'     => get_permalink( $question->ID ),
			'question_content'  => $question->post_content,
			'question_excerpt'  => ap_truncate_chars( strip_tags( $question->post_content ), 100 ),
		));

		$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