WC_Auth::create_keys()
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 8.7.0
protected function create_keys( $app_name, $app_user_id, $scope ) { global $wpdb; $description = sprintf( '%s - API (%s)', wc_trim_string( wc_clean( $app_name ), 170 ), gmdate( 'Y-m-d H:i:s' ) ); $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, ); }