WordPress at Your Fingertips
function is not described

WC_Auth::create_keys() protected WC 2.4.0

Create keys.

{} It's a method of the class: WC_Auth{}

No Hooks.

Return

Array.

Usage

// protected - for code of main (parent) or child class
$result = $this->create_keys( $app_name, $app_user_id, $scope );
$app_name(string) (required)
App name.
$app_user_id(string) (required)
User ID.
$scope(string) (required)
Scope.

Changelog

Since 2.4.0 Introduced.

Code of WC_Auth::create_keys() WC 5.8.0

protected function create_keys( $app_name, $app_user_id, $scope ) {
	global $wpdb;

	$description = sprintf(
		/* translators: 1: app name 2: scope 3: date 4: time */
		__( '%1$s - API %2$s (created on %3$s at %4$s).', 'woocommerce' ),
		wc_clean( $app_name ),
		$this->get_i18n_scope( $scope ),
		date_i18n( wc_date_format() ),
		date_i18n( wc_time_format() )
	);
	$user = wp_get_current_user();

	// Created API keys.
	$permissions     = in_array( $scope, array( 'read', 'write', 'read_write' ), true ) ? sanitize_text_field( $scope ) : 'read';
	$consumer_key    = 'ck_' . wc_rand_hash();
	$consumer_secret = 'cs_' . wc_rand_hash();

	$wpdb->insert(
		$wpdb->prefix . 'woocommerce_api_keys',
		array(
			'user_id'         => $user->ID,
			'description'     => $description,
			'permissions'     => $permissions,
			'consumer_key'    => wc_api_hash( $consumer_key ),
			'consumer_secret' => $consumer_secret,
			'truncated_key'   => substr( $consumer_key, -7 ),
		),
		array(
			'%d',
			'%s',
			'%s',
			'%s',
			'%s',
			'%s',
		)
	);

	return array(
		'key_id'          => $wpdb->insert_id,
		'user_id'         => $app_user_id,
		'consumer_key'    => $consumer_key,
		'consumer_secret' => $consumer_secret,
		'key_permissions' => $permissions,
	);
}