LLMS_REST_API_Keys::create( array $data )
Create a new API Key
Parameters Parameters
- $data
-
(array) (Required) Associative array of data to set to a key's properties.
- 'description'
(string) (Required) A friendly name for the key. - 'user_id'
(int) WP_User (Required) ID of the key's owner. - 'permissions'
(string) (Required) Permission string for the key. Acceptsread
,write
, orread_write
.
- 'description'
Return Return
(WP_Error|LLMS_REST_API_Key)
Source Source
File: libraries/lifterlms-rest/includes/class-llms-rest-api-keys.php
public function create( $data ) { $data = $this->create_prepare( $data ); if ( is_wp_error( $data ) ) { return $data; } $api_key = new LLMS_REST_API_Key(); $key = 'ck_' . llms_rest_random_hash(); $secret = 'cs_' . llms_rest_random_hash(); $data['consumer_key'] = llms_rest_api_hash( $key ); $data['consumer_secret'] = $secret; $data['truncated_key'] = substr( $key, -7 ); // Set and save. $api_key->setup( $data )->save(); // Return the unhashed key on creation to be displayed once and never stored. $api_key->set( 'consumer_key_one_time', $key ); return $api_key; }
Expand full source code Collapse full source code View on GitHub
Changelog Changelog
Version | Description |
---|---|
1.0.0-beta.1 | Introduced. |