WC_API_Authentication::get_keys_by_consumer_key()privateWC 2.4.0

Return the keys for the given consumer key

Method of the class: WC_API_Authentication{}

No Hooks.

Return

Array.

Usage

// private - for code of main (parent) class only
$result = $this->get_keys_by_consumer_key( $consumer_key );
$consumer_key(string) (required)
-

Changelog

Since 2.4.0 Introduced.

WC_API_Authentication::get_keys_by_consumer_key() code WC 8.7.0

private function get_keys_by_consumer_key( $consumer_key ) {
	global $wpdb;

	$consumer_key = wc_api_hash( sanitize_text_field( $consumer_key ) );

	$keys = $wpdb->get_row( $wpdb->prepare( "
		SELECT key_id, user_id, permissions, consumer_key, consumer_secret, nonces
		FROM {$wpdb->prefix}woocommerce_api_keys
		WHERE consumer_key = '%s'
	", $consumer_key ), ARRAY_A );

	if ( empty( $keys ) ) {
		throw new Exception( __( 'Consumer key is invalid.', 'woocommerce' ), 401 );
	}

	return $keys;
}