is_anspress()
Description #
Check if current page is AnsPress. Also check if showing question or answer page in BuddyPress.
Changelog #
Version | Description |
---|---|
4.1.8 | Added filter is_anspress . |
4.1.1 | Check for @see ap_current_page(). |
4.1.0 | Introduced. |
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' ), true ) ) { $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 = array(); foreach ( $page_slug as $slug ) { $page_ids[] = ap_opt( $slug ); } if ( in_array( $queried_object->ID, $page_ids ) ) { // phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict $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 ); }
Expand full source code Collapse full source code View on GitHub: includes/functions.php:133
Add your comment