BP_Notifications_Notification::get_query_clauses( array $args = array() )
Assemble query clauses, based on arguments, to pass to $wpdb methods.
Description
The insert(), update(), and delete() methods of wpdb expect arguments of the following forms:
- associative arrays whose key/value pairs are column => value, to be used in WHERE, SET, or VALUES clauses.
- arrays of "formats", which tell $wpdb->prepare() which type of value to expect when sanitizing (eg, array( ‘%s’, ‘%d’ ))
This utility method can be used to assemble both kinds of params, out of a single set of associative array arguments, such as:
$args = array(
'user_id' => 4,
'component_name' => 'groups',
);
This will be converted to:
array(
'data' => array(
'user_id' => 4,
'component_name' => 'groups',
),
'format' => array(
'%d',
'%s',
),
)
which can easily be passed as arguments to the $wpdb methods.
Parameters
- $args
-
(Optional) Associative array of filter arguments. See {@BP_Notifications_Notification::get()} for a breakdown.
Default value: array()
Return
(array) Associative array of 'data' and 'format' args.
Source
File: bp-notifications/classes/class-bp-notifications-notification.php
protected static function get_query_clauses( $args = array() ) { $where_clauses = array( 'data' => array(), 'format' => array(), ); // The id. if ( ! empty( $args['id'] ) ) { $where_clauses['data']['id'] = absint( $args['id'] ); $where_clauses['format'][] = '%d'; } // The user_id. if ( ! empty( $args['user_id'] ) ) { $where_clauses['data']['user_id'] = absint( $args['user_id'] ); $where_clauses['format'][] = '%d'; } // The item_id. if ( ! empty( $args['item_id'] ) ) { $where_clauses['data']['item_id'] = absint( $args['item_id'] ); $where_clauses['format'][] = '%d'; } // The secondary_item_id. if ( ! empty( $args['secondary_item_id'] ) ) { $where_clauses['data']['secondary_item_id'] = absint( $args['secondary_item_id'] ); $where_clauses['format'][] = '%d'; } // The component_name. if ( ! empty( $args['component_name'] ) ) { $where_clauses['data']['component_name'] = $args['component_name']; $where_clauses['format'][] = '%s'; } // The component_action. if ( ! empty( $args['component_action'] ) ) { $where_clauses['data']['component_action'] = $args['component_action']; $where_clauses['format'][] = '%s'; } // If is_new. if ( isset( $args['is_new'] ) ) { $where_clauses['data']['is_new'] = ! empty( $args['is_new'] ) ? 1 : 0; $where_clauses['format'][] = '%d'; } return $where_clauses; }
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.