class-wc-settings-rest-api.php
5 years ago
html-admin-page-shipping-classes.php
4 weeks ago
html-admin-page-shipping-providers.php
4 weeks ago
html-admin-page-shipping-zone-methods.php
4 weeks ago
html-admin-page-shipping-zones-instance.php
8 years ago
html-admin-page-shipping-zones.php
4 weeks ago
html-keys-edit.php
4 weeks ago
html-settings-tax.php
1 year ago
html-webhooks-edit.php
4 weeks ago
settings-tax.php
2 months ago
html-keys-edit.php
170 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Admin view: Edit API keys |
| 4 | * |
| 5 | * @package WooCommerce\Admin\Settings |
| 6 | */ |
| 7 | |
| 8 | defined( 'ABSPATH' ) || exit; |
| 9 | ?> |
| 10 | |
| 11 | <div id="key-fields" class="settings-panel"> |
| 12 | <h2><?php esc_html_e( 'Key details', 'woocommerce' ); ?></h2> |
| 13 | |
| 14 | <div class="inline notice"> |
| 15 | <ul class="advice"> |
| 16 | <li><?php esc_html_e( 'API keys open up access to potentially sensitive information. Only share them with organizations you trust.', 'woocommerce' ); ?></li> |
| 17 | <li><?php esc_html_e( 'Stick to one key per client: this makes it easier to revoke access in the future for a single client, without causing disruption for others.', 'woocommerce' ); ?></li> |
| 18 | </ul> |
| 19 | </div> |
| 20 | |
| 21 | <input type="hidden" id="key_id" value="<?php echo esc_attr( $key_id ); ?>" /> |
| 22 | |
| 23 | <table id="api-keys-options" class="form-table"> |
| 24 | <tbody> |
| 25 | <tr valign="top"> |
| 26 | <th scope="row" class="titledesc"> |
| 27 | <label for="key_description"> |
| 28 | <?php esc_html_e( 'Description', 'woocommerce' ); ?> |
| 29 | <?php echo wc_help_tip( __( 'Friendly name for identifying this key.', 'woocommerce' ) ); ?> |
| 30 | </label> |
| 31 | </th> |
| 32 | <td class="forminp"> |
| 33 | <input maxlength="200" id="key_description" type="text" class="input-text regular-input" value="<?php echo esc_attr( $key_data['description'] ); ?>" /> |
| 34 | <p class="description"> |
| 35 | <?php esc_html_e( 'Add a meaningful description, including a note of the person, company or app you are sharing the key with.', 'woocommerce' ); ?> |
| 36 | </p> |
| 37 | </td> |
| 38 | </tr> |
| 39 | <tr valign="top"> |
| 40 | <th scope="row" class="titledesc"> |
| 41 | <label for="key_user"> |
| 42 | <?php esc_html_e( 'User', 'woocommerce' ); ?> |
| 43 | <?php echo wc_help_tip( __( 'Owner of these keys.', 'woocommerce' ) ); ?> |
| 44 | </label> |
| 45 | </th> |
| 46 | <td class="forminp"> |
| 47 | <?php |
| 48 | $current_user_id = get_current_user_id(); |
| 49 | $user_id = ! empty( $key_data['user_id'] ) ? absint( $key_data['user_id'] ) : $current_user_id; |
| 50 | $user = get_user_by( 'id', $user_id ); |
| 51 | $user_string = sprintf( |
| 52 | /* translators: 1: user display name 2: user ID 3: user email */ |
| 53 | esc_html__( '%1$s (#%2$s – %3$s)', 'woocommerce' ), |
| 54 | $user->display_name, |
| 55 | absint( $user->ID ), |
| 56 | $user->user_email |
| 57 | ); |
| 58 | ?> |
| 59 | <select class="wc-customer-search" id="key_user" data-placeholder="<?php esc_attr_e( 'Search for a user…', 'woocommerce' ); ?>" data-allow_clear="true"> |
| 60 | <option value="<?php echo esc_attr( $user_id ); ?>" selected="selected"><?php echo htmlspecialchars( wp_kses_post( $user_string ) ); // htmlspecialchars to prevent XSS when rendered by selectWoo. ?></option> |
| 61 | </select> |
| 62 | </td> |
| 63 | </tr> |
| 64 | <tr valign="top"> |
| 65 | <th scope="row" class="titledesc"> |
| 66 | <label for="key_permissions"> |
| 67 | <?php esc_html_e( 'Permissions', 'woocommerce' ); ?> |
| 68 | <?php echo wc_help_tip( __( 'Select the access type of these keys.', 'woocommerce' ) ); ?> |
| 69 | </label> |
| 70 | </th> |
| 71 | <td class="forminp"> |
| 72 | <select id="key_permissions" class="wc-enhanced-select"> |
| 73 | <?php |
| 74 | $permissions = array( |
| 75 | 'read' => __( 'Read', 'woocommerce' ), |
| 76 | 'write' => __( 'Write', 'woocommerce' ), |
| 77 | 'read_write' => __( 'Read/Write', 'woocommerce' ), |
| 78 | ); |
| 79 | |
| 80 | foreach ( $permissions as $permission_id => $permission_name ) : |
| 81 | ?> |
| 82 | <option value="<?php echo esc_attr( $permission_id ); ?>" <?php selected( $key_data['permissions'], $permission_id, true ); ?>><?php echo esc_html( $permission_name ); ?></option> |
| 83 | <?php endforeach; ?> |
| 84 | </select> |
| 85 | <p class="conditional description" data-depends-on="#key_permissions" data-show-if-equals="write"> |
| 86 | <?php esc_html_e( 'Write-only keys do not prevent clients from seeing information about the entities they are updating.', 'woocommerce' ); ?> |
| 87 | </p> |
| 88 | </td> |
| 89 | </tr> |
| 90 | |
| 91 | <?php if ( 0 !== $key_id ) : ?> |
| 92 | <tr valign="top"> |
| 93 | <th scope="row" class="titledesc"> |
| 94 | <?php esc_html_e( 'Consumer key ending in', 'woocommerce' ); ?> |
| 95 | </th> |
| 96 | <td class="forminp"> |
| 97 | <code>…<?php echo esc_html( $key_data['truncated_key'] ); ?></code> |
| 98 | </td> |
| 99 | </tr> |
| 100 | <tr valign="top"> |
| 101 | <th scope="row" class="titledesc"> |
| 102 | <?php esc_html_e( 'Last access', 'woocommerce' ); ?> |
| 103 | </th> |
| 104 | <td class="forminp"> |
| 105 | <span> |
| 106 | <?php |
| 107 | if ( ! empty( $key_data['last_access'] ) ) { |
| 108 | /* translators: 1: last access date 2: last access time */ |
| 109 | $date = sprintf( __( '%1$s at %2$s', 'woocommerce' ), date_i18n( wc_date_format(), strtotime( $key_data['last_access'] ) ), date_i18n( wc_time_format(), strtotime( $key_data['last_access'] ) ) ); |
| 110 | |
| 111 | echo esc_html( apply_filters( 'woocommerce_api_key_last_access_datetime', $date, $key_data['last_access'] ) ); |
| 112 | } else { |
| 113 | esc_html_e( 'Unknown', 'woocommerce' ); |
| 114 | } |
| 115 | ?> |
| 116 | </span> |
| 117 | </td> |
| 118 | </tr> |
| 119 | <?php endif ?> |
| 120 | </tbody> |
| 121 | </table> |
| 122 | |
| 123 | <?php do_action( 'woocommerce_admin_key_fields', $key_data ); ?> |
| 124 | |
| 125 | <?php |
| 126 | if ( 0 === intval( $key_id ) ) { |
| 127 | submit_button( __( 'Generate API key', 'woocommerce' ), 'primary', 'update_api_key' ); |
| 128 | } else { |
| 129 | ?> |
| 130 | <p class="submit"> |
| 131 | <?php submit_button( __( 'Save changes', 'woocommerce' ), 'primary', 'update_api_key', false ); ?> |
| 132 | <a style="color: var(--wc-destructive, #cc1818); text-decoration: none; margin-left: 10px;" href="<?php echo esc_url( wp_nonce_url( add_query_arg( array( 'revoke-key' => $key_id ), admin_url( 'admin.php?page=wc-settings&tab=advanced§ion=keys' ) ), 'revoke' ) ); ?>"><?php esc_html_e( 'Revoke key', 'woocommerce' ); ?></a> |
| 133 | </p> |
| 134 | <?php |
| 135 | } |
| 136 | ?> |
| 137 | </div> |
| 138 | |
| 139 | <script type="text/template" id="tmpl-api-keys-template"> |
| 140 | <p id="copy-error"></p> |
| 141 | <table class="form-table"> |
| 142 | <tbody> |
| 143 | <tr valign="top"> |
| 144 | <th scope="row" class="titledesc"> |
| 145 | <?php esc_html_e( 'Consumer key', 'woocommerce' ); ?> |
| 146 | </th> |
| 147 | <td class="forminp"> |
| 148 | <input id="key_consumer_key" type="text" value="{{ data.consumer_key }}" size="55" readonly="readonly"> <button type="button" class="button-secondary copy-key" data-tip="<?php esc_attr_e( 'Copied!', 'woocommerce' ); ?>"><?php esc_html_e( 'Copy', 'woocommerce' ); ?></button> |
| 149 | </td> |
| 150 | </tr> |
| 151 | <tr valign="top"> |
| 152 | <th scope="row" class="titledesc"> |
| 153 | <?php esc_html_e( 'Consumer secret', 'woocommerce' ); ?> |
| 154 | </th> |
| 155 | <td class="forminp"> |
| 156 | <input id="key_consumer_secret" type="text" value="{{ data.consumer_secret }}" size="55" readonly="readonly"> <button type="button" class="button-secondary copy-secret" data-tip="<?php esc_attr_e( 'Copied!', 'woocommerce' ); ?>"><?php esc_html_e( 'Copy', 'woocommerce' ); ?></button> |
| 157 | </td> |
| 158 | </tr> |
| 159 | <tr valign="top"> |
| 160 | <th scope="row" class="titledesc"> |
| 161 | <?php esc_html_e( 'QRCode', 'woocommerce' ); ?> |
| 162 | </th> |
| 163 | <td class="forminp"> |
| 164 | <div id="keys-qrcode"></div> |
| 165 | </td> |
| 166 | </tr> |
| 167 | </tbody> |
| 168 | </table> |
| 169 | </script> |
| 170 |