* @license GPL-3.0+ * @link https://anspress.io * @copyright 2014 Rahul Aryan * @package AnsPress * @subpackage Theme Functions */ // If this file is called directly, abort. if ( ! defined( 'WPINC' ) ) { die; } /** * Return current page title. * * @return string current title * @since unknown * @since 4.1.0 Removed `question_name` query var check. */ function ap_page_title() { $new_title = ''; $new_title = apply_filters( 'ap_page_title', $new_title ); return $new_title; } /** * Check if current page is search page * * @return boolean */ function is_ap_search() { if ( is_anspress() && get_query_var( 'ap_s' ) ) { return true; } return false; } /** * Get post status. * * @param boolean|integer $post_id question or answer ID. * @return string * @since 2.0.0 */ function ap_post_status( $post_id = false ) { if ( false === $post_id ) { $post_id = get_the_ID(); } return get_post_status( $post_id ); } /** * Check if current post is private. * * @param boolean|integer $post_id question or answer ID. * @return boolean */ function is_private_post( $post_id = false ) { if ( ap_post_status( $post_id ) === 'private_post' ) { return true; } return false; } /** * Check if post is waiting moderation. * * @param boolean|integer $post_id question or answer ID. * @return bool */ function is_post_waiting_moderation( $post_id = false ) { if ( get_post_status( $post_id ) === 'moderate' ) { return true; } return false; } /** * Check if question is closed. * * @param boolean|integer $post_id question or answer ID. * @return boolean * @since 2.0.0 */ function is_post_closed( $post_id = null ) { if ( '1' === ap_get_post_field( 'closed', $post_id ) ) { return true; } return false; } /** * Check if question have a parent post. * * @param boolean|integer $post_id question or answer ID. * @return boolean * @since 2.0.0 */ function ap_have_parent_post( $post_id = false ) { if ( ! $post_id ) { $post_id = get_the_ID(); } // Get post. $post_o = ap_get_post( $post_id ); if ( $post_o->post_parent > 0 && 'question' === $post_o->post_type ) { return true; } return false; } /** * Anspress pagination * Uses paginate_links. * * @param float $current Current paged, if not set then get_query_var('paged') is used. * @param int $total Total number of pages, if not set then global $questions is used. * @param string $format pagination format. * @param string $page_num_link Base link. * @return string */ function ap_pagination( $current = false, $total = false, $format = '?paged=%#%', $page_num_link = false ) { global $ap_max_num_pages, $ap_current; if ( is_front_page() ) { $format = ''; } $big = 999999999; // Need an unlikely integer. if ( false === $current ) { $paged = ap_sanitize_unslash( 'ap_paged', 'r', 1 ); $current = is_front_page() ? max( 1, $paged ) : max( 1, get_query_var( 'paged' ) ); } elseif ( ! empty( $ap_current ) ) { $current = $ap_current; } if ( ! empty( $ap_max_num_pages ) ) { $total = $ap_max_num_pages; } elseif ( false === $total && isset( anspress()->questions->max_num_pages ) ) { $total = anspress()->questions->max_num_pages; } if ( false === $page_num_link ) { $page_num_link = str_replace( array( '&', '&' ), '&', get_pagenum_link( $big ) ); } $base = str_replace( $big, '%#%', $page_num_link ); if ( '1' == $total ) { // WPCS: loose comparison ok. return; } echo '