AnsPress_BP_Hooks::bp_loadmore()

Description #

Ajax callback for loading more posts.

Source #

File: addons/free/buddypress.php

	public static function bp_loadmore() {
		$type = ap_sanitize_unslash( 'type', 'r' );
		$order_by = ap_sanitize_unslash( 'order_by', 'r' );
		$user_id = (int) ap_sanitize_unslash( 'user_id', 'r' );
		$paged = (int) ap_sanitize_unslash( 'current', 'r' ) + 1;
		check_ajax_referer( 'loadmore-' . $type, '__nonce' );

		if ( 'questions' === $type ) {
			ob_start();
			SELF::page_questions( $user_id, $paged, true );
			$html = ob_get_clean();

			$paged = anspress()->questions->max_num_pages > $paged ? $paged : false;

			ap_ajax_json(array(
				'success'  => true,
				'element'  => '#ap-bp-questions',
				'args'     => [ '__nonce' => wp_create_nonce( 'loadmore-questions' ), 'type' => 'questions', 'current' => $paged, 'user_id' => bp_displayed_user_id() ],
				'html'   	 => $html,
			));
		} elseif ( 'answers' === $type ) {
			ob_start();
			SELF::page_answers( $user_id, $paged, $order_by, true );
			$html = ob_get_clean();

			global $answers;
			$paged = $answers->max_num_pages > $paged ? $paged : false;

			ap_ajax_json(array(
				'success'  => true,
				'element'  => '#ap-bp-answers',
				'args'  => [ '__nonce' => wp_create_nonce( 'loadmore-answers' ), 'type' => 'answers', 'current' => $paged, 'user_id' => bp_displayed_user_id(), 'order_by' => $order_by ],
				'html'   	 => $html,
			));
		}
	}

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