Notifications::query()
Description #
Prepare and fetch notifications from database.
Source #
File: addons/notifications/query.php
public function query() { global $wpdb; $ref_id_q = ''; if ( isset( $this->args['ref_id'] ) ) { $ref_id_q = $wpdb->prepare( 'AND noti_ref_id = %d', (int) $this->args['ref_id'] ); } $ref_type_q = ''; if ( isset( $this->args['ref_type'] ) ) { $ref_type_q = $wpdb->prepare( 'AND noti_ref_type = %s', sanitize_title( $this->args['ref_type'] ) ); } $verb_q = ''; if ( isset( $this->args['verb'] ) ) { $verb_q = $wpdb->prepare( 'AND noti_verb = %s', $this->args['verb'] ); } $seen_q = ''; if ( isset( $this->args['seen'] ) ) { $seen_q = $wpdb->prepare( 'AND noti_seen = %d', (bool) $this->args['seen'] ); } $order = 'DESC' === $this->args['order'] ? 'DESC' : 'ASC'; $query = $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}ap_notifications WHERE noti_user_id = %d {$ref_id_q} {$ref_type_q} {$verb_q} {$seen_q} ORDER BY noti_date {$order} LIMIT {$this->offset},{$this->per_page}", $this->args['user_id'] ); // phpcs:ignore WordPress.DB $this->objects = $wpdb->get_results( $query ); // phpcs:ignore WordPress.DB $count_query = $wpdb->prepare( "SELECT count(noti_id) FROM {$wpdb->prefix}ap_notifications WHERE noti_user_id = %d {$ref_id_q} {$ref_type_q} {$verb_q} {$seen_q}", $this->args['user_id'] ); // phpcs:ignore WordPress.DB $this->total_count = $wpdb->get_var( apply_filters( 'ap_notifications_found_rows', $count_query, $this ) ); // phpcs:ignore WordPress.DB $this->prefetch(); parent::query(); }
Expand full source code Collapse full source code View on GitHub: addons/notifications/query.php:54
Add your comment