BP_Notifications_Notification::get_where_sql( array $args = array(), string $select_sql = '', string $from_sql = '', string $join_sql = '', string $meta_query_sql = '' )
Assemble the WHERE clause of a get() SQL statement.
Description
Used by BP_Notifications_Notification::get() to create its WHERE clause.
Parameters
- $args
-
(Optional) See BP_Notifications_Notification::get() for more details.
Default value: array()
- $select_sql
-
(Optional) SQL SELECT fragment.
Default value: ''
- $from_sql
-
(Optional) SQL FROM fragment.
Default value: ''
- $join_sql
-
(Optional) SQL JOIN fragment.
Default value: ''
- $meta_query_sql
-
(Optional) SQL meta query fragment.
Default value: ''
Return
(string) WHERE clause.
Source
File: bp-notifications/classes/class-bp-notifications-notification.php
protected static function get_where_sql( $args = array(), $select_sql = '', $from_sql = '', $join_sql = '', $meta_query_sql = '' ) { global $wpdb; $where_conditions = array(); $where = ''; // The id. if ( ! empty( $args['id'] ) ) { $id_in = implode( ',', wp_parse_id_list( $args['id'] ) ); $where_conditions['id'] = "id IN ({$id_in})"; } // The user_id. if ( ! empty( $args['user_id'] ) ) { $user_id_in = implode( ',', wp_parse_id_list( $args['user_id'] ) ); $where_conditions['user_id'] = "user_id IN ({$user_id_in})"; } // The item_id. if ( ! empty( $args['item_id'] ) ) { $item_id_in = implode( ',', wp_parse_id_list( $args['item_id'] ) ); $where_conditions['item_id'] = "item_id IN ({$item_id_in})"; } // The secondary_item_id. if ( ! empty( $args['secondary_item_id'] ) ) { $secondary_item_id_in = implode( ',', wp_parse_id_list( $args['secondary_item_id'] ) ); $where_conditions['secondary_item_id'] = "secondary_item_id IN ({$secondary_item_id_in})"; } // The component_name. if ( ! empty( $args['component_name'] ) ) { if ( ! is_array( $args['component_name'] ) ) { $component_names = explode( ',', $args['component_name'] ); } else { $component_names = $args['component_name']; } $cn_clean = array(); foreach ( $component_names as $cn ) { $cn_clean[] = $wpdb->prepare( '%s', $cn ); } $cn_in = implode( ',', $cn_clean ); $where_conditions['component_name'] = "component_name IN ({$cn_in})"; } // The component_action. if ( ! empty( $args['component_action'] ) ) { if ( ! is_array( $args['component_action'] ) ) { $component_actions = explode( ',', $args['component_action'] ); } else { $component_actions = $args['component_action']; } $ca_clean = array(); foreach ( $component_actions as $ca ) { $ca_clean[] = $wpdb->prepare( '%s', $ca ); } $ca_in = implode( ',', $ca_clean ); $where_conditions['component_action'] = "component_action IN ({$ca_in})"; } // If is_new. if ( ! empty( $args['is_new'] ) && 'both' !== $args['is_new'] ) { $where_conditions['is_new'] = "is_new = 1"; } elseif ( isset( $args['is_new'] ) && ( 0 === $args['is_new'] || false === $args['is_new'] ) ) { $where_conditions['is_new'] = "is_new = 0"; } // The search_terms. if ( ! empty( $args['search_terms'] ) ) { $search_terms_like = '%' . bp_esc_like( $args['search_terms'] ) . '%'; $where_conditions['search_terms'] = $wpdb->prepare( "( component_name LIKE %s OR component_action LIKE %s )", $search_terms_like, $search_terms_like ); } // The date query. if ( ! empty( $args['date_query'] ) ) { $where_conditions['date_query'] = self::get_date_query_sql( $args['date_query'] ); } // The meta query. if ( ! empty( $meta_query_sql['where'] ) ) { $where_conditions['meta_query'] = $meta_query_sql['where']; } /** * Filters the MySQL WHERE conditions for the Notifications items get method. * * @since BuddyPress 2.3.0 * * @param array $where_conditions Current conditions for MySQL WHERE statement. * @param array $args Parsed arguments passed into method. * @param string $select_sql Current SELECT MySQL statement at point of execution. * @param string $from_sql Current FROM MySQL statement at point of execution. * @param string $join_sql Current INNER JOIN MySQL statement at point of execution. * @param string $meta_query_sql Current meta query WHERE statement at point of execution. */ $where_conditions = apply_filters( 'bp_notifications_get_where_conditions', $where_conditions, $args, $select_sql, $from_sql, $join_sql, $meta_query_sql ); // Custom WHERE. if ( ! empty( $where_conditions ) ) { $where = 'WHERE ' . implode( ' AND ', $where_conditions ); } return $where; }
Changelog
Version | Description |
---|---|
BuddyPress 1.9.0 | Introduced. |
Questions?
We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.