* @license GPL-3.0+ * @link https://anspress.io * @copyright 2014 Rahul Aryan */ /** * Handle output of all default pages of AnsPress */ class AnsPress_Common_Pages { /** * Register all pages of AnsPress */ public static function register_common_pages() { ap_register_page( 'base', ap_opt( 'base_page_title' ), [ __CLASS__, 'base_page' ] ); ap_register_page( 'question', __( 'Question', 'anspress-question-answer' ), [ __CLASS__, 'question_page' ], false ); ap_register_page( 'ask', __( 'Ask', 'anspress-question-answer' ), [ __CLASS__, 'ask_page' ] ); ap_register_page( 'search', __( 'Search', 'anspress-question-answer' ), [ __CLASS__, 'search_page' ], false ); ap_register_page( 'edit', __( 'Edit Answer', 'anspress-question-answer' ), [ __CLASS__, 'edit_page' ], false ); } /** * Layout of base page */ public static function base_page() { global $questions, $wp; $keywords = ap_sanitize_unslash( 'ap_s', 'query_var', false ); $tax_relation = ! empty( $wp->query_vars['ap_tax_relation'] ) ? $wp->query_vars['ap_tax_relation'] : 'OR'; $args = array(); $args['tax_query'] = array( 'relation' => $tax_relation ); $args['tax_query'] = array( 'relation' => $tax_relation ); if ( false !== $keywords ) { $args['s'] = $keywords; } /** * FILTER: ap_main_questions_args * Filter main question list args * @var array */ $args = apply_filters( 'ap_main_questions_args', $args ); anspress()->questions = $questions = new Question_Query( $args ); ap_get_template_part( 'question-list' ); } /** * Output single question page. */ public static function question_page() { // Set Header as 404 if question id is not set. if ( false === get_question_id() ) { SELF::set_404(); return; } $post = get_post( get_question_id() ); // Override okay. // Check if user is allowed to read this question. if ( ! ap_user_can_read_question( get_question_id() ) ) { if ( 'moderate' === $post->post_status ) { $msg = __( 'This question is waiting for a moderator and cannot be viewed. Please check back later to see if it has been approved.', 'anspress-question-answer' ); } else { $msg = __( 'Sorry! you are not allowed to read this question.', 'anspress-question-answer' ); } echo '
'; return; } global $questions; anspress()->questions = $questions = new Question_Query( [ 'p' => get_question_id() ] ); if ( ap_have_questions() ) { /** * Set current question as global post * @since 2.3.3 */ while ( ap_have_questions() ) : ap_the_question(); global $post; setup_postdata( $post ); endwhile; if ( 'future' == $post->post_status ) { echo '' . __( 'This question is in waiting queue and is not accessible by anyone until it get published.', 'anspress-question-answer' ) . '
'; } else { echo $notice; // xss okay. } echo '' . esc_attr__( 'Sorry, you cannot edit this answer.', 'anspress-question-answer' ) . '
'; return; } global $editing_post; $editing_post = ap_get_post( $post_id ); ap_answer_form( $editing_post->post_parent, true ); } /** * If page is not found then set header as 404 */ public static function set_404() { global $wp_query; $wp_query->set_404(); status_header( 404 ); include ap_get_theme_location( 'not-found.php' ); } }