AnsPress_Notification_Hook::get_notifications()

Description #

Ajax callback for loading user notifications dropdown.

Source #

File: addons/free/notification.php

	public static function get_notifications() {
		if ( ! is_user_logged_in() ) {
			wp_die();
		}

		$notifications = new AnsPress_Notification_Query( [ 'user_id' => get_current_user_id() ] );

		$items = [];
		while ( $notifications->have() ) : $notifications->the_notification();
			$items[] = array(
				'ID'         => $notifications->object->noti_id,
				'verb'       => $notifications->object->noti_verb,
				'verb_label' => $notifications->get_verb(),
				'icon'       => $notifications->get_icon(),
				'avatar'     => $notifications->actor_avatar(),
				'hide_actor' => $notifications->hide_actor(),
				'actor'      => $notifications->get_actor(),
				'ref_title'  => $notifications->get_ref_title(),
				'ref_type'   => $notifications->object->noti_ref_type,
				'points'     => $notifications->get_reputation_points(),
				'date'       => ap_human_time( $notifications->get_date(), false ),
				'permalink'  => $notifications->get_permalink(),
				'seen'  		 => $notifications->object->noti_seen,
			);
		endwhile;

		ap_ajax_json( array(
			'success'       => true,
			'notifications' => $items,
			'total' 				=> ap_count_unseen_notifications(),
			'mark_args' 		=> array(
				'ap_ajax_action' => 'mark_notifications_seen',
				'__nonce'        => wp_create_nonce( 'mark_notifications_seen' ),
			),
		) );
	}

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