Automattic\WooCommerce\Internal\Admin\ProductReviews

ReviewsListTable::get_sort_arguments()protectedWC 1.0

Builds the orderby and order arguments based on the current request.

Method of the class: ReviewsListTable{}

No Hooks.

Return

Array.

Usage

// protected - for code of main (parent) or child class
$result = $this->get_sort_arguments() : array;

ReviewsListTable::get_sort_arguments() code WC 7.1.1

protected function get_sort_arguments() : array {
	$orderby = sanitize_text_field( wp_unslash( $_REQUEST['orderby'] ?? '' ) );
	$order   = sanitize_text_field( wp_unslash( $_REQUEST['order'] ?? '' ) );

	$args = [];

	if ( ! in_array( $orderby, $this->get_sortable_columns(), true ) ) {
		$orderby = 'comment_date_gmt';
	}

	// If ordering by "rating", then we need to adjust to sort by meta value.
	if ( 'rating' === $orderby ) {
		$orderby          = 'meta_value_num';
		$args['meta_key'] = 'rating';
	}

	if ( ! in_array( strtolower( $order ), [ 'asc', 'desc' ], true ) ) {
		$order = 'desc';
	}

	return wp_parse_args(
		[
			'orderby' => $orderby,
			'order'   => strtolower( $order ),
		],
		$args
	);
}