/includes/admin/settings/views/html-webhooks-edit.php

  1. <?php 
  2. if ( ! defined( 'ABSPATH' ) ) { 
  3. exit; 
  4. ?> 
  5.  
  6. <input type="hidden" name="webhook_id" value="<?php echo esc_attr( $webhook->id ); ?>" /> 
  7.  
  8. <div id="webhook-options" class="settings-panel"> 
  9. <h2><?php _e( 'Webhook data', 'woocommerce' ); ?></h2> 
  10. <table class="form-table"> 
  11. <tbody> 
  12. <tr valign="top"> 
  13. <th scope="row" class="titledesc"> 
  14. <label for="webhook_name"><?php _e( 'Name', 'woocommerce' ); ?></label> 
  15. <?php 
  16. // @codingStandardsIgnoreStart 
  17. 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' ) ) ) ); 
  18. // @codingStandardsIgnoreEnd 
  19. ?> 
  20. </th> 
  21. <td class="forminp"> 
  22. <input name="webhook_name" id="webhook_name" type="text" class="input-text regular-input" value="<?php echo esc_attr( $webhook->get_name() ); ?>" /> 
  23. </td> 
  24. </tr> 
  25. <tr valign="top"> 
  26. <th scope="row" class="titledesc"> 
  27. <label for="webhook_status"><?php _e( 'Status', 'woocommerce' ); ?></label> 
  28. <?php wc_help_tip( __( 'The options are "Active" (delivers payload), "Paused" (does not deliver), or "Disabled" (does not deliver due delivery failures).', 'woocommerce' ) ); ?> 
  29. </th> 
  30. <td class="forminp"> 
  31. <select name="webhook_status" id="webhook_status" class="wc-enhanced-select"> 
  32. <?php 
  33. $statuses = wc_get_webhook_statuses(); 
  34. $current_status = $webhook->get_status(); 
  35.  
  36. foreach ( $statuses as $status_slug => $status_name ) : ?> 
  37. <option value="<?php echo esc_attr( $status_slug ); ?>" <?php selected( $current_status, $status_slug, true ); ?>><?php echo esc_html( $status_name ); ?></option> 
  38. <?php endforeach; ?> 
  39. </select> 
  40. </td> 
  41. </tr> 
  42. <tr valign="top"> 
  43. <th scope="row" class="titledesc"> 
  44. <label for="webhook_topic"><?php _e( 'Topic', 'woocommerce' ); ?></label> 
  45. <?php echo wc_help_tip( __( 'Select when the webhook will fire.', 'woocommerce' ) ); ?> 
  46. </th> 
  47. <td class="forminp"> 
  48. <select name="webhook_topic" id="webhook_topic" class="wc-enhanced-select"> 
  49. <?php 
  50. $topic_data = WC_Admin_Webhooks::get_topic_data( $webhook ); 
  51.  
  52. $topics = apply_filters( 'woocommerce_webhook_topics', array( 
  53. '' => __( 'Select an option…', 'woocommerce' ),  
  54. 'coupon.created' => __( 'Coupon created', 'woocommerce' ),  
  55. 'coupon.updated' => __( 'Coupon updated', 'woocommerce' ),  
  56. 'coupon.deleted' => __( 'Coupon deleted', 'woocommerce' ),  
  57. 'customer.created' => __( 'Customer created', 'woocommerce' ),  
  58. 'customer.updated' => __( 'Customer updated', 'woocommerce' ),  
  59. 'customer.deleted' => __( 'Customer deleted', 'woocommerce' ),  
  60. 'order.created' => __( 'Order created', 'woocommerce' ),  
  61. 'order.updated' => __( 'Order updated', 'woocommerce' ),  
  62. 'order.deleted' => __( 'Order deleted', 'woocommerce' ),  
  63. 'product.created' => __( 'Product created', 'woocommerce' ),  
  64. 'product.updated' => __( 'Product updated', 'woocommerce' ),  
  65. 'product.deleted' => __( 'Product deleted', 'woocommerce' ),  
  66. 'action' => __( 'Action', 'woocommerce' ),  
  67. 'custom' => __( 'Custom', 'woocommerce' ),  
  68. ) ); 
  69.  
  70. foreach ( $topics as $topic_slug => $topic_name ) : ?> 
  71. <option value="<?php echo esc_attr( $topic_slug ); ?>" <?php selected( $topic_data['topic'], $topic_slug, true ); ?>><?php echo esc_html( $topic_name ); ?></option> 
  72. <?php endforeach; ?> 
  73. </select> 
  74. </td> 
  75. </tr> 
  76. <tr valign="top" id="webhook-action-event-wrap"> 
  77. <th scope="row" class="titledesc"> 
  78. <label for="webhook_action_event"><?php _e( 'Action event', 'woocommerce' ); ?></label> 
  79. <?php echo wc_help_tip( __( 'Enter the action that will trigger this webhook.', 'woocommerce' ) ); ?> 
  80. </th> 
  81. <td class="forminp"> 
  82. <input name="webhook_action_event" id="webhook_action_event" type="text" class="input-text regular-input" value="<?php echo esc_attr( $topic_data['event'] ); ?>" /> 
  83. </td> 
  84. </tr> 
  85. <tr valign="top" id="webhook-custom-topic-wrap"> 
  86. <th scope="row" class="titledesc"> 
  87. <label for="webhook_custom_topic"><?php _e( 'Custom topic', 'woocommerce' ); ?></label> 
  88. <?php echo wc_help_tip( __( 'Enter the custom topic that will trigger this webhook.', 'woocommerce' ) ); ?> 
  89. </th> 
  90. <td class="forminp"> 
  91. <input name="webhook_custom_topic" id="webhook_custom_topic" type="text" class="input-text regular-input" value="<?php echo esc_attr( $webhook->get_topic() ); ?>" /> 
  92. </td> 
  93. </tr> 
  94. <tr valign="top"> 
  95. <th scope="row" class="titledesc"> 
  96. <label for="webhook_delivery_url"><?php _e( 'Delivery URL', 'woocommerce' ); ?></label> 
  97. <?php echo wc_help_tip( __( 'URL where the webhook payload is delivered.', 'woocommerce' ) ); ?> 
  98. </th> 
  99. <td class="forminp"> 
  100. <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() ); ?>" /> 
  101. </td> 
  102. </tr> 
  103. <tr valign="top"> 
  104. <th scope="row" class="titledesc"> 
  105. <label for="webhook_secret"><?php _e( 'Secret', 'woocommerce' ); ?></label> 
  106. <?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' ) ); ?> 
  107. </th> 
  108. <td class="forminp"> 
  109. <input name="webhook_secret" id="webhook_secret" type="text" class="input-text regular-input" value="<?php echo esc_attr( $webhook->get_secret() ); ?>" /> 
  110. </td> 
  111. </tr> 
  112. <tr valign="top"> 
  113. <th scope="row" class="titledesc"> 
  114. <label for="webhook_api_version"><?php _e( 'API Version', 'woocommerce' ); ?></label> 
  115. <?php echo wc_help_tip( __( 'REST API version used in the webhook deliveries.', 'woocommerce' ) ); ?> 
  116. </th> 
  117. <td class="forminp"> 
  118. <select name="webhook_api_version" id="webhook_api_version"> 
  119. <option value="wp_api_v2" <?php selected( 'wp_api_v2', $webhook->get_api_version(), true ); ?>><?php _e( 'WP REST API Integration v2', 'woocommerce' ); ?></option> 
  120. <option value="wp_api_v1" <?php selected( 'wp_api_v1', $webhook->get_api_version(), true ); ?>><?php _e( 'WP REST API Integration v1', 'woocommerce' ); ?></option> 
  121. <option value="legacy_v3" <?php selected( 'legacy_v3', $webhook->get_api_version(), true ); ?>><?php _e( 'Legacy API v3 (deprecated)', 'woocommerce' ); ?></option> 
  122. </select> 
  123. </td> 
  124. </tr> 
  125. </tbody> 
  126. </table> 
  127.  
  128. <?php do_action( 'woocommerce_webhook_options' ); ?> 
  129. </div> 
  130.  
  131. <div id="webhook-actions" class="settings-panel"> 
  132. <h2><?php _e( 'Webhook actions', 'woocommerce' ); ?></h2> 
  133. <table class="form-table"> 
  134. <tbody> 
  135. <?php if ( '0000-00-00 00:00:00' != $webhook->post_data->post_modified_gmt ) : ?> 
  136. <?php if ( '0000-00-00 00:00:00' == $webhook->post_data->post_date_gmt ) : ?> 
  137. <tr valign="top"> 
  138. <th scope="row" class="titledesc"> 
  139. <?php _e( 'Created at', 'woocommerce' ); ?> 
  140. </th> 
  141. <td class="forminp"> 
  142. <?php echo date_i18n( __( 'M j, Y @ G:i', 'woocommerce' ), strtotime( $webhook->post_data->post_modified_gmt ) ); ?> 
  143. </td> 
  144. </tr> 
  145. <?php else : ?> 
  146. <tr valign="top"> 
  147. <th scope="row" class="titledesc"> 
  148. <?php _e( 'Created at', 'woocommerce' ); ?> 
  149. </th> 
  150. <td class="forminp"> 
  151. <?php echo date_i18n( __( 'M j, Y @ G:i', 'woocommerce' ), strtotime( $webhook->post_data->post_date_gmt ) ); ?> 
  152. </td> 
  153. </tr> 
  154. <tr valign="top"> 
  155. <th scope="row" class="titledesc"> 
  156. <?php _e( 'Updated at', 'woocommerce' ); ?> 
  157. </th> 
  158. <td class="forminp"> 
  159. <?php echo date_i18n( __( 'M j, Y @ G:i', 'woocommerce' ), strtotime( $webhook->post_data->post_modified_gmt ) ); ?> 
  160. </td> 
  161. </tr> 
  162. <?php endif; ?> 
  163. <?php endif; ?> 
  164. <tr valign="top"> 
  165. <td colspan="2" scope="row" style="padding-left: 0;"> 
  166. <p class="submit"> 
  167. <input type="submit" class="button button-primary button-large" name="save" id="publish" accesskey="p" value="<?php esc_attr_e( 'Save webhook', 'woocommerce' ); ?>" /> 
  168. <?php if ( current_user_can( 'delete_post', $webhook->id ) ) : ?> 
  169. <a style="color: #a00; text-decoration: none; margin-left: 10px;" href="<?php echo esc_url( get_delete_post_link( $webhook->id ) ); ?>"><?php echo ( ! EMPTY_TRASH_DAYS ) ? __( 'Delete permanently', 'woocommerce' ) : __( 'Move to trash', 'woocommerce' ); ?></a> 
  170. <?php endif; ?> 
  171. </p> 
  172. </td> 
  173. </tr> 
  174. </tbody> 
  175. </table> 
  176. </div> 
  177.  
  178. <div id="webhook-logs" class="settings-panel"> 
  179. <h2><?php _e( 'Webhook logs', 'woocommerce' ); ?></h2> 
  180.  
  181. <?php WC_Admin_Webhooks::logs_output( $webhook ); ?> 
  182. </div> 
  183.  
  184. <script type="text/javascript"> 
  185. jQuery( function ( $ ) { 
  186. $( '#webhook-options' ).find( '#webhook_topic' ).on( 'change', function() { 
  187. var current = $( this ).val(),  
  188. action_event_field = $( '#webhook-options' ).find( '#webhook-action-event-wrap' ),  
  189. custom_topic_field = $( '#webhook-options' ).find( '#webhook-custom-topic-wrap' ); 
  190.  
  191. action_event_field.hide(); 
  192. custom_topic_field.hide(); 
  193.  
  194. if ( 'action' === current ) { 
  195. action_event_field.show(); 
  196. } else if ( 'custom' === current ) { 
  197. custom_topic_field.show(); 
  198. }).change(); 
  199. }); 
  200. </script> 
.