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

133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
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 );
}

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