ap_current_page( false|string $looking_for = false )

Description #

Return current AnsPress page

Parameters #

  • $looking_for
    false | string (Optional) Looking for page. Default value: false

Changelog #

VersionDescription
unknownunknown
4.1.9Changed cache key which was causing conflict with core.
4.1.2If 404 do not return anything.
4.1.15Added parameter $looking_for.
4.1.1Do not return base by default.
4.1.0Introduced.

Source #

File: includes/theme.php

function ap_current_page( $looking_for = false ) {
	$query_var  = get_query_var( 'ap_page', '' );
	$main_pages = array_keys( ap_main_pages() );
	$page_ids   = [];

	foreach ( $main_pages as $page_slug ) {
		$page_ids[ ap_opt( $page_slug ) ] = $page_slug;
	}

	if ( is_question() || is_singular( 'question' ) ) {
		$query_var = 'question';
	} elseif ( 'edit' === $query_var ) {
		$query_var = 'edit';
	} elseif ( in_array( $query_var . '_page', $main_pages, true ) ) {
		$query_var = $query_var;
	} elseif ( in_array( get_the_ID(), array_keys( $page_ids ) ) ) {
		$query_var = str_replace( '_page', '', $page_ids[ get_the_ID() ] );
	} elseif ( 'base' === $query_var ) {
		$query_var = 'base';
	} elseif ( is_404() ) {
		$query_var = '';
	}

	/**
	 * Filter AnsPress current page.
	 *
	 * @param    string $query_var Current page slug.
	 */
	$ret = apply_filters( 'ap_current_page', esc_attr( $query_var ) );

	if ( false !== $looking_for ) {
		return $looking_for === $ret;
	}

	return $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