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