html-webhooks-edit.php 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  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', array(
  62. '' => __( 'Select an option&hellip;', 'woocommerce' ),
  63. 'coupon.created' => __( 'Coupon created', 'woocommerce' ),
  64. 'coupon.updated' => __( 'Coupon updated', 'woocommerce' ),
  65. 'coupon.deleted' => __( 'Coupon deleted', 'woocommerce' ),
  66. 'coupon.restored' => __( 'Coupon restored', 'woocommerce' ),
  67. 'customer.created' => __( 'Customer created', 'woocommerce' ),
  68. 'customer.updated' => __( 'Customer updated', 'woocommerce' ),
  69. 'customer.deleted' => __( 'Customer deleted', 'woocommerce' ),
  70. 'order.created' => __( 'Order created', 'woocommerce' ),
  71. 'order.updated' => __( 'Order updated', 'woocommerce' ),
  72. 'order.deleted' => __( 'Order deleted', 'woocommerce' ),
  73. 'order.restored' => __( 'Order restored', 'woocommerce' ),
  74. 'product.created' => __( 'Product created', 'woocommerce' ),
  75. 'product.updated' => __( 'Product updated', 'woocommerce' ),
  76. 'product.deleted' => __( 'Product deleted', 'woocommerce' ),
  77. 'product.restored' => __( 'Product restored', 'woocommerce' ),
  78. 'action' => __( 'Action', 'woocommerce' ),
  79. )
  80. );
  81. foreach ( $topics as $topic_slug => $topic_name ) :
  82. $selected = $topic_slug === $topic_data['topic'] || $topic_slug === $topic_data['resource'] . '.' . $topic_data['event'];
  83. ?>
  84. <option value="<?php echo esc_attr( $topic_slug ); ?>" <?php selected( $selected, true, true ); ?>><?php echo esc_html( $topic_name ); ?></option>
  85. <?php endforeach; ?>
  86. </select>
  87. </td>
  88. </tr>
  89. <tr valign="top" id="webhook-action-event-wrap">
  90. <th scope="row" class="titledesc">
  91. <label for="webhook_action_event">
  92. <?php esc_html_e( 'Action event', 'woocommerce' ); ?>
  93. <?php echo wc_help_tip( __( 'Enter the action that will trigger this webhook.', 'woocommerce' ) ); ?>
  94. </label>
  95. </th>
  96. <td class="forminp">
  97. <input name="webhook_action_event" id="webhook_action_event" type="text" class="input-text regular-input" value="<?php echo esc_attr( $topic_data['event'] ); ?>" />
  98. </td>
  99. </tr>
  100. <tr valign="top">
  101. <th scope="row" class="titledesc">
  102. <label for="webhook_delivery_url">
  103. <?php esc_html_e( 'Delivery URL', 'woocommerce' ); ?>
  104. <?php echo wc_help_tip( __( 'URL where the webhook payload is delivered.', 'woocommerce' ) ); ?>
  105. </label>
  106. </th>
  107. <td class="forminp">
  108. <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() ); ?>" />
  109. </td>
  110. </tr>
  111. <tr valign="top">
  112. <th scope="row" class="titledesc">
  113. <label for="webhook_secret">
  114. <?php esc_html_e( 'Secret', 'woocommerce' ); ?>
  115. <?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' ) ); ?>
  116. </label>
  117. </th>
  118. <td class="forminp">
  119. <input name="webhook_secret" id="webhook_secret" type="text" class="input-text regular-input" value="<?php echo esc_attr( $webhook->get_secret() ); ?>" />
  120. </td>
  121. </tr>
  122. <tr valign="top">
  123. <th scope="row" class="titledesc">
  124. <label for="webhook_api_version">
  125. <?php esc_html_e( 'API Version', 'woocommerce' ); ?>
  126. <?php echo wc_help_tip( __( 'REST API version used in the webhook deliveries.', 'woocommerce' ) ); ?>
  127. </label>
  128. </th>
  129. <td class="forminp">
  130. <select name="webhook_api_version" id="webhook_api_version">
  131. <option value="wp_api_v2" <?php selected( 'wp_api_v2', $webhook->get_api_version(), true ); ?>><?php esc_html_e( 'WP REST API Integration v2', 'woocommerce' ); ?></option>
  132. <option value="wp_api_v1" <?php selected( 'wp_api_v1', $webhook->get_api_version(), true ); ?>><?php esc_html_e( 'WP REST API Integration v1', 'woocommerce' ); ?></option>
  133. <option value="legacy_v3" <?php selected( 'legacy_v3', $webhook->get_api_version(), true ); ?>><?php esc_html_e( 'Legacy API v3 (deprecated)', 'woocommerce' ); ?></option>
  134. </select>
  135. </td>
  136. </tr>
  137. </tbody>
  138. </table>
  139. <?php do_action( 'woocommerce_webhook_options' ); ?>
  140. </div>
  141. <div id="webhook-actions" class="settings-panel">
  142. <h2><?php esc_html_e( 'Webhook actions', 'woocommerce' ); ?></h2>
  143. <table class="form-table">
  144. <tbody>
  145. <?php if ( $webhook->get_date_created() && '0000-00-00 00:00:00' !== $webhook->get_date_created()->date( 'Y-m-d H:i:s' ) ) : ?>
  146. <?php if ( is_null( $webhook->get_date_modified() ) ) : ?>
  147. <tr valign="top">
  148. <th scope="row" class="titledesc">
  149. <?php esc_html_e( 'Created at', 'woocommerce' ); ?>
  150. </th>
  151. <td class="forminp">
  152. <?php echo esc_html( date_i18n( __( 'M j, Y @ G:i', 'woocommerce' ), strtotime( $webhook->get_date_created()->date( 'Y-m-d H:i:s' ) ) ) ); ?>
  153. </td>
  154. </tr>
  155. <?php else : ?>
  156. <tr valign="top">
  157. <th scope="row" class="titledesc">
  158. <?php esc_html_e( 'Created at', 'woocommerce' ); ?>
  159. </th>
  160. <td class="forminp">
  161. <?php echo esc_html( date_i18n( __( 'M j, Y @ G:i', 'woocommerce' ), strtotime( $webhook->get_date_created()->date( 'Y-m-d H:i:s' ) ) ) ); ?>
  162. </td>
  163. </tr>
  164. <tr valign="top">
  165. <th scope="row" class="titledesc">
  166. <?php esc_html_e( 'Updated at', 'woocommerce' ); ?>
  167. </th>
  168. <td class="forminp">
  169. <?php echo esc_html( date_i18n( __( 'M j, Y @ G:i', 'woocommerce' ), strtotime( $webhook->get_date_modified()->date( 'Y-m-d H:i:s' ) ) ) ); ?>
  170. </td>
  171. </tr>
  172. <?php endif; ?>
  173. <?php endif; ?>
  174. <tr valign="top">
  175. <td colspan="2" scope="row" style="padding-left: 0;">
  176. <p class="submit">
  177. <button type="submit" class="button button-primary button-large" name="save" id="publish" accesskey="p"><?php esc_html_e( 'Save webhook', 'woocommerce' ); ?></button>
  178. <?php
  179. if ( $webhook->get_id() ) :
  180. $delete_url = wp_nonce_url(
  181. add_query_arg(
  182. array(
  183. 'delete' => $webhook->get_id(),
  184. ), admin_url( 'admin.php?page=wc-settings&tab=advanced&section=webhooks' )
  185. ), 'delete-webhook'
  186. );
  187. ?>
  188. <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>
  189. <?php endif; ?>
  190. </p>
  191. </td>
  192. </tr>
  193. </tbody>
  194. </table>
  195. </div>
  196. <script type="text/javascript">
  197. jQuery( function ( $ ) {
  198. $( '#webhook-options' ).find( '#webhook_topic' ).on( 'change', function() {
  199. var current = $( this ).val(),
  200. action_event_field = $( '#webhook-options' ).find( '#webhook-action-event-wrap' );
  201. action_event_field.hide();
  202. if ( 'action' === current ) {
  203. action_event_field.show();
  204. }
  205. }).change();
  206. });
  207. </script>