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0-beta.1 3.2.2 6.3.0-rc.1 3.2.3 6.3.0-rc.2 3.2.4 6.3.1 3.2.5 6.3.2 3.2.6 6.4.0 3.3.0 6.4.0-beta.1 3.3.1 6.4.0-rc.1 3.3.2 6.4.1 3.3.2-rc.1 6.4.2 3.3.3 6.5.0 3.3.4 6.5.0-beta.1 3.3.5 6.5.0-rc.1 3.3.6 6.5.0-rc.2 3.4.0 6.5.1 3.4.0-beta.1 6.5.2 3.4.0-rc.2 6.6.0 3.4.1 6.6.0-beta.1 3.4.2 6.6.0-rc.1 3.4.3 6.6.0-rc.2 3.4.4 6.6.1 3.4.5 6.6.2 3.4.6 6.7.0 3.4.7 6.7.0-beta.1 3.4.8 6.7.0-beta.2 3.5.0 6.7.0-rc.1 3.5.0-beta.1 6.7.1 3.5.0-rc.1 6.8.0 3.5.0-rc.2 6.8.0-beta.1 3.5.1 6.8.0-beta.2 3.5.10 6.8.0-rc.1 3.5.2 6.8.1 3.5.3 6.8.2 3.5.4 6.8.3 3.5.5 6.9.0 3.5.6 6.9.0-beta.1 3.5.7 6.9.0-beta.2 3.5.8 6.9.0-rc.1 3.5.9 6.9.1 3.6.0 6.9.2 3.6.0-beta.1 6.9.3 3.6.0-rc.1 6.9.4 3.6.0-rc.2 6.9.5 3.6.0-rc.3 7.0.0 3.6.1 7.0.0-beta.1 3.6.2 7.0.0-beta.2 3.6.3 7.0.0-beta.3 3.6.4 7.0.0-rc.1 3.6.5 7.0.0-rc.2 3.6.6 7.0.1 3.6.7 7.0.2 3.7.0 7.1.0 3.7.0-beta.1 7.1.0-beta.1 3.7.0-rc.1 7.1.0-beta.2 3.7.0-rc.2 7.1.0-rc.1 3.7.1 7.1.0-rc.2 3.7.2 7.1.1
woocommerce / includes / admin / class-wc-admin-webhooks-table-list.php
woocommerce / includes / admin Last commit date
helper 2 years ago importers 3 years ago list-tables 2 years ago marketplace-suggestions 2 years ago meta-boxes 2 years ago notes 2 years ago plugin-updates 2 years ago reports 2 years ago settings 2 years ago views 2 years ago class-wc-admin-addons.php 2 years ago class-wc-admin-api-keys-table-list.php 2 years ago class-wc-admin-api-keys.php 2 years ago class-wc-admin-assets.php 2 years ago class-wc-admin-attributes.php 3 years ago class-wc-admin-customize.php 5 years ago class-wc-admin-dashboard-setup.php 2 years ago class-wc-admin-dashboard.php 3 years ago class-wc-admin-duplicate-product.php 5 years ago class-wc-admin-exporters.php 3 years ago class-wc-admin-help.php 2 years ago class-wc-admin-importers.php 2 years ago class-wc-admin-log-table-list.php 2 years ago class-wc-admin-menus.php 2 years ago class-wc-admin-meta-boxes.php 2 years ago class-wc-admin-notices.php 2 years ago class-wc-admin-permalink-settings.php 5 years ago class-wc-admin-pointers.php 3 years ago class-wc-admin-post-types.php 2 years ago class-wc-admin-profile.php 2 years ago class-wc-admin-reports.php 5 years ago class-wc-admin-settings.php 2 years ago class-wc-admin-setup-wizard.php 2 years ago class-wc-admin-status.php 2 years ago class-wc-admin-taxonomies.php 3 years ago class-wc-admin-upload-downloadable-product.php 2 years ago class-wc-admin-webhooks-table-list.php 2 years ago class-wc-admin-webhooks.php 2 years ago class-wc-admin.php 2 years ago wc-admin-functions.php 2 years ago wc-meta-box-functions.php 2 years ago
class-wc-admin-webhooks-table-list.php
344 lines
1 <?php
2 /**
3 * WooCommerce Webhooks Table List
4 *
5 * @package WooCommerce\Admin
6 * @version 3.3.0
7 */
8
9 use Automattic\WooCommerce\Internal\Utilities\WebhookUtil;
10
11 defined( 'ABSPATH' ) || exit;
12
13 if ( ! class_exists( 'WP_List_Table' ) ) {
14 require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
15 }
16
17 /**
18 * Webhooks table list class.
19 */
20 class WC_Admin_Webhooks_Table_List extends WP_List_Table {
21
22 /**
23 * Initialize the webhook table list.
24 */
25 public function __construct() {
26 parent::__construct(
27 array(
28 'singular' => 'webhook',
29 'plural' => 'webhooks',
30 'ajax' => false,
31 )
32 );
33 }
34
35 /**
36 * No items found text.
37 */
38 public function no_items() {
39 esc_html_e( 'No webhooks found.', 'woocommerce' );
40 }
41
42 /**
43 * Get list columns.
44 *
45 * @return array
46 */
47 public function get_columns() {
48 return array(
49 'cb' => '<input type="checkbox" />',
50 'title' => __( 'Name', 'woocommerce' ),
51 'status' => __( 'Status', 'woocommerce' ),
52 'topic' => __( 'Topic', 'woocommerce' ),
53 'delivery_url' => __( 'Delivery URL', 'woocommerce' ),
54 );
55 }
56
57 /**
58 * Column cb.
59 *
60 * @param WC_Webhook $webhook Webhook instance.
61 * @return string
62 */
63 public function column_cb( $webhook ) {
64 return sprintf( '<input type="checkbox" name="%1$s[]" value="%2$s" />', $this->_args['singular'], $webhook->get_id() );
65 }
66
67 /**
68 * Return title column.
69 *
70 * @param WC_Webhook $webhook Webhook instance.
71 * @return string
72 */
73 public function column_title( $webhook ) {
74 $edit_link = admin_url( 'admin.php?page=wc-settings&amp;tab=advanced&amp;section=webhooks&amp;edit-webhook=' . $webhook->get_id() );
75 $output = '';
76
77 // Title.
78 $output .= '<strong><a href="' . esc_url( $edit_link ) . '" class="row-title">' . esc_html( $webhook->get_name() ) . '</a></strong>';
79
80 // Get actions.
81 $actions = array(
82 /* translators: %s: webhook ID. */
83 'id' => sprintf( __( 'ID: %d', 'woocommerce' ), $webhook->get_id() ),
84 'edit' => '<a href="' . esc_url( $edit_link ) . '">' . esc_html__( 'Edit', 'woocommerce' ) . '</a>',
85 /* translators: %s: webhook name */
86 'delete' => '<a class="submitdelete" aria-label="' . esc_attr( sprintf( __( 'Delete "%s" permanently', 'woocommerce' ), $webhook->get_name() ) ) . '" href="' . esc_url(
87 wp_nonce_url(
88 add_query_arg(
89 array(
90 'delete' => $webhook->get_id(),
91 ),
92 admin_url( 'admin.php?page=wc-settings&tab=advanced&section=webhooks' )
93 ),
94 'delete-webhook'
95 )
96 ) . '">' . esc_html__( 'Delete permanently', 'woocommerce' ) . '</a>',
97 );
98
99 $actions = apply_filters( 'webhook_row_actions', $actions, $webhook );
100 $row_actions = array();
101
102 foreach ( $actions as $action => $link ) {
103 $row_actions[] = '<span class="' . esc_attr( $action ) . '">' . $link . '</span>';
104 }
105
106 $output .= '<div class="row-actions">' . implode( ' | ', $row_actions ) . '</div>';
107
108 return $output;
109 }
110
111 /**
112 * Return status column.
113 *
114 * @param WC_Webhook $webhook Webhook instance.
115 * @return string
116 */
117 public function column_status( $webhook ) {
118 return $webhook->get_i18n_status();
119 }
120
121 /**
122 * Return topic column.
123 *
124 * @param WC_Webhook $webhook Webhook instance.
125 * @return string
126 */
127 public function column_topic( $webhook ) {
128 return $webhook->get_topic();
129 }
130
131 /**
132 * Return delivery URL column.
133 *
134 * @param WC_Webhook $webhook Webhook instance.
135 * @return string
136 */
137 public function column_delivery_url( $webhook ) {
138 return $webhook->get_delivery_url();
139 }
140
141 /**
142 * Get the status label for webhooks.
143 *
144 * @param string $status_name Status name.
145 * @param int $amount Amount of webhooks.
146 * @return array
147 */
148 private function get_status_label( $status_name, $amount ) {
149 $statuses = wc_get_webhook_statuses();
150
151 if ( isset( $statuses[ $status_name ] ) ) {
152 return array(
153 'singular' => sprintf( '%s <span class="count">(%s)</span>', esc_html( $statuses[ $status_name ] ), $amount ),
154 'plural' => sprintf( '%s <span class="count">(%s)</span>', esc_html( $statuses[ $status_name ] ), $amount ),
155 'context' => '',
156 'domain' => 'woocommerce',
157 );
158 }
159
160 return array(
161 'singular' => sprintf( '%s <span class="count">(%s)</span>', esc_html( $status_name ), $amount ),
162 'plural' => sprintf( '%s <span class="count">(%s)</span>', esc_html( $status_name ), $amount ),
163 'context' => '',
164 'domain' => 'woocommerce',
165 );
166 }
167
168 /**
169 * Table list views.
170 *
171 * @return array
172 */
173 protected function get_views() {
174 $status_links = array();
175 $data_store = WC_Data_Store::load( 'webhook' );
176 $num_webhooks = $data_store->get_count_webhooks_by_status();
177 $total_webhooks = array_sum( (array) $num_webhooks );
178 $statuses = array_keys( wc_get_webhook_statuses() );
179 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
180 $class = empty( $_REQUEST['status'] ) && empty( $_REQUEST['legacy'] ) ? ' class="current"' : '';
181
182 /* translators: %s: count */
183 $status_links['all'] = "<a href='admin.php?page=wc-settings&amp;tab=advanced&amp;section=webhooks'$class>" . sprintf( _nx( 'All <span class="count">(%s)</span>', 'All <span class="count">(%s)</span>', $total_webhooks, 'posts', 'woocommerce' ), number_format_i18n( $total_webhooks ) ) . '</a>';
184
185 foreach ( $statuses as $status_name ) {
186 $class = '';
187
188 if ( empty( $num_webhooks[ $status_name ] ) ) {
189 continue;
190 }
191
192 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
193 if ( isset( $_REQUEST['status'] ) && sanitize_key( wp_unslash( $_REQUEST['status'] ) ) === $status_name ) {
194 $class = ' class="current"';
195 }
196
197 $label = $this->get_status_label( $status_name, $num_webhooks[ $status_name ] );
198
199 $status_links[ $status_name ] = "<a href='admin.php?page=wc-settings&amp;tab=advanced&amp;section=webhooks&amp;status=$status_name'$class>" . sprintf( translate_nooped_plural( $label, $num_webhooks[ $status_name ] ), number_format_i18n( $num_webhooks[ $status_name ] ) ) . '</a>';
200 }
201
202 $legacy_webhooks_count = wc_get_container()->get( WebhookUtil::class )->get_legacy_webhooks_count();
203 if ( $legacy_webhooks_count > 0 ) {
204 $class = '';
205
206 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
207 if ( 'true' === sanitize_key( wp_unslash( $_REQUEST['legacy'] ?? '' ) ) ) {
208 $class = ' class="current"';
209 }
210
211 $label = $this->get_status_label( __( 'Legacy', 'woocommerce' ), $legacy_webhooks_count );
212
213 $status_links['legacy'] = "<a href='admin.php?page=wc-settings&amp;tab=advanced&amp;section=webhooks&amp;legacy=true'$class>" . sprintf( translate_nooped_plural( $label, $legacy_webhooks_count ), number_format_i18n( $legacy_webhooks_count ) ) . '</a>';
214 }
215
216 return $status_links;
217 }
218
219 /**
220 * Get bulk actions.
221 *
222 * @return array
223 */
224 protected function get_bulk_actions() {
225 return array(
226 'delete' => __( 'Delete permanently', 'woocommerce' ),
227 );
228 }
229
230 /**
231 * Process bulk actions.
232 */
233 public function process_bulk_action() {
234 $action = $this->current_action();
235 $webhooks = isset( $_REQUEST['webhook'] ) ? array_map( 'absint', (array) $_REQUEST['webhook'] ) : array(); // WPCS: input var okay, CSRF ok.
236
237 if ( false !== $action ) {
238 check_admin_referer( 'woocommerce-settings' );
239
240 if ( ! current_user_can( 'manage_woocommerce' ) ) {
241 wp_die( esc_html__( 'You do not have permission to edit Webhooks', 'woocommerce' ) );
242 }
243
244 if ( 'delete' === $action ) {
245 WC_Admin_Webhooks::bulk_delete( $webhooks );
246 }
247 }
248 }
249
250 /**
251 * Generate the table navigation above or below the table.
252 * Included to remove extra nonce input.
253 *
254 * @param string $which The location of the extra table nav markup: 'top' or 'bottom'.
255 */
256 protected function display_tablenav( $which ) {
257 echo '<div class="tablenav ' . esc_attr( $which ) . '">';
258
259 if ( $this->has_items() ) {
260 echo '<div class="alignleft actions bulkactions">';
261 $this->bulk_actions( $which );
262 echo '</div>';
263 }
264
265 $this->extra_tablenav( $which );
266 $this->pagination( $which );
267 echo '<br class="clear" />';
268 echo '</div>';
269 }
270
271 /**
272 * Search box.
273 *
274 * @param string $text Button text.
275 * @param string $input_id Input ID.
276 */
277 public function search_box( $text, $input_id ) {
278 if ( empty( $_REQUEST['s'] ) && ! $this->has_items() ) { // WPCS: input var okay, CSRF ok.
279 return;
280 }
281
282 $input_id = $input_id . '-search-input';
283 $search_query = isset( $_REQUEST['s'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['s'] ) ) : ''; // WPCS: input var okay, CSRF ok.
284
285 echo '<p class="search-box">';
286 echo '<label class="screen-reader-text" for="' . esc_attr( $input_id ) . '">' . esc_html( $text ) . ':</label>';
287 echo '<input type="search" id="' . esc_attr( $input_id ) . '" name="s" value="' . esc_attr( $search_query ) . '" />';
288 submit_button(
289 $text,
290 '',
291 '',
292 false,
293 array(
294 'id' => 'search-submit',
295 )
296 );
297 echo '</p>';
298 }
299
300 /**
301 * Prepare table list items.
302 */
303 public function prepare_items() {
304 $per_page = $this->get_items_per_page( 'woocommerce_webhooks_per_page' );
305 $current_page = $this->get_pagenum();
306
307 // Query args.
308 $args = array(
309 'limit' => $per_page,
310 'offset' => $per_page * ( $current_page - 1 ),
311 );
312
313 // Handle the status query.
314 if ( ! empty( $_REQUEST['status'] ) ) { // WPCS: input var okay, CSRF ok.
315 $args['status'] = sanitize_key( wp_unslash( $_REQUEST['status'] ) ); // WPCS: input var okay, CSRF ok.
316 }
317
318 if ( ! empty( $_REQUEST['s'] ) ) { // WPCS: input var okay, CSRF ok.
319 $args['search'] = sanitize_text_field( wp_unslash( $_REQUEST['s'] ) ); // WPCS: input var okay, CSRF ok.
320 }
321
322 $args['paginate'] = true;
323
324 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
325 if ( 'true' === sanitize_key( wp_unslash( $_REQUEST['legacy'] ?? null ) ) ) {
326 $args['api_version'] = -1;
327 }
328
329 // Get the webhooks.
330 $data_store = WC_Data_Store::load( 'webhook' );
331 $webhooks = $data_store->search_webhooks( $args );
332 $this->items = array_map( 'wc_get_webhook', $webhooks->webhooks );
333
334 // Set the pagination.
335 $this->set_pagination_args(
336 array(
337 'total_items' => $webhooks->total,
338 'per_page' => $per_page,
339 'total_pages' => $webhooks->max_num_pages,
340 )
341 );
342 }
343 }
344