Merge pull request #7074 from woothemes/webhooks-settings-tab

New Webhooks UI in Settings Menu, closes #6912
This commit is contained in:
Claudio Sanches 2015-01-12 16:04:07 -02:00
commit d290be0749
22 changed files with 1042 additions and 367 deletions

View File

@ -1,16 +0,0 @@
jQuery( function ( $ ) {
$( '#webhook-options #topic' ).on( 'change', function() {
var current = $( this ).val(),
action_event_field = $( '#webhook-options .action_event_field' ),
custom_topic_field = $( '#webhook-options .custom_topic_field' );
action_event_field.hide();
custom_topic_field.hide();
if ( 'action' === current ) {
action_event_field.show();
} else if ( 'custom' === current ) {
custom_topic_field.show();
}
}).change();
});

View File

@ -1 +0,0 @@
jQuery(function(a){a("#webhook-options #topic").on("change",function(){var b=a(this).val(),c=a("#webhook-options .action_event_field"),d=a("#webhook-options .custom_topic_field");c.hide(),d.hide(),"action"===b?c.show():"custom"===b&&d.show()}).change()});

View File

@ -195,9 +195,6 @@ class WC_Admin_Assets {
if ( in_array( $screen->id, array( 'shop_coupon', 'edit-shop_coupon' ) ) ) {
wp_enqueue_script( 'wc-admin-coupon-meta-boxes', WC()->plugin_url() . '/assets/js/admin/meta-boxes-coupon' . $suffix . '.js', array( 'wc-admin-meta-boxes' ), WC_VERSION );
}
if ( 'shop_webhook' == $screen->id ) {
wp_enqueue_script( 'wc-admin-webhook-meta-boxes', WC()->plugin_url() . '/assets/js/admin/meta-boxes-webhook' . $suffix . '.js', array( 'jquery' ), WC_VERSION, true );
}
if ( in_array( str_replace( 'edit-', '', $screen->id ), array_merge( array( 'shop_coupon', 'product' ), wc_get_order_types( 'order-meta-boxes' ) ) ) ) {
$params = array(
'remove_item_notice' => __( 'Are you sure you want to remove the selected items? If you have previously reduced this item\'s stock, or this order was submitted by a customer, you will need to manually restore the item\'s stock.', 'woocommerce' ),

View File

@ -27,7 +27,6 @@ class WC_Admin_Menus {
add_action( 'admin_menu', array( $this, 'admin_menu' ), 9 );
add_action( 'admin_menu', array( $this, 'reports_menu' ), 20 );
add_action( 'admin_menu', array( $this, 'settings_menu' ), 50 );
add_action( 'admin_menu', array( $this, 'webhooks_menu' ), 55 );
add_action( 'admin_menu', array( $this, 'status_menu' ), 60 );
if ( apply_filters( 'woocommerce_show_addons_page', true ) ) {
@ -75,15 +74,6 @@ class WC_Admin_Menus {
add_action( 'load-' . $settings_page, array( $this, 'settings_page_init' ) );
}
/**
* Add webhook item
*/
public function webhooks_menu() {
if ( apply_filters( 'woocommerce_show_webhooks_menu', 'yes' == get_option( 'woocommerce_api_enabled' ) ) ) {
add_submenu_page( 'woocommerce', __( 'Webhooks', 'woocommerce' ), __( 'Webhooks', 'woocommerce' ), 'manage_woocommerce', 'edit.php?post_type=shop_webhook' );
}
}
/**
* Loads gateways and shipping methods into memory for use within settings.
*/
@ -113,7 +103,7 @@ class WC_Admin_Menus {
public function menu_highlight() {
global $menu, $submenu, $parent_file, $submenu_file, $self, $post_type, $taxonomy;
$to_highlight_types = array( 'shop_order', 'shop_coupon', 'shop_webhook' );
$to_highlight_types = array( 'shop_order', 'shop_coupon' );
if ( isset( $post_type ) ) {
if ( in_array( $post_type, $to_highlight_types ) ) {

View File

@ -55,9 +55,6 @@ class WC_Admin_Meta_Boxes {
// Save Rating Meta Boxes
add_action( 'comment_edit_redirect', 'WC_Meta_Box_Order_Reviews::save', 1, 2 );
// Save Webhook Meta Boxes
add_action( 'woocommerce_process_shop_webhook_meta', 'WC_Meta_Box_Webhook_Data::save', 10 );
// Error handling (for showing errors from meta boxes on next page load)
add_action( 'admin_notices', array( $this, 'output_errors' ) );
add_action( 'shutdown', array( $this, 'save_errors' ) );
@ -127,11 +124,6 @@ class WC_Admin_Meta_Boxes {
add_meta_box( 'woocommerce-rating', __( 'Rating', 'woocommerce' ), 'WC_Meta_Box_Order_Reviews::output', 'comment', 'normal', 'high' );
}
}
// Webhook
add_meta_box( 'woocommerce-webhook-data', __( 'Webhook Data', 'woocommerce' ), 'WC_Meta_Box_Webhook_Data::output', 'shop_webhook', 'normal', 'high' );
add_meta_box( 'woocommerce-webhook-actions', __( 'Webhook Actions', 'woocommerce' ), 'WC_Meta_Box_Webhook_Actions::output', 'shop_webhook', 'side', 'high' );
add_meta_box( 'woocommerce-webhook-logs', __( 'Webhook Logs', 'woocommerce' ), 'WC_Meta_Box_Webhook_Logs::output', 'shop_webhook', 'normal', 'low' );
}
/**
@ -146,9 +138,6 @@ class WC_Admin_Meta_Boxes {
remove_meta_box( 'woothemes-settings', 'shop_coupon' , 'normal' );
remove_meta_box( 'commentstatusdiv', 'shop_coupon' , 'normal' );
remove_meta_box( 'slugdiv', 'shop_coupon' , 'normal' );
remove_meta_box( 'submitdiv', 'shop_webhook' , 'side' );
remove_meta_box( 'slugdiv', 'shop_webhook' , 'normal' );
remove_meta_box( 'commentstatusdiv', 'shop_webhook' , 'normal' );
foreach ( wc_get_order_types( 'order-meta-boxes' ) as $type ) {
remove_meta_box( 'commentsdiv', $type, 'normal' );
@ -207,7 +196,7 @@ class WC_Admin_Meta_Boxes {
// Check the post type
if ( in_array( $post->post_type, wc_get_order_types( 'order-meta-boxes' ) ) ) {
do_action( 'woocommerce_process_shop_order_meta', $post_id, $post );
} elseif ( in_array( $post->post_type, array( 'product', 'shop_coupon', 'shop_webhook' ) ) ) {
} elseif ( in_array( $post->post_type, array( 'product', 'shop_coupon' ) ) ) {
do_action( 'woocommerce_process_' . $post->post_type . '_meta', $post_id, $post );
}
}

View File

@ -32,23 +32,19 @@ class WC_Admin_Post_Types {
add_filter( 'manage_edit-product_columns', array( $this, 'product_columns' ) );
add_filter( 'manage_edit-shop_coupon_columns', array( $this, 'shop_coupon_columns' ) );
add_filter( 'manage_edit-shop_order_columns', array( $this, 'shop_order_columns' ) );
add_filter( 'manage_edit-shop_webhook_columns', array( $this, 'shop_webhook_columns' ) );
add_action( 'manage_product_posts_custom_column', array( $this, 'render_product_columns' ), 2 );
add_action( 'manage_shop_coupon_posts_custom_column', array( $this, 'render_shop_coupon_columns' ), 2 );
add_action( 'manage_shop_order_posts_custom_column', array( $this, 'render_shop_order_columns' ), 2 );
add_action( 'manage_shop_webhook_posts_custom_column', array( $this, 'render_shop_webhook_columns' ), 2 );
add_filter( 'manage_edit-product_sortable_columns', array( $this, 'product_sortable_columns' ) );
add_filter( 'manage_edit-shop_coupon_sortable_columns', array( $this, 'shop_coupon_sortable_columns' ) );
add_filter( 'manage_edit-shop_order_sortable_columns', array( $this, 'shop_order_sortable_columns' ) );
add_filter( 'manage_edit-shop_webhook_sortable_columns', array( $this, 'shop_webhook_sortable_columns' ) );
add_filter( 'bulk_actions-edit-shop_order', array( $this, 'shop_order_bulk_actions' ) );
// Views
add_filter( 'views_edit-product', array( $this, 'product_sorting_link' ) );
add_filter( 'views_edit-shop_webhook', array( $this, 'shop_webhook_links' ) );
// Bulk / quick edit
add_action( 'bulk_edit_custom_box', array( $this, 'bulk_edit' ), 10, 2 );
@ -179,22 +175,6 @@ class WC_Admin_Post_Types {
return $columns;
}
/**
* Define custom columns for webhooks
* @param array $existing_columns
* @return array
*/
public function shop_webhook_columns( $existing_columns ) {
$columns = array();
$columns['cb'] = $existing_columns['cb'];
$columns['webhook_name'] = __( 'Name', 'woocommerce' );
$columns['webhook_status'] = __( 'Status', 'woocommerce' );
$columns['webhook_topic'] = __( 'Topic', 'woocommerce' );
$columns['webhook_delivery_url'] = __( 'Delivery URL', 'woocommerce' );
return $columns;
}
/**
* Ouput custom columns for products
* @param string $column
@ -689,75 +669,6 @@ class WC_Admin_Post_Types {
}
}
/**
* Output custom columns for webhooks
* @param string $column
*/
public function render_shop_webhook_columns( $column ) {
global $post, $the_webhook;
if ( empty( $the_webhook ) || $the_webhook->id != $post->ID ) {
$the_webhook = new WC_Webhook( $post->ID );
}
switch ( $column ) {
case 'webhook_name' :
$edit_link = get_edit_post_link( $the_webhook->id );
$title = _draft_or_post_title();
$post_type_object = get_post_type_object( $post->post_type );
echo '<strong><a href="' . esc_attr( $edit_link ) . '">' . esc_html( $title ) . '</a></strong>';
// Get actions
$actions = array();
if ( current_user_can( $post_type_object->cap->edit_post, $the_webhook->id ) ) {
$actions['edit'] = '<a href="' . admin_url( sprintf( $post_type_object->_edit_link . '&amp;action=edit', $the_webhook->id ) ) . '">' . __( 'Edit', 'woocommerce' ) . '</a>';
}
if ( current_user_can( $post_type_object->cap->delete_post, $the_webhook->id ) ) {
if ( 'trash' == $post->post_status ) {
$actions['untrash'] = "<a title='" . esc_attr( __( 'Restore this item from the Trash', 'woocommerce' ) ) . "' href='" . wp_nonce_url( admin_url( sprintf( $post_type_object->_edit_link . '&amp;action=untrash', $the_webhook->id ) ), 'untrash-post_' . $the_webhook->id ) . "'>" . __( 'Restore', 'woocommerce' ) . "</a>";
} elseif ( EMPTY_TRASH_DAYS ) {
$actions['trash'] = "<a class='submitdelete' title='" . esc_attr( __( 'Move this item to the Trash', 'woocommerce' ) ) . "' href='" . get_delete_post_link( $the_webhook->id ) . "'>" . __( 'Trash', 'woocommerce' ) . "</a>";
}
if ( 'trash' == $post->post_status || ! EMPTY_TRASH_DAYS ) {
$actions['delete'] = "<a class='submitdelete' title='" . esc_attr( __( 'Delete this item permanently', 'woocommerce' ) ) . "' href='" . get_delete_post_link( $the_webhook->id, '', true ) . "'>" . __( 'Delete Permanently', 'woocommerce' ) . "</a>";
}
}
$actions = apply_filters( 'post_row_actions', $actions, $post );
echo '<div class="row-actions">';
$i = 0;
$action_count = sizeof( $actions );
foreach ( $actions as $action => $link ) {
++$i;
( $i == $action_count ) ? $sep = '' : $sep = ' | ';
echo "<span class='$action'>$link$sep</span>";
}
echo '</div>';
break;
case 'webhook_status' :
echo $the_webhook->get_i18n_status();
break;
case 'webhook_topic' :
echo $the_webhook->get_topic();
break;
case 'webhook_delivery_url' :
echo $the_webhook->get_delivery_url();
break;
default :
break;
}
}
/**
* Make columns sortable - https://gist.github.com/906872
*
@ -801,20 +712,6 @@ class WC_Admin_Post_Types {
return wp_parse_args( $custom, $columns );
}
/**
* Make columns sortable - https://gist.github.com/906872
*
* @param array $columns
* @return array
*/
public function shop_webhook_sortable_columns( $columns ) {
$custom = array(
'webhook_name' => 'title'
);
return $custom;
}
/**
* Remove edit from the bulk actions.
*
@ -854,30 +751,6 @@ class WC_Admin_Post_Types {
return $views;
}
/**
* Webhooks links
*
* @param array $views
* @return array
*/
public function shop_webhook_links( $views ) {
$pattern = '/(shop_webhook\'>| class="current">)(.*?)(<span)/s';
if ( isset( $views['publish'] ) ) {
$views['publish'] = preg_replace( $pattern, '${1}' . __( 'Actived', 'woocommerce' ) . ' ${3}', $views['publish'] );
}
if ( isset( $views['draft'] ) ) {
$views['draft'] = preg_replace( $pattern, '${1}' . __( 'Paused', 'woocommerce' ) . ' ${3}', $views['draft'] );
}
if ( isset( $views['pending'] ) ) {
$views['pending'] = preg_replace( $pattern, '${1}' . __( 'Disabled', 'woocommerce' ) . ' ${3}', $views['pending'] );
}
return $views;
}
/**
* Custom bulk edit - form
*
@ -1848,20 +1721,6 @@ class WC_Admin_Post_Types {
10 => __( 'Coupon draft updated.', 'woocommerce' )
);
$messages['shop_webhook'] = array(
0 => '', // Unused. Messages start at index 1.
1 => __( 'Webhook saved.', 'woocommerce' ),
2 => __( 'Custom field updated.', 'woocommerce' ),
3 => __( 'Custom field deleted.', 'woocommerce' ),
4 => __( 'Webhook saved.', 'woocommerce' ),
5 => '',
6 => __( 'Webhook saved.', 'woocommerce' ),
7 => __( 'Webhook saved.', 'woocommerce' ),
8 => __( 'Webhook saved.', 'woocommerce' ),
9 => '',
10 => __( 'Webhook saved.', 'woocommerce' )
);
return $messages;
}

View File

@ -40,6 +40,7 @@ class WC_Admin_Settings {
$settings[] = include( 'settings/class-wc-settings-accounts.php' );
$settings[] = include( 'settings/class-wc-settings-emails.php' );
$settings[] = include( 'settings/class-wc-settings-integrations.php' );
$settings[] = include( 'settings/class-wc-settings-webhooks.php' );
self::$settings = apply_filters( 'woocommerce_get_settings_pages', $settings );
}

View File

@ -0,0 +1,307 @@
<?php
/**
* WooCommerce Webhooks Table List
*
* @author WooThemes
* @category Admin
* @package WooCommerce/Admin
* @version 2.3.0
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
if ( ! class_exists( 'WP_List_Table' ) ) {
require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
}
class WC_Admin_Webhooks_Table_List extends WP_List_Table {
/**
* Initialize the webhook table list
*/
public function __construct() {
parent::__construct( array(
'singular' => __( 'webhook', 'woocommerce' ),
'plural' => __( 'webhooks', 'woocommerce' ),
'ajax' => false
) );
}
/**
* Get list columns
*
* @return array
*/
public function get_columns() {
$columns = array(
'cb' => '<input type="checkbox" />',
'title' => __( 'Name', 'woocommerce' ),
'status' => __( 'Status', 'woocommerce' ),
'topic' => __( 'Topic', 'woocommerce' ),
'delivery_url' => __( 'Delivery URL', 'woocommerce' ),
);
return $columns;
}
/**
* Column cb.
*
* @param WC_Post $webhook
*
* @return string
*/
public function column_cb( $webhook ) {
return sprintf( '<input type="checkbox" name="%1$s[]" value="%2$s" />', $this->_args['singular'], $webhook->ID );
}
/**
* Webhook columns.
*
* @param WC_Post $webhook
* @param string $column_name
*
* @return string
*/
public function column_default( $webhook, $column_name ) {
global $the_webhook;
if ( empty( $the_webhook ) || $the_webhook->id != $webhook->ID ) {
$the_webhook = new WC_Webhook( $webhook->ID );
}
$output = '';
switch ( $column_name ) {
case 'title' :
$edit_link = admin_url( 'admin.php?page=wc-settings&amp;tab=webhooks&amp;edit-webhook=' . $the_webhook->id );
$title = _draft_or_post_title( $the_webhook->post_data );
$post_type_object = get_post_type_object( $the_webhook->post_data->post_type );
$post_status = $the_webhook->post_data->post_status;
// Title
$output = '<strong>';
if ( 'trash' == $post_status ) {
$output .= esc_html( $title );
} else {
$output .= '<a href="' . esc_attr( $edit_link ) . '">' . esc_html( $title ) . '</a>';
}
$output .= '</strong>';
// Get actions
$actions = array();
$actions['id'] = sprintf( __( 'ID: %d', 'woocommerce' ), $the_webhook->id );
if ( current_user_can( $post_type_object->cap->edit_post, $the_webhook->id ) && 'trash' !== $post_status ) {
$actions['edit'] = '<a href="' . esc_attr( $edit_link ) . '">' . __( 'Edit', 'woocommerce' ) . '</a>';
}
if ( current_user_can( $post_type_object->cap->delete_post, $the_webhook->id ) ) {
if ( 'trash' == $post_status ) {
$actions['untrash'] = '<a title="' . esc_attr( __( 'Restore this item from the Trash', 'woocommerce' ) ) . '" href="' . wp_nonce_url( admin_url( sprintf( $post_type_object->_edit_link . '&amp;action=untrash', $the_webhook->id ) ), 'untrash-post_' . $the_webhook->id ) . '">' . __( 'Restore', 'woocommerce' ) . '</a>';
} elseif ( EMPTY_TRASH_DAYS ) {
$actions['trash'] = '<a class="submitdelete" title="' . esc_attr( __( 'Move this item to the Trash', 'woocommerce' ) ) . '" href="' . get_delete_post_link( $the_webhook->id ) . '">' . __( 'Trash', 'woocommerce' ) . '</a>';
}
if ( 'trash' == $post_status || ! EMPTY_TRASH_DAYS ) {
$actions['delete'] = '<a class="submitdelete" title="' . esc_attr( __( 'Delete this item permanently', 'woocommerce' ) ) . '" href="' . get_delete_post_link( $the_webhook->id, '', true ) . '">' . __( 'Delete Permanently', 'woocommerce' ) . '</a>';
}
}
$actions = apply_filters( 'post_row_actions', $actions, $the_webhook->post_data );
$output .= '<div class="row-actions">';
$i = 0;
$action_count = sizeof( $actions );
foreach ( $actions as $action => $link ) {
++$i;
$sep = ( $i == $action_count ) ? '' : ' | ';
$output .= '<span class="' . $action . '">' . $link . $sep . '</span>';
}
$output .= '</div>';
break;
case 'status' :
$output = $the_webhook->get_i18n_status();
break;
case 'topic' :
$output = $the_webhook->get_topic();
break;
case 'delivery_url' :
$output = $the_webhook->get_delivery_url();
break;
default :
break;
}
return $output;
}
/**
* Get the status label for webhooks
*
* @param string $status_name
* @param stdClass $status
*
* @return array
*/
private function get_status_label( $status_name, $status ) {
switch ( $status_name ) {
case 'publish' :
$label = array(
'singular' => __( 'Actived <span class="count">(%s)</span>', 'woocommerce' ),
'plural' => __( 'Actived <span class="count">(%s)</span>', 'woocommerce' ),
'context' => '',
'domain' => 'woocommerce',
);
break;
case 'draft' :
$label = array(
'singular' => __( 'Paused <span class="count">(%s)</span>', 'woocommerce' ),
'plural' => __( 'Paused <span class="count">(%s)</span>', 'woocommerce' ),
'context' => '',
'domain' => 'woocommerce',
);
break;
case 'pending' :
$label = array(
'singular' => __( 'Disabled <span class="count">(%s)</span>', 'woocommerce' ),
'plural' => __( 'Disabled <span class="count">(%s)</span>', 'woocommerce' ),
'context' => '',
'domain' => 'woocommerce',
);
break;
default:
$label = $status->label_count;
break;
}
return $label;
}
/**
* Table list views
*
* @return array
*/
protected function get_views() {
$status_links = array();
$num_posts = wp_count_posts( 'shop_webhook', 'readable' );
$class = '';
$total_posts = array_sum( (array) $num_posts );
$current_user_id = get_current_user_id();
// Subtract post types that are not included in the admin all list.
foreach ( get_post_stati( array( 'show_in_admin_all_list' => false ) ) as $state ) {
$total_posts -= $num_posts->$state;
}
$class = empty( $class ) && empty( $_REQUEST['status'] ) ? ' class="current"' : '';
$status_links['all'] = "<a href='admin.php?page=wc-settings&amp;tab=webhooks'$class>" . sprintf( _nx( 'All <span class="count">(%s)</span>', 'All <span class="count">(%s)</span>', $total_posts, 'posts' ), number_format_i18n( $total_posts ) ) . '</a>';
foreach ( get_post_stati( array( 'show_in_admin_status_list' => true ), 'objects' ) as $status ) {
$class = '';
$status_name = $status->name;
if ( ! in_array( $status_name, array( 'publish', 'draft', 'pending', 'trash', 'future', 'private', 'auto-draft' ) ) ) {
continue;
}
if ( empty( $num_posts->$status_name ) ) {
continue;
}
if ( isset( $_REQUEST['status'] ) && $status_name == $_REQUEST['status'] ) {
$class = ' class="current"';
}
$label = $this->get_status_label( $status_name, $status );
$status_links[ $status_name ] = "<a href='admin.php?page=wc-settings&amp;tab=webhooks&amp;status=$status_name'$class>" . sprintf( translate_nooped_plural( $label, $num_posts->$status_name ), number_format_i18n( $num_posts->$status_name ) ) . '</a>';
}
return $status_links;
}
/**
* Get bulk actions
*
* @return array
*/
protected function get_bulk_actions() {
if ( isset( $_GET['status'] ) && 'trash' == $_GET['status'] ) {
return array(
'untrash' => __( 'Restore', 'woocommerce' ),
'delete' => __( 'Delete Permanently', 'woocommerce' )
);
}
return array(
'trash' => __( 'Move to Trash', 'woocommerce' )
);
}
/**
* Extra controls to be displayed between bulk actions and pagination
*
* @param string $which
*/
protected function extra_tablenav( $which ) {
if ( 'top' == $which && isset( $_GET['status'] ) && 'trash' == $_GET['status'] && current_user_can( 'delete_shop_webhooks' ) ) {
echo '<div class="alignleft actions"><a class="button apply" href="' . esc_url( admin_url( 'admin.php?page=wc-settings&tab=webhooks&status=trash&empty_trash=1' ) ) . '">' . __( 'Empty Trash' ) . '</a></div>';
}
}
/**
* Prepare table list items.
*/
public function prepare_items() {
$per_page = apply_filters( 'woocommerce_webhooks_settings_posts_per_page', 10 );
$columns = $this->get_columns();
$hidden = array();
$sortable = $this->get_sortable_columns();
// Column headers
$this->_column_headers = array( $columns, $hidden, $sortable );
$current_page = $this->get_pagenum();
// Query args
$args = array(
'post_type' => 'shop_webhook',
'posts_per_page' => $per_page,
'ignore_sticky_posts' => true,
'paged' => $current_page
);
// Handle the status query
if ( ! empty( $_REQUEST['status'] ) ) {
$args['post_status'] = sanitize_text_field( $_REQUEST['status'] );
}
if ( ! empty( $_REQUEST['s'] ) ) {
$args['s'] = sanitize_text_field( $_REQUEST['s'] );
}
// Get the webhooks
$webhooks = new WP_Query( $args );
$this->items = $webhooks->posts;
// Set the pagination
$this->set_pagination_args( array(
'total_items' => $webhooks->found_posts,
'per_page' => $per_page,
'total_pages' => $webhooks->max_num_pages
) );
}
}

View File

@ -0,0 +1,302 @@
<?php
/**
* WooCommerce Admin Webhooks Class.
*
* @author WooThemes
* @category Admin
* @package WooCommerce/Admin
* @version 2.3.0
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/**
* WC_Admin_Webhooks
*/
class WC_Admin_Webhooks {
/**
* Initialize the webhooks admin actions
*/
public function __construct() {
add_action( 'admin_init', array( $this, 'actions' ) );
}
/**
* Check if is webhook settings page
*
* @return bool
*/
private function is_webhook_settings_page() {
return isset( $_GET['page'] ) && 'wc-settings' == $_GET['page'] && isset( $_GET['tab'] ) && 'webhooks' == $_GET['tab'];
}
/**
* Updated the Webhook name
*
* @param int $webhook_id
*/
private function update_name( $webhook_id ) {
global $wpdb;
$name = ! empty( $_POST['webhook_name'] ) ? $_POST['webhook_name'] : sprintf( __( 'Webhook created on %s', 'woocommerce' ), strftime( _x( '%b %d, %Y @ %I:%M %p', 'Webhook created on date parsed by strftime', 'woocommerce' ) ) );
$wpdb->update( $wpdb->posts, array( 'post_title' => $name ), array( 'ID' => $webhook_id ) );
}
/**
* Updated the Webhook status
*
* @param WC_Webhook $webhook
*/
private function update_status( $webhook ) {
$status = ! empty( $_POST['webhook_status'] ) ? wc_clean( $_POST['webhook_status'] ) : '';
$webhook->update_status( $status );
}
/**
* Updated the Webhook delivery URL
*
* @param WC_Webhook $webhook
*/
private function update_delivery_url( $webhook ) {
$delivery_url = ! empty( $_POST['webhook_delivery_url'] ) ? $_POST['webhook_delivery_url'] : '';
if ( wc_is_valid_url( $delivery_url ) ) {
$webhook->set_delivery_url( $delivery_url );
}
}
/**
* Updated the Webhook secret
*
* @param WC_Webhook $webhook
*/
private function update_secret( $webhook ) {
$secret = ! empty( $_POST['webhook_secret'] ) ? $_POST['webhook_secret'] : get_user_meta( get_current_user_id(), 'woocommerce_api_consumer_secret', true );
$webhook->set_secret( $secret );
}
/**
* Updated the Webhook topic
*
* @param WC_Webhook $webhook
*/
private function update_topic( $webhook ) {
if ( ! empty( $_POST['webhook_topic'] ) ) {
list( $resource, $event ) = explode( '.', wc_clean( $_POST['webhook_topic'] ) );
if ( 'action' === $resource ) {
$event = ! empty( $_POST['webhook_action_event'] ) ? wc_clean( $_POST['webhook_action_event'] ) : '';
} else if ( ! in_array( $resource, array( 'coupon', 'customer', 'order', 'product' ) ) && ! empty( $_POST['webhook_custom_topic'] ) ) {
list( $resource, $event ) = explode( '.', wc_clean( $_POST['webhook_custom_topic'] ) );
}
$topic = $resource . '.' . $event;
if ( wc_is_webhook_valid_topic( $topic ) ) {
$webhook->set_topic( $topic );
}
}
}
/**
* Save method
*/
private function save() {
if ( empty( $_REQUEST['_wpnonce'] ) || ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'woocommerce-settings' ) ) {
die( __( 'Action failed. Please refresh the page and retry.', 'woocommerce' ) );
}
$webhook_id = absint( $_POST['webhook_id'] );
if ( ! current_user_can( 'edit_shop_webhook', $webhook_id ) ) {
return;
}
$webhook = new WC_Webhook( $webhook_id );
// Name
$this->update_name( $webhook->id );
// Status
$this->update_status( $webhook );
// Delivery URL
$this->update_delivery_url( $webhook );
// Secret
$this->update_secret( $webhook );
// Topic
$this->update_topic( $webhook );
// Ping the webhook at the first time that is activated
$peding_delivery = get_post_meta( $webhook->id, '_webhook_pending_delivery', true );
if ( isset( $_POST['webhook_status'] ) && 'active' === $_POST['webhook_status'] && $peding_delivery ) {
$webhook->deliver_ping();
}
do_action( 'woocommerce_webhook_options_save', $webhook->id );
// Redirect to webhook edit page to avoid settings save actions
wp_redirect( admin_url( 'admin.php?page=wc-settings&tab=webhooks&edit-webhook=' . $webhook->id . '&updated=1' ) );
exit();
}
/**
* Create Webhook
*/
private function create() {
if ( ! current_user_can( 'publish_shop_webhooks' ) ) {
wp_die( __( 'You don\'t have permissions to create Webhooks!', 'woocommerce' ) );
}
$webhook_id = wp_insert_post( array(
'post_type' => 'shop_webhook',
'post_status' => 'pending',
'ping_status' => 'closed',
'post_author' => get_current_user_id(),
'post_password' => strlen( ( $password = uniqid( 'webhook_' ) ) ) > 20 ? substr( $password, 0, 20 ) : $password,
'post_title' => sprintf( __( 'Webhook created on %s', 'woocommerce' ), strftime( _x( '%b %d, %Y @ %I:%M %p', 'Webhook created on date parsed by strftime', 'woocommerce' ) ) ),
'comment_status' => 'open'
) );
if ( is_wp_error( $webhook_id ) ) {
wp_die( $webhook_id->get_error_messages() );
}
update_post_meta( $webhook_id, '_webhook_pending_delivery', true );
// Redirect to edit page
wp_redirect( admin_url( 'admin.php?page=wc-settings&tab=webhooks&edit-webhook=' . $webhook_id . '&created=1' ) );
exit();
}
/**
* Bulk trash/delete
*
* @param array $webhooks
* @param bool $delete
*/
private function bulk_trash( $webhooks, $delete = false ) {
foreach ( $webhooks as $webhook_id ) {
if ( $delete ) {
wp_delete_post( $webhook_id, true );
} else {
wp_trash_post( $webhook_id );
}
}
$type = ! EMPTY_TRASH_DAYS || $delete ? 'deleted' : 'trashed';
$qty = count( $webhooks );
$status = isset( $_GET['status'] ) ? '&status=' . sanitize_text_field( $_GET['status'] ) : '';
// Redirect to webhooks page
wp_redirect( admin_url( 'admin.php?page=wc-settings&tab=webhooks' . $status . '&' . $type . '=' . $qty ) );
exit();
}
/**
* Bulk untrash
*
* @param array $webhooks
*/
private function bulk_untrash( $webhooks ) {
foreach ( $webhooks as $webhook_id ) {
wp_untrash_post( $webhook_id );
}
$qty = count( $webhooks );
// Redirect to webhooks page
wp_redirect( admin_url( 'admin.php?page=wc-settings&tab=webhooks&status=trash&untrashed=' . $qty ) );
exit();
}
/**
* Webhook bulk actions
*/
private function bulk_actions() {
if ( ! current_user_can( 'edit_shop_webhooks' ) ) {
wp_die( __( 'You don\'t have permissions to edit Webhooks!', 'woocommerce' ) );
}
$webhooks = array_map( 'absint', (array) $_GET['webhook'] );
switch ( $_GET['action'] ) {
case 'trash' :
$this->bulk_trash( $webhooks );
break;
case 'untrash' :
$this->bulk_untrash( $webhooks );
break;
case 'delete' :
$this->bulk_trash( $webhooks, true );
break;
default :
break;
}
}
/**
* Empty Trash
*/
public function empty_trash() {
if ( ! current_user_can( 'delete_shop_webhooks' ) ) {
wp_die( __( 'You don\'t have permissions to delete Webhooks!', 'woocommerce' ) );
}
$webhooks = get_posts( array(
'post_type' => 'shop_webhook',
'ignore_sticky_posts' => true,
'nopaging' => true,
'post_status' => 'trash',
'fields' => 'ids'
) );
foreach ( $webhooks as $webhook_id ) {
wp_delete_post( $webhook_id, true );
}
$qty = count( $webhooks );
// Redirect to webhooks page
wp_redirect( admin_url( 'admin.php?page=wc-settings&tab=webhooks&deleted=' . $qty ) );
exit();
}
/**
* Webhooks admin actions
*/
public function actions() {
if ( $this->is_webhook_settings_page() ) {
// Save
if ( isset( $_POST['save'] ) && isset( $_POST['webhook_id'] ) ) {
$this->save();
}
// Create
if ( isset( $_GET['create-webhook'] ) ) {
$this->create();
}
// Bulk actions
if ( isset( $_GET['action'] ) && isset( $_GET['webhook'] ) ) {
$this->bulk_actions();
}
// Bulk actions
if ( isset( $_GET['empty_trash'] ) ) {
$this->empty_trash();
}
}
}
}
new WC_Admin_Webhooks();

View File

@ -47,6 +47,7 @@ class WC_Admin {
include( 'class-wc-admin-welcome.php' );
include( 'class-wc-admin-notices.php' );
include( 'class-wc-admin-assets.php' );
include( 'class-wc-admin-webhooks.php' );
// Help
if ( apply_filters( 'woocommerce_enable_admin_help_tab', true ) ) {

View File

@ -1,75 +0,0 @@
<?php
/**
* Webhook Actions
*
* Display the webhook actions meta box.
*
* @author WooThemes
* @category Admin
* @package WooCommerce/Admin/Meta Boxes
* @version 2.3.0
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/**
* WC_Meta_Box_Webhook_Actions Class
*/
class WC_Meta_Box_Webhook_Actions {
/**
* Get date i18n.
*
* @param string $date
*
* @return string
*/
protected static function get_date_i18n( $date ) {
return date_i18n( __( 'M j, Y @ G:i', 'woocommerce' ), strtotime( $date ) );
}
/**
* Output the metabox
*/
public static function output( $post ) {
?>
<style>
#poststuff #woocommerce-webhook-actions .inside { padding: 0; margin: 0; }
</style>
<?php if ( '0000-00-00 00:00:00' != $post->post_modified_gmt ) : ?>
<ul class="order_actions submitbox">
<?php if ( '0000-00-00 00:00:00' == $post->post_date_gmt ) : ?>
<li class="wide">
<strong><?php _e( 'Created at' ); ?>:</strong> <?php echo self::get_date_i18n( $post->post_modified_gmt ); ?>
</li>
<?php else : ?>
<li class="wide">
<strong><?php _e( 'Created at' ); ?>:</strong> <?php echo self::get_date_i18n( $post->post_date_gmt ); ?>
</li>
<li class="wide">
<strong><?php _e( 'Updated at' ); ?>:</strong> <?php echo self::get_date_i18n( $post->post_modified_gmt ); ?>
</li>
<?php endif; ?>
</ul>
<?php endif; ?>
<div class="submitbox" id="submitpost">
<div id="major-publishing-actions">
<?php if ( current_user_can( 'delete_post', $post->ID ) ) : ?>
<div id="delete-action">
<a class="submitdelete deletion" href="<?php echo esc_url( get_delete_post_link( $post->ID ) ); ?>"><?php echo ( ! EMPTY_TRASH_DAYS ) ? __( 'Delete Permanently', 'woocommerce' ) : __( 'Move to Trash', 'woocommerce' ); ?></a></div>
<?php endif; ?>
<div id="publishing-action">
<span class="spinner"></span>
<input type="submit" class="button button-primary button-large" name="save" id="publish" accesskey="p" value="<?php _e( 'Save Webhook', 'woocommerce' ); ?>" data-tip="<?php _e( 'Save/update the Webhook', 'woocommerce' ); ?>" />
</div>
<div class="clear"></div>
</div>
</div>
<?php
}
}

View File

@ -1,97 +0,0 @@
<?php
/**
* Webhook Logs
*
* @author WooThemes
* @category Admin
* @package WooCommerce/Admin/Meta Boxes
* @version 2.3.0
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/**
* WC_Meta_Box_Webhook_Logs Class
*/
class WC_Meta_Box_Webhook_Logs {
/**
* Log quantity
*
* @var int
*/
public static $quantity = 10;
/**
* Output the metabox
*/
public static function output( $post ) {
$webhook = new WC_Webhook( $post->ID );
$current = isset( $_GET['log_page'] ) ? absint( $_GET['log_page'] ) : 1;
$args = array(
'post_id' => $webhook->id,
'status' => 'approve',
'type' => 'webhook_delivery',
'number' => self::$quantity
);
if ( 1 < $current ) {
$args['offset'] = ( $current - 1 ) * self::$quantity;
}
remove_filter( 'comments_clauses', array( 'WC_Comments', 'exclude_webhook_comments' ), 10, 1 );
$logs = get_comments( $args );
add_filter( 'comments_clauses', array( 'WC_Comments', 'exclude_webhook_comments' ), 10, 1 );
if ( $logs ) {
include_once( 'views/html-webhook-logs.php' );
} else {
echo '<p>' . __( 'This Webhook has no log yet.', 'woocommerce' ) . '</p>';
}
}
/**
* Get the logs navigation.
*
* @param int $total
*
* @return string
*/
public static function get_navigation( $total ) {
global $post;
$pages = ceil( $total / self::$quantity );
$current = isset( $_GET['log_page'] ) ? absint( $_GET['log_page'] ) : 1;
$html = '<div class="webhook-logs-navigation">';
$html .= '<p class="info" style="float: left;"><strong>';
$html .= sprintf( '%s &ndash; Page %d of %d', _n( '1 item', sprintf( '%d items', $total ), $total, 'woocommerce' ), $current, $pages );
$html .= '</strong></p>';
if ( 1 < $pages ) {
$html .= '<p class="tools" style="float: right;">';
if ( 1 == $current ) {
$html .= '<button class="button-primary" disabled="disabled">' . __( '&lsaquo; Previous', 'woocommerce' ) . '</button> ';
} else {
$html .= '<a class="button-primary" href="' . admin_url( 'post.php?post=' . $post->ID . '&action=edit&log_page=' . ( $current - 1 ) ) . '">' . __( '&lsaquo; Previous', 'woocommerce' ) . '</a> ';
}
if ( $pages == $current ) {
$html .= '<button class="button-primary" disabled="disabled">' . __( 'Next &rsaquo;', 'woocommerce' ) . '</button>';
} else {
$html .= '<a class="button-primary" href="' . admin_url( 'post.php?post=' . $post->ID . '&action=edit&log_page=' . ( $current + 1 ) ) . '">' . __( 'Next &rsaquo;', 'woocommerce' ) . '</a>';
}
$html .= '</p>';
}
$html .= '<div class="clear"></div></div>';
return $html;
}
}

View File

@ -63,7 +63,7 @@ class WC_Settings_Tax extends WC_Settings_Page {
$classes_options[ sanitize_title( $class ) ] = esc_html( $class );
}
return apply_filters( 'woocommerce_get_settings_' . $this->id, include( 'settings-tax.php' ) );
return apply_filters( 'woocommerce_get_settings_' . $this->id, include( 'views/settings-tax.php' ) );
}
/**
@ -110,7 +110,7 @@ class WC_Settings_Tax extends WC_Settings_Page {
$limit = 100;
$current_class = $this->get_current_tax_class();
include( 'html-settings-tax.php' );
include( 'views/html-settings-tax.php' );
}
/**

View File

@ -0,0 +1,234 @@
<?php
/**
* WooCommerce Webhooks Settings
*
* @author WooThemes
* @category Admin
* @package WooCommerce/Admin
* @version 2.3.0
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
if ( ! class_exists( 'WC_Settings_Webhooks' ) ) :
/**
* WC_Settings_Webhooks
*/
class WC_Settings_Webhooks extends WC_Settings_Page {
/**
* Constructor
*/
public function __construct() {
$this->id = 'webhooks';
$this->label = __( 'Webhooks', 'woocommerce' );
add_filter( 'woocommerce_settings_tabs_array', array( $this, 'add_settings_page' ), 20 );
add_action( 'woocommerce_settings_' . $this->id, array( $this, 'output' ) );
add_action( 'woocommerce_settings_form_method_tab_' . $this->id, array( $this, 'form_method' ) );
$this->notices();
}
/**
* Form method
*
* @param string $method
*
* @return string
*/
public function form_method( $method ) {
if ( isset( $_GET['edit-webhook'] ) ) {
$webhook_id = absint( $_GET['edit-webhook'] );
$webhook = new WC_Webhook( $webhook_id );
if ( 'trash' != $webhook->post_data->post_status ) {
return 'post';
}
}
return 'get';
}
/**
* Notices.
*/
private function notices() {
if ( isset( $_GET['trashed'] ) ) {
$trashed = absint( $_GET['trashed'] );
WC_Admin_Settings::add_message( sprintf( _n( '1 webhook moved to the Trash.', '%d webhooks moved to the Trash.', $trashed, 'woocommerce' ), $trashed ) );
}
if ( isset( $_GET['untrashed'] ) ) {
$untrashed = absint( $_GET['untrashed'] );
WC_Admin_Settings::add_message( sprintf( _n( '1 webhook restored from the Trash.', '%d webhooks restored from the Trash.', $untrashed, 'woocommerce' ), $untrashed ) );
}
if ( isset( $_GET['deleted'] ) ) {
$deleted = absint( $_GET['deleted'] );
WC_Admin_Settings::add_message( sprintf( _n( '1 webhook permanently deleted.', '%d webhooks permanently deleted.', $deleted, 'woocommerce' ), $deleted ) );
}
if ( isset( $_GET['updated'] ) ) {
WC_Admin_Settings::add_message( __( 'Webhook updated successfully.', 'woocommerce' ) );
}
if ( isset( $_GET['created'] ) ) {
WC_Admin_Settings::add_message( __( 'Webhook created successfully.', 'woocommerce' ) );
}
}
/**
* Table list output
*/
private function table_list_output() {
echo '<h3>' . __( 'Webhooks', 'woocommerce' ) . ' <a href="' . esc_url( admin_url( 'admin.php?page=wc-settings&tab=webhooks&create-webhook=1' ) ) . '" class="add-new-h2">' . __( 'Add Webhook', 'woocommerce' ) . '</a></h3>';
$webhooks_table_list = new WC_Admin_Webhooks_Table_List();
$webhooks_table_list->prepare_items();
echo '<input type="hidden" name="page" value="wc-settings" />';
echo '<input type="hidden" name="tab" value="webhooks" />';
$webhooks_table_list->views();
$webhooks_table_list->search_box( __( 'Search Webhooks', 'woocommerce' ), 'webhook' );
$webhooks_table_list->display();
}
/**
* Edit webhook output
*
* @param WC_Webhook $webhook
*/
private function edit_output( $webhook ) {
include_once( 'views/html-webhooks-edit.php' );
}
/**
* Logs output
*
* @param WC_Webhook $webhook
*/
private function logs_output( $webhook ) {
$current = isset( $_GET['log_page'] ) ? absint( $_GET['log_page'] ) : 1;
$args = array(
'post_id' => $webhook->id,
'status' => 'approve',
'type' => 'webhook_delivery',
'number' => 10
);
if ( 1 < $current ) {
$args['offset'] = ( $current - 1 ) * 10;
}
remove_filter( 'comments_clauses', array( 'WC_Comments', 'exclude_webhook_comments' ), 10, 1 );
$logs = get_comments( $args );
add_filter( 'comments_clauses', array( 'WC_Comments', 'exclude_webhook_comments' ), 10, 1 );
if ( $logs ) {
include_once( 'views/html-webhook-logs.php' );
} else {
echo '<p>' . __( 'This Webhook has no log yet.', 'woocommerce' ) . '</p>';
}
}
/**
* Output the settings
*/
public function output() {
global $current_section;
// Hide the save button
$GLOBALS['hide_save_button'] = true;
if ( isset( $_GET['edit-webhook'] ) ) {
$webhook_id = absint( $_GET['edit-webhook'] );
$webhook = new WC_Webhook( $webhook_id );
if ( 'trash' != $webhook->post_data->post_status ) {
$this->edit_output( $webhook );
return;
}
}
$this->table_list_output();
}
/**
* Get the webhook topic data
*
* @return array
*/
private function get_topic_data( $webhook ) {
$topic = $webhook->get_topic();
$event = '';
$resource = '';
if ( $topic ) {
list( $resource, $event ) = explode( '.', $topic );
if ( 'action' === $resource ) {
$topic = 'action';
} else if ( ! in_array( $resource, array( 'coupon', 'customer', 'order', 'product' ) ) ) {
$topic = 'custom';
}
}
return array(
'topic' => $topic,
'event' => $event,
'resource' => $resource
);
}
/**
* Get the logs navigation.
*
* @param int $total
*
* @return string
*/
private function get_logs_navigation( $total, $webhook ) {
$pages = ceil( $total / 10 );
$current = isset( $_GET['log_page'] ) ? absint( $_GET['log_page'] ) : 1;
$html = '<div class="webhook-logs-navigation">';
$html .= '<p class="info" style="float: left;"><strong>';
$html .= sprintf( '%s &ndash; Page %d of %d', _n( '1 item', sprintf( '%d items', $total ), $total, 'woocommerce' ), $current, $pages );
$html .= '</strong></p>';
if ( 1 < $pages ) {
$html .= '<p class="tools" style="float: right;">';
if ( 1 == $current ) {
$html .= '<button class="button-primary" disabled="disabled">' . __( '&lsaquo; Previous', 'woocommerce' ) . '</button> ';
} else {
$html .= '<a class="button-primary" href="' . admin_url( 'admin.php?page=wc-settings&tab=webhooks&edit-webhook=' . $webhook->id . '&log_page=' . ( $current - 1 ) ) . '#webhook-logs">' . __( '&lsaquo; Previous', 'woocommerce' ) . '</a> ';
}
if ( $pages == $current ) {
$html .= '<button class="button-primary" disabled="disabled">' . __( 'Next &rsaquo;', 'woocommerce' ) . '</button>';
} else {
$html .= '<a class="button-primary" href="' . admin_url( 'admin.php?page=wc-settings&tab=webhooks&edit-webhook=' . $webhook->id . '&log_page=' . ( $current + 1 ) ) . '#webhook-logs">' . __( 'Next &rsaquo;', 'woocommerce' ) . '</a>';
}
$html .= '</p>';
}
$html .= '<div class="clear"></div></div>';
return $html;
}
}
endif;
return new WC_Settings_Webhooks();

View File

@ -9,9 +9,9 @@ $total = $count_comments->approved;
?>
<?php echo WC_Meta_Box_Webhook_Logs::get_navigation( $total ); ?>
<?php echo $this->get_logs_navigation( $total, $webhook ); ?>
<table id="webhook-logs" class="widefat">
<table id="webhook-logs-table" class="widefat">
<thead>
<tr>
<th><?php _e( 'Date', 'woocommerce' ); ?></th>
@ -39,4 +39,4 @@ $total = $count_comments->approved;
</tbody>
</table>
<?php echo WC_Meta_Box_Webhook_Logs::get_navigation( $total ); ?>
<?php echo $this->get_logs_navigation( $total, $webhook ); ?>

View File

@ -0,0 +1,185 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
?>
<input type="hidden" name="webhook_id" value="<?php echo esc_attr( $webhook->id ); ?>" />
<div id="webhook-options" class="settings-panel">
<h3><?php _e( 'Webhook Data', 'woocommerce' ); ?></h3>
<table class="form-table">
<tbody>
<tr valign="top">
<th scope="row" class="titledesc">
<label for="webhook_name"><?php _e( 'Name', 'woocommerce' ); ?></label>
<img class="help_tip" data-tip="<?php echo 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' ) ) ); ?>" src="<?php echo WC()->plugin_url(); ?>/assets/images/help.png" height="16" width="16" />
</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">
<label for="webhook_status"><?php _e( 'Status', 'woocommerce' ); ?></label>
<img class="help_tip" data-tip="<?php _e( 'The options are "Active" (delivers payload), "Paused" (does not deliver), or "Disabled" (does not deliver due delivery failures).', 'woocommerce' ); ?>" src="<?php echo WC()->plugin_url(); ?>/assets/images/help.png" height="16" width="16" />
</th>
<td class="forminp">
<select name="webhook_status" id="webhook_status">
<?php
$statuses = wc_get_webhook_statuses();
$current_status = $webhook->get_status();
foreach ( $statuses as $status_slug => $status_name ) : ?>
<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">
<label for="webhook_topic"><?php _e( 'Topic', 'woocommerce' ); ?></label>
<img class="help_tip" data-tip="<?php _e( 'Select when the webhook will fire.', 'woocommerce' ); ?>" src="<?php echo WC()->plugin_url(); ?>/assets/images/help.png" height="16" width="16" />
</th>
<td class="forminp">
<select name="webhook_topic" id="webhook_topic">
<?php
$topic_data = $this->get_topic_data( $webhook );
$topics = array(
'' => __( 'Select an option&hellip;', 'woocommerce' ),
'coupon.created' => __( 'Coupon Created', 'woocommerce' ),
'coupon.updated' => __( 'Coupon Updated', 'woocommerce' ),
'coupon.deleted' => __( 'Coupon Deleted', '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' ),
'product.created' => __( 'Product Created', 'woocommerce' ),
'product.updated' => __( 'Product Updated', 'woocommerce' ),
'product.deleted' => __( 'Product Deleted', 'woocommerce' ),
'action' => __( 'Action', 'woocommerce' ),
'custom' => __( 'Custom', 'woocommerce' )
);
foreach ( $topics as $topic_slug => $topic_name ) : ?>
<option value="<?php echo esc_attr( $topic_slug ); ?>" <?php selected( $topic_data['topic'], $topic_slug, true ); ?>><?php echo esc_html( $topic_name ); ?></option>
<?php endforeach; ?>
</select>
</td>
</tr>
<tr valign="top" id="webhook-action-event-wrap">
<th scope="row" class="titledesc">
<label for="webhook_action_event"><?php _e( 'Action Event', 'woocommerce' ); ?></label>
<img class="help_tip" data-tip="<?php _e( 'Enter the Action that will trigger this webhook.', 'woocommerce' ); ?>" src="<?php echo WC()->plugin_url(); ?>/assets/images/help.png" height="16" width="16" />
</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" id="webhook-custom-topic-wrap">
<th scope="row" class="titledesc">
<label for="webhook_custom_topic"><?php _e( 'Custom Topic', 'woocommerce' ); ?></label>
<img class="help_tip" data-tip="<?php _e( 'Enter the Custom Topic that will trigger this webhook.', 'woocommerce' ); ?>" src="<?php echo WC()->plugin_url(); ?>/assets/images/help.png" height="16" width="16" />
</th>
<td class="forminp">
<input name="webhook_custom_topic" id="webhook_custom_topic" type="text" class="input-text regular-input" value="<?php echo esc_attr( $webhook->get_topic() ); ?>" />
</td>
</tr>
<tr valign="top">
<th scope="row" class="titledesc">
<label for="webhook_delivery_url"><?php _e( 'Delivery URL', 'woocommerce' ); ?></label>
<img class="help_tip" data-tip="<?php _e( 'URL where the webhook payload is delivered.', 'woocommerce' ); ?>" src="<?php echo WC()->plugin_url(); ?>/assets/images/help.png" height="16" width="16" />
</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">
<label for="webhook_secret"><?php _e( 'Secret', 'woocommerce' ); ?></label>
<img class="help_tip" data-tip="<?php _e( 'The a Secret Key is used to generate a hash of the delivered webhook and provided in the request headers. This will default to the current API user\'s consumer secret if not provided.', 'woocommerce' ); ?>" src="<?php echo WC()->plugin_url(); ?>/assets/images/help.png" height="16" width="16" />
</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>
</tbody>
</table>
<?php do_action( 'woocommerce_webhook_options' ); ?>
</div>
<div id="webhook-actions" class="settings-panel">
<h3><?php _e( 'Webhook Actions', 'woocommerce' ); ?></h3>
<table class="form-table">
<tbody>
<?php if ( '0000-00-00 00:00:00' != $webhook->post_data->post_modified_gmt ) : ?>
<?php if ( '0000-00-00 00:00:00' == $webhook->post_data->post_date_gmt ) : ?>
<tr valign="top">
<th scope="row" class="titledesc">
<?php _e( 'Created at', 'woocommerce' ); ?>
</th>
<td class="forminp">
<?php echo date_i18n( __( 'M j, Y @ G:i', 'woocommerce' ), strtotime( $webhook->post_data->post_modified_gmt ) ); ?>
</td>
</tr>
<?php else : ?>
<tr valign="top">
<th scope="row" class="titledesc">
<?php _e( 'Created at', 'woocommerce' ); ?>
</th>
<td class="forminp">
<?php echo date_i18n( __( 'M j, Y @ G:i', 'woocommerce' ), strtotime( $webhook->post_data->post_date_gmt ) ); ?>
</td>
</tr>
<tr valign="top">
<th scope="row" class="titledesc">
<?php _e( 'Updated at', 'woocommerce' ); ?>
</th>
<td class="forminp">
<?php echo date_i18n( __( 'M j, Y @ G:i', 'woocommerce' ), strtotime( $webhook->post_data->post_modified_gmt ) ); ?>
</td>
</tr>
<?php endif; ?>
<?php endif; ?>
<tr valign="top">
<td colspan="2" scope="row" style="padding-left: 0;">
<p class="submit">
<input type="submit" class="button button-primary button-large" name="save" id="publish" accesskey="p" value="<?php _e( 'Save Webhook', 'woocommerce' ); ?>" data-tip="<?php _e( 'Save/update the Webhook', 'woocommerce' ); ?>" />
<?php if ( current_user_can( 'delete_post', $webhook->id ) ) : ?>
<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>
<?php endif; ?>
</p>
</td>
</tr>
</tbody>
</table>
</div>
<div id="webhook-logs" class="settings-panel">
<h3><?php _e( 'Webhook Logs', 'woocommerce' ); ?></h3>
<?php $this->logs_output( $webhook ); ?>
</div>
<script type="text/javascript">
jQuery( function ( $ ) {
$( '#webhook-options #webhook_topic' ).on( 'change', function() {
var current = $( this ).val(),
action_event_field = $( '#webhook-options #webhook-action-event-wrap' ),
custom_topic_field = $( '#webhook-options #webhook-custom-topic-wrap' );
action_event_field.hide();
custom_topic_field.hide();
if ( 'action' === current ) {
action_event_field.show();
} else if ( 'custom' === current ) {
custom_topic_field.show();
}
}).change();
});
</script>

View File

@ -10,11 +10,12 @@ if ( ! defined( 'ABSPATH' ) ) {
?>
<div class="wrap woocommerce">
<form method="post" id="mainform" action="" enctype="multipart/form-data">
<form method="<?php echo esc_attr( apply_filters( 'woocommerce_settings_form_method_tab_' . $current_tab, 'post' ) ); ?>" id="mainform" action="" enctype="multipart/form-data">
<div class="icon32 icon32-woocommerce-settings" id="icon-woocommerce"><br /></div><h2 class="nav-tab-wrapper woo-nav-tab-wrapper">
<?php
foreach ( $tabs as $name => $label )
foreach ( $tabs as $name => $label ) {
echo '<a href="' . admin_url( 'admin.php?page=wc-settings&tab=' . $name ) . '" class="nav-tab ' . ( $current_tab == $name ? 'nav-tab-active' : '' ) . '">' . $label . '</a>';
}
do_action( 'woocommerce_settings_tabs' );
?>

View File

@ -34,9 +34,7 @@ function wc_get_screen_ids() {
'edit-product_cat',
'edit-product_tag',
'edit-product_shipping_class',
'profile',
'shop_webhook',
'edit-shop_webhook'
'profile'
);
foreach ( wc_get_order_types() as $type ) {

View File

@ -386,7 +386,7 @@ class WC_Post_types {
'parent' => __( 'Parent Webhook', 'woocommerce' )
),
'public' => false,
'show_ui' => true,
'show_ui' => false,
'capability_type' => 'shop_webhook',
'map_meta_cap' => true,
'publicly_queryable' => false,