LLMS_REST_API_Keys::create( array $data )

Create a new API Key

Parameters Parameters


(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. Accepts read, write, or read_write.

Top ↑

Return Return


Top ↑

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;


Top ↑

Changelog Changelog

Version Description
1.0.0-beta.1 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.