Email::ap_after_update_question( int $post_id, object $question )

Description #

Notify after question get updated.

Parameters #

  • $post_id
    int (Required) Question id.
  • $question
    object (Required) Question object.

Changelog #

VersionDescription
4.1.0Introduced.

Source #

File: addons/email/email.php

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

		$args = array();

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

		$current_user = wp_get_current_user();
		$email        = new EmailHelper( 'edit_question', $args );

		$subscribers = ap_get_subscribers(
			array(
				'subs_event'  => 'question',
				'subs_ref_id' => $question->ID,
			)
		);

		// Exclude current author.
		if ( get_current_user_id() !== (int) $question->post_author ) {
			$email->add_user( $question->post_author );
		}

		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( wp_strip_all_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