LLMS_Rest_Admin_Settings_API_Keys::save_update( int $key_id )
Form handler to save an API key.
Parameters Parameters
- $key_id
-
(int) (Required) API Key ID.
Return Return
(LLMS_REST_API_Key|WP_Error)
Source Source
File: libraries/lifterlms-rest/includes/admin/class-llms-rest-admin-settings-api-keys.php
protected static function save_update( $key_id ) {
$key = LLMS_REST_API()->keys()->get( $key_id );
if ( ! $key ) {
// Translators: %s = Invalid API Key ID.
return new WP_Error( 'llms_rest_api_key_not_found', sprintf( __( '"%s" is not a valid API Key.', 'lifterlms' ), $key_id ) );
}
$user_id = llms_filter_input( INPUT_POST, 'llms_rest_key_user_id', FILTER_SANITIZE_NUMBER_INT );
$authorized = self::authorize_key_owner( $user_id );
if ( is_wp_error( $authorized ) ) {
return $authorized;
}
$update = LLMS_REST_API()->keys()->update(
array(
'id' => $key_id,
'description' => llms_filter_input_sanitize_string( INPUT_POST, 'llms_rest_key_description' ),
'user_id' => $user_id,
'permissions' => llms_filter_input_sanitize_string( INPUT_POST, 'llms_rest_key_permissions' ),
)
);
return $update;
}
Expand full source code Collapse full source code View on GitHub
Changelog Changelog
| Version | Description |
|---|---|
| 1.0.0-beta.27 | Replaced use of the deprecated FILTER_SANITIZE_STRING constant. |
| 1.0.0-beta.1 | Introduced. |