BP_Optout::get_query_clauses( array $args = array() )

Assemble query clauses, based on arguments, to pass to $wpdb methods.


Description 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,
    'email_type' => 'type_string',
);

This will be converted to:

array(
    'data' => array(
        'user_id' => 4,
        'email_type'   => 'type_string',
    ),
    'format' => array(
        '%d',
        '%s',
    ),
)

which can easily be passed as arguments to the $wpdb methods.


Top ↑

Parameters Parameters

$args

(array) (Optional) Associative array of filter arguments. See {@BP_optout::get()} for a breakdown.

Default value: array()


Top ↑

Return Return

(array) Associative array of 'data' and 'format' args.


Source Source

File: bp-core/classes/class-bp-optout.php

	protected static function get_query_clauses( $args = array() ) {
		$where_clauses = array(
			'data'   => array(),
			'format' => array(),
		);

		// id.
		if ( ! empty( $args['id'] ) ) {
			$where_clauses['data']['id'] = absint( $args['id'] );
			$where_clauses['format'][]   = '%d';
		}

		// email_address.
		if ( ! empty( $args['email_address'] ) ) {
			$where_clauses['data']['email_address_hash'] = $args['email_address'];
			$where_clauses['format'][]                   = '%s';
		}

		// user_id.
		if ( ! empty( $args['user_id'] ) ) {
			$where_clauses['data']['user_id'] = absint( $args['user_id'] );
			$where_clauses['format'][]        = '%d';
		}

		// email_type.
		if ( ! empty( $args['email_type'] ) ) {
			$where_clauses['data']['email_type'] = $args['email_type'];
			$where_clauses['format'][]           = '%s';
		}

		return $where_clauses;
	}


Top ↑

Changelog Changelog

Changelog
Version Description
8.0.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.