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

227 lines
9.3 KiB
PHP
Raw Normal View History

2015-01-08 18:34:30 +00:00
<?php
/**
* Admin View: Edit Webhooks
*
2020-08-05 16:36:24 +00:00
* @package WooCommerce\Admin\Webhooks\Views
*/
2015-01-08 18:34:30 +00:00
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
?>
<input type="hidden" name="webhook_id" value="<?php echo esc_attr( $webhook->get_id() ); ?>" />
2015-01-08 18:34:30 +00:00
<div id="webhook-options" class="settings-panel">
<h2><?php esc_html_e( 'Webhook data', 'woocommerce' ); ?></h2>
2015-01-08 18:34:30 +00:00
<table class="form-table">
<tbody>
<tr valign="top">
<th scope="row" class="titledesc">
2018-04-17 11:19:01 +00:00
<label for="webhook_name">
<?php esc_html_e( 'Name', 'woocommerce' ); ?>
<?php
/* translators: %s: date */
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
?>
</label>
2015-01-08 18:34:30 +00:00
</th>
<td class="forminp">
<input name="webhook_name" id="webhook_name" type="text" class="input-text regular-input" value="<?php echo esc_attr( $webhook->get_name() ); ?>" />
</td>
</tr>
<tr valign="top">
<th scope="row" class="titledesc">
2018-04-17 11:19:01 +00:00
<label for="webhook_status">
<?php esc_html_e( 'Status', 'woocommerce' ); ?>
<?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' ) ); ?>
</label>
2015-01-08 18:34:30 +00:00
</th>
<td class="forminp">
<select name="webhook_status" id="webhook_status" class="wc-enhanced-select">
2015-01-08 18:34:30 +00:00
<?php
$statuses = wc_get_webhook_statuses();
$current_status = $webhook->get_status();
2015-01-08 18:34:30 +00:00
foreach ( $statuses as $status_slug => $status_name ) :
?>
2015-01-08 18:34:30 +00:00
<option value="<?php echo esc_attr( $status_slug ); ?>" <?php selected( $current_status, $status_slug, true ); ?>><?php echo esc_html( $status_name ); ?></option>
<?php endforeach; ?>
</select>
</td>
</tr>
<tr valign="top">
<th scope="row" class="titledesc">
2018-04-17 11:19:01 +00:00
<label for="webhook_topic">
<?php esc_html_e( 'Topic', 'woocommerce' ); ?>
<?php echo wc_help_tip( __( 'Select when the webhook will fire.', 'woocommerce' ) ); ?>
</label>
2015-01-08 18:34:30 +00:00
</th>
<td class="forminp">
<select name="webhook_topic" id="webhook_topic" class="wc-enhanced-select">
2015-01-08 18:34:30 +00:00
<?php
$topic_data = WC_Admin_Webhooks::get_topic_data( $webhook );
2015-01-08 18:34:30 +00:00
$topics = apply_filters(
'woocommerce_webhook_topics', array(
'' => __( 'Select an option&hellip;', 'woocommerce' ),
'coupon.created' => __( 'Coupon created', 'woocommerce' ),
'coupon.updated' => __( 'Coupon updated', 'woocommerce' ),
'coupon.deleted' => __( 'Coupon deleted', 'woocommerce' ),
'coupon.restored' => __( 'Coupon restored', 'woocommerce' ),
'customer.created' => __( 'Customer created', 'woocommerce' ),
'customer.updated' => __( 'Customer updated', 'woocommerce' ),
'customer.deleted' => __( 'Customer deleted', 'woocommerce' ),
'order.created' => __( 'Order created', 'woocommerce' ),
'order.updated' => __( 'Order updated', 'woocommerce' ),
'order.deleted' => __( 'Order deleted', 'woocommerce' ),
'order.restored' => __( 'Order restored', 'woocommerce' ),
'product.created' => __( 'Product created', 'woocommerce' ),
'product.updated' => __( 'Product updated', 'woocommerce' ),
'product.deleted' => __( 'Product deleted', 'woocommerce' ),
'product.restored' => __( 'Product restored', 'woocommerce' ),
'action' => __( 'Action', 'woocommerce' ),
)
);
2015-01-08 18:34:30 +00:00
foreach ( $topics as $topic_slug => $topic_name ) :
2018-06-07 14:33:13 +00:00
2018-06-08 15:08:20 +00:00
$selected = $topic_slug === $topic_data['topic'] || $topic_slug === $topic_data['resource'] . '.' . $topic_data['event'];
2018-06-07 14:33:13 +00:00
2018-06-08 15:08:20 +00:00
?>
2018-06-08 15:07:20 +00:00
<option value="<?php echo esc_attr( $topic_slug ); ?>" <?php selected( $selected, true, true ); ?>><?php echo esc_html( $topic_name ); ?></option>
2015-01-08 18:34:30 +00:00
<?php endforeach; ?>
</select>
</td>
</tr>
<tr valign="top" id="webhook-action-event-wrap">
<th scope="row" class="titledesc">
2018-04-17 11:19:01 +00:00
<label for="webhook_action_event">
<?php esc_html_e( 'Action event', 'woocommerce' ); ?>
<?php echo wc_help_tip( __( 'Enter the action that will trigger this webhook.', 'woocommerce' ) ); ?>
</label>
2015-01-08 18:34:30 +00:00
</th>
<td class="forminp">
<input name="webhook_action_event" id="webhook_action_event" type="text" class="input-text regular-input" value="<?php echo esc_attr( $topic_data['event'] ); ?>" />
</td>
</tr>
<tr valign="top">
<th scope="row" class="titledesc">
2018-04-17 11:19:01 +00:00
<label for="webhook_delivery_url">
<?php esc_html_e( 'Delivery URL', 'woocommerce' ); ?>
<?php echo wc_help_tip( __( 'URL where the webhook payload is delivered.', 'woocommerce' ) ); ?>
</label>
2015-01-08 18:34:30 +00:00
</th>
<td class="forminp">
<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() ); ?>" />
</td>
</tr>
<tr valign="top">
<th scope="row" class="titledesc">
2018-04-17 11:19:01 +00:00
<label for="webhook_secret">
<?php esc_html_e( 'Secret', 'woocommerce' ); ?>
<?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' ) ); ?>
</label>
2015-01-08 18:34:30 +00:00
</th>
<td class="forminp">
<input name="webhook_secret" id="webhook_secret" type="text" class="input-text regular-input" value="<?php echo esc_attr( $webhook->get_secret() ); ?>" />
</td>
</tr>
2016-11-22 23:58:36 +00:00
<tr valign="top">
<th scope="row" class="titledesc">
2018-04-17 11:19:01 +00:00
<label for="webhook_api_version">
<?php esc_html_e( 'API Version', 'woocommerce' ); ?>
<?php echo wc_help_tip( __( 'REST API version used in the webhook deliveries.', 'woocommerce' ) ); ?>
</label>
2016-11-22 23:58:36 +00:00
</th>
<td class="forminp">
<select name="webhook_api_version" id="webhook_api_version">
<?php foreach ( array_reverse( wc_get_webhook_rest_api_versions() ) as $version ) : ?>
<option value="<?php echo esc_attr( $version ); ?>" <?php selected( $version, $webhook->get_api_version(), true ); ?>>
<?php
/* translators: %d: rest api version number */
echo esc_html( sprintf( __( 'WP REST API Integration v%d', 'woocommerce' ), str_replace( 'wp_api_v', '', $version ) ) );
?>
</option>
<?php endforeach; ?>
<option value="legacy_v3" <?php selected( 'legacy_v3', $webhook->get_api_version(), true ); ?>><?php esc_html_e( 'Legacy API v3 (deprecated)', 'woocommerce' ); ?></option>
2016-11-22 23:58:36 +00:00
</select>
</td>
</tr>
2015-01-08 18:34:30 +00:00
</tbody>
</table>
<?php do_action( 'woocommerce_webhook_options' ); ?>
</div>
2015-01-09 17:42:01 +00:00
<div id="webhook-actions" class="settings-panel">
<h2><?php esc_html_e( 'Webhook actions', 'woocommerce' ); ?></h2>
2015-01-08 18:34:30 +00:00
<table class="form-table">
<tbody>
<?php if ( $webhook->get_date_created() && '0000-00-00 00:00:00' !== $webhook->get_date_created()->date( 'Y-m-d H:i:s' ) ) : ?>
2017-11-10 14:37:49 +00:00
<?php if ( is_null( $webhook->get_date_modified() ) ) : ?>
2015-01-08 18:34:30 +00:00
<tr valign="top">
<th scope="row" class="titledesc">
<?php esc_html_e( 'Created at', 'woocommerce' ); ?>
2015-01-08 18:34:30 +00:00
</th>
<td class="forminp">
<?php echo esc_html( date_i18n( __( 'M j, Y @ G:i', 'woocommerce' ), strtotime( $webhook->get_date_created()->date( 'Y-m-d H:i:s' ) ) ) ); ?>
2015-01-08 18:34:30 +00:00
</td>
</tr>
<?php else : ?>
<tr valign="top">
<th scope="row" class="titledesc">
<?php esc_html_e( 'Created at', 'woocommerce' ); ?>
2015-01-08 18:34:30 +00:00
</th>
<td class="forminp">
<?php echo esc_html( date_i18n( __( 'M j, Y @ G:i', 'woocommerce' ), strtotime( $webhook->get_date_created()->date( 'Y-m-d H:i:s' ) ) ) ); ?>
2015-01-08 18:34:30 +00:00
</td>
</tr>
<tr valign="top">
<th scope="row" class="titledesc">
<?php esc_html_e( 'Updated at', 'woocommerce' ); ?>
2015-01-08 18:34:30 +00:00
</th>
<td class="forminp">
<?php echo esc_html( date_i18n( __( 'M j, Y @ G:i', 'woocommerce' ), strtotime( $webhook->get_date_modified()->date( 'Y-m-d H:i:s' ) ) ) ); ?>
2015-01-08 18:34:30 +00:00
</td>
</tr>
<?php endif; ?>
<?php endif; ?>
2015-01-09 17:42:01 +00:00
<tr valign="top">
<td colspan="2" scope="row" style="padding-left: 0;">
<p class="submit">
<button type="submit" class="button button-primary button-large" name="save" id="publish" accesskey="p"><?php esc_html_e( 'Save webhook', 'woocommerce' ); ?></button>
<?php
if ( $webhook->get_id() ) :
$delete_url = wp_nonce_url(
add_query_arg(
array(
'delete' => $webhook->get_id(),
), admin_url( 'admin.php?page=wc-settings&tab=advanced&section=webhooks' )
), 'delete-webhook'
);
?>
<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>
<?php endif; ?>
2015-01-09 17:42:01 +00:00
</p>
</td>
</tr>
2015-01-08 18:34:30 +00:00
</tbody>
</table>
</div>
<script type="text/javascript">
jQuery( function ( $ ) {
$( '#webhook-options' ).find( '#webhook_topic' ).on( 'change', function() {
2015-01-08 18:34:30 +00:00
var current = $( this ).val(),
action_event_field = $( '#webhook-options' ).find( '#webhook-action-event-wrap' );
2015-01-08 18:34:30 +00:00
action_event_field.hide();
if ( 'action' === current ) {
action_event_field.show();
}
}).trigger( 'change' );
2015-01-08 18:34:30 +00:00
});
</script>