AnsPress_Hooks::transition_post_status( string $new_status, string $old_status, WP_Post $post )

Description #

Trigger activity update hook on question and answer status transition.

Parameters #

  • $new_status
    string (Required) New post status.
  • $old_status
    string (Required) Old post status.
  • $post
    WP_Post (Required) WordPress post object.

Changelog #

VersionDescription
4.1.2Introduced.

Source #

File: includes/hooks.php

	public static function transition_post_status( $new_status, $old_status, $post ) {
		if ( 'new' === $old_status || ! in_array( $post->post_type, [ 'answer', 'question' ], true ) ) {
			return;
		}

		$question_id = 'answer' === $post->post_type ? $post->post_parent : $post->ID;
		$answer_id   = 'answer' === $post->post_type ? $post->ID : 0;

		// Log to db.
		ap_activity_add( array(
			'q_id'   => $question_id,
			'a_id'   => $answer_id,
			'action' => 'status_' . $new_status,
		) );
	}

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