Automattic\WooCommerce\Admin\API\Reports

DataStore::get_filtered_ids()protectedWC 1.0

Returns filtered comma separated ids, based on query arguments from the user.

Метод класса: DataStore{}

Хуки из метода

Возвращает

Строку.

Использование

// protected - в коде основоного (родительского) или дочернего класса
$result = $this->get_filtered_ids( $query_args, $field, $separator );
$query_args(массив) (обязательный)
Parameters supplied by the user.
$field(строка) (обязательный)
Query field to filter.
$separator(строка)
Field separator.
По умолчанию: ','

Код DataStore::get_filtered_ids() WC 8.7.0

protected function get_filtered_ids( $query_args, $field, $separator = ',' ) {
	global $wpdb;

	$ids_str = '';
	$ids     = isset( $query_args[ $field ] ) && is_array( $query_args[ $field ] ) ? $query_args[ $field ] : array();

	/**
	 * Filter the IDs before retrieving report data.
	 *
	 * Allows filtering of the objects included or excluded from reports.
	 *
	 * @param array  $ids        List of object Ids.
	 * @param array  $query_args The original arguments for the request.
	 * @param string $field      The object type.
	 * @param string $context    The data store context.
	 */
	$ids = apply_filters( 'woocommerce_analytics_' . $field, $ids, $query_args, $field, $this->context );

	if ( ! empty( $ids ) ) {
		$placeholders = implode( $separator, array_fill( 0, count( $ids ), '%d' ) );
		/* phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared */
		$ids_str = $wpdb->prepare( "{$placeholders}", $ids );
		/* phpcs:enable */
	}
	return $ids_str;
}