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

Assemble the ORDER BY clause of a get() SQL statement.


Description Description

Used by BP_Optout::get() to create its ORDER BY clause.


Top ↑

Parameters Parameters

$args

(array) (Optional) See BP_optout::get() for more details.

Default value: array()


Top ↑

Return Return

(string) ORDER BY clause.


Source Source

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

	protected static function get_order_by_sql( $args = array() ) {

		$conditions = array();
		$retval     = '';

		// Order by.
		if ( ! empty( $args['order_by'] ) ) {
			$order_by_clean = array();
			$columns        = array( 'id', 'email_address_hash', 'user_id', 'email_type', 'date_modified' );
			foreach ( (array) $args['order_by'] as $key => $value ) {
				if ( in_array( $value, $columns, true ) ) {
					$order_by_clean[] = $value;
				}
			}
			if ( ! empty( $order_by_clean ) ) {
				$order_by               = implode( ', ', $order_by_clean );
				$conditions['order_by'] = "{$order_by}";
			}
		}

		// Sort order direction.
		if ( ! empty( $args['sort_order'] ) ) {
			$sort_order               = bp_esc_sql_order( $args['sort_order'] );
			$conditions['sort_order'] = "{$sort_order}";
		}

		// Custom ORDER BY.
		if ( ! empty( $conditions['order_by'] ) ) {
			$retval = 'ORDER BY ' . implode( ' ', $conditions );
		}

		return $retval;
	}


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.