AnsPress_Hooks::question_answer_hooks( integer $post_id, object $post, boolean $updated )

Description #

Trigger AnsPress posts hooks right after inserting question/answer

Parameters #

  • $post_id
    integer (Required) Post ID.
  • $post
    object (Required) Post Object
  • $updated
    boolean (Required) Is updating post

Changelog #

VersionDescription
3.0.3Introduced.

Source #

File: includes/hooks.php

	public static function question_answer_hooks( $post_id, $post, $updated ) {
		if ( wp_is_post_autosave( $post ) || wp_is_post_revision( $post ) ) {
			return;
		}

		// check if post type is question or answer.
		if ( ! in_array( $post->post_type, [ 'question', 'answer' ] ) ) {
			return;
		}

		if ( $updated ) {
			if ( 'answer' === $post->post_type ) {
				// Update answer count.
				ap_update_answers_count( $post->post_parent );
			}

			/**
			 * Action triggered right after updating question/answer.
			 *
			 * @param integer $post_id Inserted post ID.
			 * @param object	$post		Inserted post object.
			 * @since 0.9
			 */
			do_action( 'ap_processed_update_' . $post->post_type, $post_id, $post );

		} else {
			/**
			 * Action triggered right after inserting new question/answer.
			 *
			 * @param integer $post_id Inserted post ID.
			 * @param object	$post		Inserted post object.
			 * @since 0.9
			 */
			do_action( 'ap_processed_new_' . $post->post_type, $post_id, $post );
		}

		if ( 'question' === $post->post_type ) {
			// Update qameta terms.
			ap_update_qameta_terms( $post_id );
		}
	}

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