AnsPress_BasePage_Shortcode::anspress_sc( array $atts, string $content = '' )

Description #

Control the output of [anspress] shortcode.

Parameters #

  • $atts
    array (Required) Attributes of the shortcode.
    • 'categories'
      (string) Slug of question_category
    • 'tags'
      (string) Slug of question_tag
    • 'tax_relation'
      (string) Taxonomy relation, see here @link <a href="https://codex.wordpress.org/Taxonomies">https://codex.wordpress.org/Taxonomies</a>
    • 'tags_operator'
      (string) Operator for question_tag taxonomy
    • 'categories_operator'
      (string) Operator for question_category taxonomy
    • 'page'
      (string) Select a page to display.
    • 'hide_list_head'
      (boolean) Hide list head?
    • 'order_by'
      (string) Sort by.
  • $content
    string (Optional) Shortcode content. Default value: ''

Changelog #

VersionDescription
3.0.0Added new attribute hide_list_head and attr_order_by.
2.0.0Introduced.

Source #

File: includes/shortcode-basepage.php

	public function anspress_sc( $atts, $content = '' ) {
		global $ap_shortcode_loaded;

		// Drop current page variable cache. As we are allowing to change page from shortcode.
		wp_cache_delete( 'current_page', 'anspress' );

		// Check if AnsPress shortcode already loaded.
		if ( true === $ap_shortcode_loaded ) {
			return __( 'AnsPress shortcode cannot be nested.', 'anspress-question-answer' );
		}

		wp_enqueue_script( 'anspress-main' );
		wp_enqueue_script( 'anspress-theme' );
		wp_enqueue_style( 'anspress-main' );
		wp_enqueue_style( 'anspress-fonts' );

		$ap_shortcode_loaded = true;

		$this->attributes( $atts, $content );

		ob_start();
		echo '<div id="anspress" class="anspress">';

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

			// Include theme file.
			ap_page( $this->current_page );

		echo '</div>';
		// Linkback to author.
		if ( ! ap_opt( 'author_credits' ) ) {
			echo '<div class="ap-cradit">' . esc_attr__( 'Question and answer is powered by', 'anspress-question-answer' ) . ' <a href="https://anspress.net" target="_blank">anspress.net</a></div>';
		}

		wp_reset_postdata();
		$ap_shortcode_loaded = false;
		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