AnsPress_Notification_Hook::load_more_notifications()

Description #

Ajax callback for loading more notifications.

Source #

File: addons/free/notification.php

	public static function load_more_notifications() {
		check_admin_referer( 'load_more_notifications', '__nonce' );

		$user_id = ap_sanitize_unslash( 'user_id', 'r' );
		$paged = ap_sanitize_unslash( 'current', 'r', 1 ) + 1;

		ob_start();
		$notifications = new AnsPress_Notification_Query( [ 'user_id' => $user_id, 'paged' => $paged ] );

		while ( $notifications->have() ) : $notifications->the_notification();
			$notifications->item_template();
		endwhile;

		$html = ob_get_clean();

		$paged = $notifications->total_pages > $paged ? $paged : 0;

		ap_ajax_json( array(
			'success' => true,
			'args'    => [ 'ap_ajax_action' => 'load_more_notifications', '__nonce' => wp_create_nonce( 'load_more_notifications' ), 'current' => (int) $paged, 'user_id' => $user_id ],
			'html'    => $html,
			'element' => '.ap-noti',
		) );
	}

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