ap_get_notifications( array $args = array() )

Description #

Get notifications.

Parameters #

  • $args
    array (Optional) Arguments. Default value: array()

Source #

File: addons/notifications/functions.php

function ap_get_notifications( $args = array() ) {
	global $wpdb;

	$args = wp_parse_args(
		$args,
		array(
			'number'  => 20,
			'offset'  => 0,
			'user_id' => get_current_user_id(),
		)
	);

	$number = (int) $args['number'];
	$offset = (int) $args['offset'];

	$actor_q = '';
	if ( isset( $args['actor'] ) ) {
		$actor_q = $wpdb->prepare( 'AND noti_actor = %d', $args['actor'] );
	}

	$ref_parent_q = '';
	if ( isset( $args['parent'] ) ) {
		$ref_parent_q = $wpdb->prepare( 'AND noti_parent = %d', $args['parent'] );
	}

	$ref_id_q = '';
	if ( isset( $args['ref_id'] ) ) {
		$ref_id_q = $wpdb->prepare( 'AND noti_ref_id = %d', $args['ref_id'] );
	}

	$ref_type_q = '';
	if ( isset( $args['ref_type'] ) ) {
		$ref_type_q = $wpdb->prepare( 'AND noti_ref_type = %s', $args['ref_type'] );
	}

	$verb_q = '';
	if ( isset( $args['verb'] ) ) {
		$verb_q = $wpdb->prepare( 'AND noti_verb = %s', $args['verb'] );
	}

	$seen_q = '';
	if ( isset( $args['seen'] ) ) {
		$seen_q = $wpdb->prepare( 'AND noti_seen = %d', $args['seen'] );
	}

	$query = $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}ap_notifications WHERE noti_user_id = %d {$actor_q} {$ref_parent_q} {$ref_id_q} {$ref_type_q} {$verb_q} {$seen_q} LIMIT {$offset},{$number}", $args['user_id'] ); // phpcs:ignore WordPress.DB

	return $wpdb->get_results( $query ); // phpcs:ignore WordPress.DB
}

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