html-keys-edit.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <?php
  2. if ( ! defined( 'ABSPATH' ) ) {
  3. exit;
  4. }
  5. ?>
  6. <div id="key-fields" class="settings-panel">
  7. <h2><?php esc_html_e( 'Key details', 'woocommerce' ); ?></h2>
  8. <input type="hidden" id="key_id" value="<?php echo esc_attr( $key_id ); ?>" />
  9. <table id="api-keys-options" class="form-table">
  10. <tbody>
  11. <tr valign="top">
  12. <th scope="row" class="titledesc">
  13. <label for="key_description">
  14. <?php esc_html_e( 'Description', 'woocommerce' ); ?>
  15. <?php echo wc_help_tip( __( 'Friendly name for identifying this key.', 'woocommerce' ) ); ?>
  16. </label>
  17. </th>
  18. <td class="forminp">
  19. <input id="key_description" type="text" class="input-text regular-input" value="<?php echo esc_attr( $key_data['description'] ); ?>" />
  20. </td>
  21. </tr>
  22. <tr valign="top">
  23. <th scope="row" class="titledesc">
  24. <label for="key_user">
  25. <?php esc_html_e( 'User', 'woocommerce' ); ?>
  26. <?php echo wc_help_tip( __( 'Owner of these keys.', 'woocommerce' ) ); ?>
  27. </label>
  28. </th>
  29. <td class="forminp">
  30. <?php
  31. $curent_user_id = get_current_user_id();
  32. $user_id = ! empty( $key_data['user_id'] ) ? absint( $key_data['user_id'] ) : $curent_user_id;
  33. $user = get_user_by( 'id', $user_id );
  34. /* translators: 1: user display name 2: user ID 3: user email */
  35. $user_string = sprintf(
  36. esc_html__( '%1$s (#%2$s &ndash; %3$s)', 'woocommerce' ),
  37. $user->display_name,
  38. absint( $user->ID ),
  39. $user->user_email
  40. );
  41. ?>
  42. <select class="wc-customer-search" id="key_user" data-placeholder="<?php esc_attr_e( 'Search for a user&hellip;', 'woocommerce' ); ?>" data-allow_clear="true">
  43. <option value="<?php echo esc_attr( $user_id ); ?>" selected="selected"><?php echo $user_string; ?><option>
  44. </select>
  45. </td>
  46. </tr>
  47. <tr valign="top">
  48. <th scope="row" class="titledesc">
  49. <label for="key_permissions">
  50. <?php esc_html_e( 'Permissions', 'woocommerce' ); ?>
  51. <?php echo wc_help_tip( __( 'Select the access type of these keys.', 'woocommerce' ) ); ?>
  52. </label>
  53. </th>
  54. <td class="forminp">
  55. <select id="key_permissions" class="wc-enhanced-select">
  56. <?php
  57. $permissions = array(
  58. 'read' => __( 'Read', 'woocommerce' ),
  59. 'write' => __( 'Write', 'woocommerce' ),
  60. 'read_write' => __( 'Read/Write', 'woocommerce' ),
  61. );
  62. foreach ( $permissions as $permission_id => $permission_name ) :
  63. ?>
  64. <option value="<?php echo esc_attr( $permission_id ); ?>" <?php selected( $key_data['permissions'], $permission_id, true ); ?>><?php echo esc_html( $permission_name ); ?></option>
  65. <?php endforeach; ?>
  66. </select>
  67. </td>
  68. </tr>
  69. <?php if ( 0 !== $key_id ) : ?>
  70. <tr valign="top">
  71. <th scope="row" class="titledesc">
  72. <?php esc_html_e( 'Consumer key ending in', 'woocommerce' ); ?>
  73. </th>
  74. <td class="forminp">
  75. <code>&hellip;<?php echo esc_html( $key_data['truncated_key'] ); ?></code>
  76. </td>
  77. </tr>
  78. <tr valign="top">
  79. <th scope="row" class="titledesc">
  80. <?php esc_html_e( 'Last access', 'woocommerce' ); ?>
  81. </th>
  82. <td class="forminp">
  83. <span>
  84. <?php
  85. if ( ! empty( $key_data['last_access'] ) ) {
  86. /* translators: 1: last access date 2: last access time */
  87. $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'] ) ) );
  88. echo apply_filters( 'woocommerce_api_key_last_access_datetime', $date, $key_data['last_access'] );
  89. } else {
  90. esc_html_e( 'Unknown', 'woocommerce' );
  91. }
  92. ?>
  93. </span>
  94. </td>
  95. </tr>
  96. <?php endif ?>
  97. </tbody>
  98. </table>
  99. <?php do_action( 'woocommerce_admin_key_fields', $key_data ); ?>
  100. <?php
  101. if ( 0 == $key_id ) {
  102. submit_button( __( 'Generate API key', 'woocommerce' ), 'primary', 'update_api_key' );
  103. } else {
  104. ?>
  105. <p class="submit">
  106. <?php submit_button( __( 'Save changes', 'woocommerce' ), 'primary', 'update_api_key', false ); ?>
  107. <a style="color: #a00; 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&section=keys' ) ), 'revoke' ) ); ?>"><?php esc_html_e( 'Revoke key', 'woocommerce' ); ?></a>
  108. </p>
  109. <?php
  110. }
  111. ?>
  112. </div>
  113. <script type="text/template" id="tmpl-api-keys-template">
  114. <p id="copy-error"></p>
  115. <table class="form-table">
  116. <tbody>
  117. <tr valign="top">
  118. <th scope="row" class="titledesc">
  119. <?php esc_html_e( 'Consumer key', 'woocommerce' ); ?>
  120. </th>
  121. <td class="forminp">
  122. <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>
  123. </td>
  124. </tr>
  125. <tr valign="top">
  126. <th scope="row" class="titledesc">
  127. <?php esc_html_e( 'Consumer secret', 'woocommerce' ); ?>
  128. </th>
  129. <td class="forminp">
  130. <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>
  131. </td>
  132. </tr>
  133. <tr valign="top">
  134. <th scope="row" class="titledesc">
  135. <?php esc_html_e( 'QRCode', 'woocommerce' ); ?>
  136. </th>
  137. <td class="forminp">
  138. <div id="keys-qrcode"></div>
  139. </td>
  140. </tr>
  141. </tbody>
  142. </table>
  143. </script>