LLMS_REST_API_Keys::is_data_valid( array $data )
Validate data supplied for creating/updating a key.
Parameters Parameters
- $data
-
(array) (Required) Associative array of data to set to a key's properties.
- 'description'
(string) A friendly name for the key. - 'user_id'
(int) WP_User ID of the key's owner. - 'permissions'
(string) Permission string for the key. Acceptsread
,write
, orread_write
.
- 'description'
Return Return
(WP_Error|true) When data is invalid will return a WP_Error with information about the invalid properties, otherwise true
denoting data is valid.
Source Source
File: libraries/lifterlms-rest/includes/class-llms-rest-api-keys.php
protected function is_data_valid( $data ) { // First conditions prevents '', '0', 0, etc... & second prevents invalid / non existant user ids. if ( ( isset( $data['user_id'] ) && empty( $data['user_id'] ) ) || ( ! empty( $data['user_id'] ) && ! get_user_by( 'id', $data['user_id'] ) ) ) { // Translators: %s = Invalid user id. return new WP_Error( 'llms_rest_key_invalid_user_id', sprintf( __( '"%s" is not a valid user ID.', 'lifterlms' ), $data['user_id'] ) ); } // Prevent blank/empty descriptions. if ( isset( $data['description'] ) && empty( $data['description'] ) ) { return new WP_Error( 'llms_rest_key_invalid_description', __( 'An API Description is required.', 'lifterlms' ) ); } // Validate Permissions. if ( ! empty( $data['permissions'] ) && ! in_array( $data['permissions'], array_keys( $this->get_permissions() ), true ) ) { // Translators: %s = Invalid permission string. return new WP_Error( 'llms_rest_key_invalid_permissions', sprintf( __( '"%s" is not a valid permission.', 'lifterlms' ), $data['permissions'] ) ); } return true; }
Expand full source code Collapse full source code View on GitHub
Changelog Changelog
Version | Description |
---|---|
1.0.0-beta.1 | Introduced. |