Нет описания

html-webhooks-edit.php 9.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. <?php
  2. /**
  3. * Admin View: Edit Webhooks
  4. *
  5. * @package WooCommerce\Admin\Webhooks\Views
  6. */
  7. if ( ! defined( 'ABSPATH' ) ) {
  8. exit;
  9. }
  10. ?>
  11. <input type="hidden" name="webhook_id" value="<?php echo esc_attr( $webhook->get_id() ); ?>" />
  12. <div id="webhook-options" class="settings-panel">
  13. <h2><?php esc_html_e( 'Webhook data', 'woocommerce' ); ?></h2>
  14. <table class="form-table">
  15. <tbody>
  16. <tr valign="top">
  17. <th scope="row" class="titledesc">
  18. <label for="webhook_name">
  19. <?php esc_html_e( 'Name', 'woocommerce' ); ?>
  20. <?php
  21. /* translators: %s: date */
  22. echo wc_help_tip( sprintf( __( 'Friendly name for identifying this webhook, defaults to Webhook created on %s.', 'woocommerce' ), strftime( _x( '%b %d, %Y @ %I:%M %p', 'Webhook created on date parsed by strftime', 'woocommerce' ) ) ) ); // @codingStandardsIgnoreLine
  23. ?>
  24. </label>
  25. </th>
  26. <td class="forminp">
  27. <input name="webhook_name" id="webhook_name" type="text" class="input-text regular-input" value="<?php echo esc_attr( $webhook->get_name() ); ?>" />
  28. </td>
  29. </tr>
  30. <tr valign="top">
  31. <th scope="row" class="titledesc">
  32. <label for="webhook_status">
  33. <?php esc_html_e( 'Status', 'woocommerce' ); ?>
  34. <?php echo wc_help_tip( __( 'The options are &quot;Active&quot; (delivers payload), &quot;Paused&quot; (does not deliver), or &quot;Disabled&quot; (does not deliver due delivery failures).', 'woocommerce' ) ); ?>
  35. </label>
  36. </th>
  37. <td class="forminp">
  38. <select name="webhook_status" id="webhook_status" class="wc-enhanced-select">
  39. <?php
  40. $statuses = wc_get_webhook_statuses();
  41. $current_status = $webhook->get_status();
  42. foreach ( $statuses as $status_slug => $status_name ) :
  43. ?>
  44. <option value="<?php echo esc_attr( $status_slug ); ?>" <?php selected( $current_status, $status_slug, true ); ?>><?php echo esc_html( $status_name ); ?></option>
  45. <?php endforeach; ?>
  46. </select>
  47. </td>
  48. </tr>
  49. <tr valign="top">
  50. <th scope="row" class="titledesc">
  51. <label for="webhook_topic">
  52. <?php esc_html_e( 'Topic', 'woocommerce' ); ?>
  53. <?php echo wc_help_tip( __( 'Select when the webhook will fire.', 'woocommerce' ) ); ?>
  54. </label>
  55. </th>
  56. <td class="forminp">
  57. <select name="webhook_topic" id="webhook_topic" class="wc-enhanced-select">
  58. <?php
  59. $topic_data = WC_Admin_Webhooks::get_topic_data( $webhook );
  60. $topics = apply_filters(
  61. 'woocommerce_webhook_topics',
  62. array(
  63. '' => __( 'Select an option&hellip;', 'woocommerce' ),
  64. 'coupon.created' => __( 'Coupon created', 'woocommerce' ),
  65. 'coupon.updated' => __( 'Coupon updated', 'woocommerce' ),
  66. 'coupon.deleted' => __( 'Coupon deleted', 'woocommerce' ),
  67. 'coupon.restored' => __( 'Coupon restored', 'woocommerce' ),
  68. 'customer.created' => __( 'Customer created', 'woocommerce' ),
  69. 'customer.updated' => __( 'Customer updated', 'woocommerce' ),
  70. 'customer.deleted' => __( 'Customer deleted', 'woocommerce' ),
  71. 'order.created' => __( 'Order created', 'woocommerce' ),
  72. 'order.updated' => __( 'Order updated', 'woocommerce' ),
  73. 'order.deleted' => __( 'Order deleted', 'woocommerce' ),
  74. 'order.restored' => __( 'Order restored', 'woocommerce' ),
  75. 'product.created' => __( 'Product created', 'woocommerce' ),
  76. 'product.updated' => __( 'Product updated', 'woocommerce' ),
  77. 'product.deleted' => __( 'Product deleted', 'woocommerce' ),
  78. 'product.restored' => __( 'Product restored', 'woocommerce' ),
  79. 'action' => __( 'Action', 'woocommerce' ),
  80. )
  81. );
  82. foreach ( $topics as $topic_slug => $topic_name ) :
  83. $selected = $topic_slug === $topic_data['topic'] || $topic_slug === $topic_data['resource'] . '.' . $topic_data['event'];
  84. ?>
  85. <option value="<?php echo esc_attr( $topic_slug ); ?>" <?php selected( $selected, true, true ); ?>><?php echo esc_html( $topic_name ); ?></option>
  86. <?php endforeach; ?>
  87. </select>
  88. </td>
  89. </tr>
  90. <tr valign="top" id="webhook-action-event-wrap">
  91. <th scope="row" class="titledesc">
  92. <label for="webhook_action_event">
  93. <?php esc_html_e( 'Action event', 'woocommerce' ); ?>
  94. <?php echo wc_help_tip( __( 'Enter the action that will trigger this webhook.', 'woocommerce' ) ); ?>
  95. </label>
  96. </th>
  97. <td class="forminp">
  98. <input name="webhook_action_event" id="webhook_action_event" type="text" class="input-text regular-input" value="<?php echo esc_attr( $topic_data['event'] ); ?>" />
  99. </td>
  100. </tr>
  101. <tr valign="top">
  102. <th scope="row" class="titledesc">
  103. <label for="webhook_delivery_url">
  104. <?php esc_html_e( 'Delivery URL', 'woocommerce' ); ?>
  105. <?php echo wc_help_tip( __( 'URL where the webhook payload is delivered.', 'woocommerce' ) ); ?>
  106. </label>
  107. </th>
  108. <td class="forminp">
  109. <input name="webhook_delivery_url" id="webhook_delivery_url" type="text" class="input-text regular-input" value="<?php echo esc_attr( $webhook->get_delivery_url() ); ?>" />
  110. </td>
  111. </tr>
  112. <tr valign="top">
  113. <th scope="row" class="titledesc">
  114. <label for="webhook_secret">
  115. <?php esc_html_e( 'Secret', 'woocommerce' ); ?>
  116. <?php echo wc_help_tip( __( 'The secret key is used to generate a hash of the delivered webhook and provided in the request headers.', 'woocommerce' ) ); ?>
  117. </label>
  118. </th>
  119. <td class="forminp">
  120. <input name="webhook_secret" id="webhook_secret" type="text" class="input-text regular-input" value="<?php echo esc_attr( $webhook->get_secret() ); ?>" />
  121. </td>
  122. </tr>
  123. <tr valign="top">
  124. <th scope="row" class="titledesc">
  125. <label for="webhook_api_version">
  126. <?php esc_html_e( 'API Version', 'woocommerce' ); ?>
  127. <?php echo wc_help_tip( __( 'REST API version used in the webhook deliveries.', 'woocommerce' ) ); ?>
  128. </label>
  129. </th>
  130. <td class="forminp">
  131. <select name="webhook_api_version" id="webhook_api_version">
  132. <?php foreach ( array_reverse( wc_get_webhook_rest_api_versions() ) as $version ) : ?>
  133. <option value="<?php echo esc_attr( $version ); ?>" <?php selected( $version, $webhook->get_api_version(), true ); ?>>
  134. <?php
  135. /* translators: %d: rest api version number */
  136. echo esc_html( sprintf( __( 'WP REST API Integration v%d', 'woocommerce' ), str_replace( 'wp_api_v', '', $version ) ) );
  137. ?>
  138. </option>
  139. <?php endforeach; ?>
  140. <option value="legacy_v3" <?php selected( 'legacy_v3', $webhook->get_api_version(), true ); ?>><?php esc_html_e( 'Legacy API v3 (deprecated)', 'woocommerce' ); ?></option>
  141. </select>
  142. </td>
  143. </tr>
  144. </tbody>
  145. </table>
  146. <?php do_action( 'woocommerce_webhook_options' ); ?>
  147. </div>
  148. <div id="webhook-actions" class="settings-panel">
  149. <h2><?php esc_html_e( 'Webhook actions', 'woocommerce' ); ?></h2>
  150. <table class="form-table">
  151. <tbody>
  152. <?php if ( $webhook->get_date_created() && '0000-00-00 00:00:00' !== $webhook->get_date_created()->date( 'Y-m-d H:i:s' ) ) : ?>
  153. <?php if ( is_null( $webhook->get_date_modified() ) ) : ?>
  154. <tr valign="top">
  155. <th scope="row" class="titledesc">
  156. <?php esc_html_e( 'Created at', 'woocommerce' ); ?>
  157. </th>
  158. <td class="forminp">
  159. <?php echo esc_html( date_i18n( __( 'M j, Y @ G:i', 'woocommerce' ), strtotime( $webhook->get_date_created()->date( 'Y-m-d H:i:s' ) ) ) ); ?>
  160. </td>
  161. </tr>
  162. <?php else : ?>
  163. <tr valign="top">
  164. <th scope="row" class="titledesc">
  165. <?php esc_html_e( 'Created at', 'woocommerce' ); ?>
  166. </th>
  167. <td class="forminp">
  168. <?php echo esc_html( date_i18n( __( 'M j, Y @ G:i', 'woocommerce' ), strtotime( $webhook->get_date_created()->date( 'Y-m-d H:i:s' ) ) ) ); ?>
  169. </td>
  170. </tr>
  171. <tr valign="top">
  172. <th scope="row" class="titledesc">
  173. <?php esc_html_e( 'Updated at', 'woocommerce' ); ?>
  174. </th>
  175. <td class="forminp">
  176. <?php echo esc_html( date_i18n( __( 'M j, Y @ G:i', 'woocommerce' ), strtotime( $webhook->get_date_modified()->date( 'Y-m-d H:i:s' ) ) ) ); ?>
  177. </td>
  178. </tr>
  179. <?php endif; ?>
  180. <?php endif; ?>
  181. <tr valign="top">
  182. <td colspan="2" scope="row" style="padding-left: 0;">
  183. <p class="submit">
  184. <button type="submit" class="button button-primary button-large" name="save" id="publish" accesskey="p"><?php esc_html_e( 'Save webhook', 'woocommerce' ); ?></button>
  185. <?php
  186. if ( $webhook->get_id() ) :
  187. $delete_url = wp_nonce_url(
  188. add_query_arg(
  189. array(
  190. 'delete' => $webhook->get_id(),
  191. ),
  192. admin_url( 'admin.php?page=wc-settings&tab=advanced&section=webhooks' )
  193. ),
  194. 'delete-webhook'
  195. );
  196. ?>
  197. <a style="color: #a00; text-decoration: none; margin-left: 10px;" href="<?php echo esc_url( $delete_url ); ?>"><?php esc_html_e( 'Delete permanently', 'woocommerce' ); ?></a>
  198. <?php endif; ?>
  199. </p>
  200. </td>
  201. </tr>
  202. </tbody>
  203. </table>
  204. </div>
  205. <script type="text/javascript">
  206. jQuery( function ( $ ) {
  207. $( '#webhook-options' ).find( '#webhook_topic' ).on( 'change', function() {
  208. var current = $( this ).val(),
  209. action_event_field = $( '#webhook-options' ).find( '#webhook-action-event-wrap' );
  210. action_event_field.hide();
  211. if ( 'action' === current ) {
  212. action_event_field.show();
  213. }
  214. }).trigger( 'change' );
  215. });
  216. </script>