WC_Auth::create_keys() protected WC 2.4.0
Create keys.
{} Это метод класса: WC_Auth{}
Хуков нет.
Возвращает
Массив.
Использование
// protected - в коде основоного (родительского) или дочернего класса $result = $this->create_keys( $app_name, $app_user_id, $scope );
- $app_name(строка) (обязательный)
- App name.
- $app_user_id(строка) (обязательный)
- User ID.
- $scope(строка) (обязательный)
- Scope.
Список изменений
С версии 2.4.0 | Введена. |
Код WC_Auth::create_keys() WC Auth::create keys WC 5.0.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,
);
}