LLMS_Rest_Admin_Settings_API_Keys::get_fields()
Get settings fields for the Keys tab.
Return Return
(array)
Source Source
File: libraries/lifterlms-rest/includes/admin/class-llms-rest-admin-settings-api-keys.php
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 | public static function get_fields() { require_once 'tables/class-llms-rest-table-api-keys.php' ; $add_key = '1' === llms_filter_input( INPUT_GET, 'add-key' , FILTER_SANITIZE_NUMBER_INT ); $key_id = llms_filter_input( INPUT_GET, 'edit-key' , FILTER_SANITIZE_NUMBER_INT ); $settings = array (); $settings [] = array ( 'class' => 'top' , 'id' => 'rest_keys_options_start' , 'type' => 'sectionstart' , ); $settings [] = array ( 'title' => $key_id || $add_key ? __( 'API Key Details' , 'lifterlms' ) : __( 'API Keys' , 'lifterlms' ), 'type' => 'title-with-html' , 'id' => 'rest_keys_options_title' , 'html' => $key_id || $add_key ? '' : '<a href="' . esc_url( admin_url( 'admin.php?page=llms-settings&tab=rest-api§ion=keys&add-key=1' ) ) . '" class="llms-button-primary small" type="submit" style="top:-2px;">' . __( 'Add API Key' , 'lifterlms' ) . '</a>' , ); if ( $add_key || $key_id ) { $key = $add_key ? false : new LLMS_REST_API_Key( $key_id ); if ( self:: $generated_key ) { $key = self:: $generated_key ; } if ( $add_key || $key ->exists() ) { $user_id = $key ? $key ->get( 'user_id' ) : get_current_user_id(); $settings [] = array ( 'title' => __( 'Description' , 'lifterlms' ), 'desc' => '<br>' . __( 'A friendly, human-readable, name used to identify the key.' , 'lifterlms' ), 'id' => 'llms_rest_key_description' , 'type' => 'text' , 'value' => $key ? $key ->get( 'description' ) : '' , 'custom_attributes' => array ( 'required' => 'required' , ), ); $settings [] = array ( 'title' => __( 'User' , 'lifterlms' ), 'class' => 'llms-select2-student' , 'desc' => sprintf( // Translators: %1$s = opening anchor tag to capabilities doc; %2$s closing anchor tag. __( 'The owner is used to determine what user %1$scapabilities%2$s are available to the API key.' , 'lifterlms' ), '</a>' ), 'custom_attributes' => array ( 'data-placeholder' => __( 'Select a user' , 'lifterlms' ), ), 'id' => 'llms_rest_key_user_id' , 'options' => llms_make_select2_student_array( array ( $user_id ) ), 'type' => 'select' , ); $settings [] = array ( 'title' => __( 'Permissions' , 'lifterlms' ), 'desc' => '<br>' . sprintf( // Translators: %1$s = opening anchor tag to doc; %2$s closing anchor tag. __( 'Determines what kind of requests can be made with the API key. %1$sRead more%2$s.' , 'lifterlms' ), '<a href="https://lifterlms.com/docs/getting-started-with-the-lifterlms-rest-api/#api-keys" target="_blank">' , '</a>' ), 'id' => 'llms_rest_key_permissions' , 'type' => 'select' , 'options' => LLMS_REST_API()->keys()->get_permissions(), 'value' => $key ? $key ->get( 'permissions' ) : '' , ); if ( $key && ! self:: $generated_key ) { $settings [] = array ( 'title' => __( 'Consumer key ending in' , 'lifterlms' ), 'custom_attributes' => array ( 'readonly' => 'readonly' , ), 'class' => 'code' , 'id' => 'llms_rest_key__read_only_key' , 'type' => 'text' , 'value' => '…' . $key ->get( 'truncated_key' ), ); $settings [] = array ( 'title' => __( 'Last accessed at' , 'lifterlms' ), 'custom_attributes' => array ( 'readonly' => 'readonly' , ), 'id' => 'llms_rest_key__read_only_date' , 'type' => 'text' , 'value' => $key ->get_last_access_date(), ); } elseif ( self:: $generated_key ) { $settings [] = array ( 'type' => 'custom-html' , 'id' => 'llms_rest_key_onetime_notice' , 'value' => '<p style="padding: 10px;border-left:4px solid #ff922b;background:rgba(255, 146, 43, 0.3);">' . __( 'Make sure to copy or download the consumer key and consumer secret. After leaving this page they will not be displayed again.' , 'lifterlms' ) . '</p>' , ); $settings [] = array ( 'title' => __( 'Consumer key' , 'lifterlms' ), 'custom_attributes' => array ( 'readonly' => 'readonly' , ), 'css' => 'width:400px' , 'class' => 'code widefat' , 'id' => 'llms_rest_key__read_only_key' , 'type' => 'text' , 'value' => $key ->get( 'consumer_key_one_time' ), ); $settings [] = array ( 'title' => __( 'Consumer secret' , 'lifterlms' ), 'custom_attributes' => array ( 'readonly' => 'readonly' , ), 'css' => 'width:400px' , 'class' => 'code widefat' , 'id' => 'llms_rest_key__read_only_secret' , 'type' => 'text' , 'value' => $key ->get( 'consumer_secret' ), ); } $buttons = '<br><br>' ; if ( self:: $generated_key ) { $download_url = wp_nonce_url( admin_url( add_query_arg( array ( 'id' => $key ->get( 'id' ), 'ck' => base64_encode ( $key ->get( 'consumer_key_one_time' ) ), //phpcs:disable WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode -- This is benign usage. ), 'admin.php' ) ), 'dl-key' , 'dl-key-nonce' ); $buttons .= '<a class="llms-button-primary" href="' . $download_url . '" target="_blank"><i class="fa fa-download" aria-hidden="true"></i> ' . __( 'Download Keys' , 'lifterlms' ) . '</a>' ; } else { $buttons .= '<button class="llms-button-primary" type="submit" value="llms-rest-save-key">' . __( 'Save' , 'lifterlms' ) . '</button>' ; } if ( $key ) { $buttons .= $buttons ? ' ' : '<br><br>' ; $buttons .= '<a class="llms-button-danger" href="' . esc_url( $key ->get_delete_link() ) . '">' . __( 'Revoke' , 'lifterlms' ) . '</a>' ; } $buttons .= wp_nonce_field( 'lifterlms-settings' , '_wpnonce' , true, false ); $settings [] = array ( 'type' => 'custom-html' , 'id' => 'llms_rest_key_buttons' , 'value' => $buttons , ); } else { $settings [] = array ( 'id' => 'rest_keys_options_invalid_error' , 'type' => 'custom-html' , 'value' => __( 'Invalid api key.' , 'lifterlms' ), ); } } else { $settings [] = array ( 'id' => 'llms_api_keys_table' , 'table' => new LLMS_REST_Table_API_Keys(), 'type' => 'table' , ); } $settings [] = array ( 'id' => 'rest_keys_options_end' , 'type' => 'sectionend' , ); return $settings ; } |
Expand full source code Collapse full source code View on GitHub
Changelog Changelog
Version | Description |
---|---|
1.0.0-beta.3 | Add "required" to the description field, add helper text, & add credential download option after generation. |
1.0.0-beta.1 | Introduced. |