AnsPress_Question_Shortcode::anspress_question_sc( array $atts, string $content = '' )

Description #

Control the output of [question] shortcode

Parameters #

  • $atts
    array (Required) Attributes.
  • $content
    string (Optional) Content. Default value: ''

Changelog #

VersionDescription
2.0.0Introduced.

Source #

File: includes/shortcode-question.php

	public function anspress_question_sc( $atts, $content = '' ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed
		ob_start();
		echo '<div id="anspress" class="ap-eq">';

		/**
		 * Action is fired before loading AnsPress body.
		 */
		do_action( 'ap_before_question_shortcode' );

		$id = ! empty( $atts['ID'] ) ? absint( $atts['ID'] ) : absint( $atts['id'] );

		$questions = ap_get_question( $id );

		if ( $questions->have_posts() ) {
			/**
			 * Set current question as global post
			 *
			 * @since 2.3.3
			 */

			while ( $questions->have_posts() ) :
				$questions->the_post();
				include ap_get_theme_location( 'shortcode/question.php' );
			endwhile;
		} else {
			esc_attr_e( 'Invalid or non existing question id.', 'anspress-question-answer' );
		}

		echo '</div>';
		wp_reset_postdata();

		return ob_get_clean();
	}

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