is_anspress()

Description #

Check if current page is AnsPress. Also check if showing question or answer page in BuddyPress.

Changelog #

VersionDescription
4.1.8Added filter is_anspress.
4.1.1Check for @see ap_current_page().
4.1.0Introduced.

Source #

File: includes/functions.php

function is_anspress() {
	$ret = false;

	// If BuddyPress installed.
	if ( function_exists( 'bp_current_component' ) ) {
		if ( in_array( bp_current_component(),  array( 'qa', 'questions', 'answers' ) ) ) {
			$ret = true;
		}
	}

	$page_slug      = array_keys( ap_main_pages() );
	$queried_object = get_queried_object();

	// Check if main pages.
	if ( $queried_object instanceof WP_Post ) {
		$page_ids = [];
		foreach ( $page_slug as $slug ) {
			$page_ids[] = ap_opt( $slug );
		}

		if ( in_array( $queried_object->ID, $page_ids ) ) {
			$ret = true;
		}
	}

	// Check if ap_page.
	if ( is_search() && 'question' === get_query_var( 'post_type' ) ) {
		$ret = true;
	} elseif ( '' !== ap_current_page() ) {
		$ret = true;
	}

	/**
	 * Filter for overriding is_anspress() return value.
	 *
	 * @param boolean $ret True or false.
	 * @since 4.1.8
	 */
	return apply_filters( 'is_anspress', $ret );
}

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Add your comment