AnsPress_Theme::the_content_single_question( string $content )

Description #

Filter single question content to render [anspress] shortcode.

Parameters #

  • $content
    string (Required) Content.

Changelog #

VersionDescription
4.1.2Do not replace content once question is loaded.
4.1.0Introduced.

Source #

File: includes/class-theme.php

	public static function the_content_single_question( $content ) {
		global $ap_shortcode_loaded, $post, $question_rendered;

		if ( ! $post || true === $question_rendered ) {
			return $content;
		}

		if ( true !== $ap_shortcode_loaded && is_singular( 'question' ) ) {
			return do_shortcode( '[anspress]' );
		}

		// Check if user have permission.
		if ( in_array( $post->post_type, [ 'question', 'answer' ], true ) && ! ap_user_can_read_post( $post->ID, false, $post->post_type ) ) {
			return '<p>' . esc_attr__( 'Sorry, you do not have permission to read this post.', 'anspress-question-answer' ) . '</p>';
		}

		return $content;
	}

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