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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.php
woocommerce / includes / admin Last commit date
helper 3 years ago importers 3 years ago list-tables 3 years ago marketplace-suggestions 3 years ago meta-boxes 3 years ago notes 3 years ago plugin-updates 5 years ago reports 3 years ago settings 3 years ago views 3 years ago class-wc-admin-addons.php 3 years ago class-wc-admin-api-keys-table-list.php 6 years ago class-wc-admin-api-keys.php 6 years ago class-wc-admin-assets.php 3 years ago class-wc-admin-attributes.php 3 years ago class-wc-admin-customize.php 5 years ago class-wc-admin-dashboard-setup.php 3 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 4 years ago class-wc-admin-importers.php 5 years ago class-wc-admin-log-table-list.php 5 years ago class-wc-admin-menus.php 3 years ago class-wc-admin-meta-boxes.php 3 years ago class-wc-admin-notices.php 3 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 3 years ago class-wc-admin-profile.php 4 years ago class-wc-admin-reports.php 5 years ago class-wc-admin-settings.php 3 years ago class-wc-admin-setup-wizard.php 4 years ago class-wc-admin-status.php 3 years ago class-wc-admin-taxonomies.php 3 years ago class-wc-admin-webhooks-table-list.php 4 years ago class-wc-admin-webhooks.php 3 years ago class-wc-admin.php 4 years ago wc-admin-functions.php 3 years ago wc-meta-box-functions.php 3 years ago
class-wc-admin-webhooks.php
378 lines
1 <?php
2 /**
3 * WooCommerce Admin Webhooks Class
4 *
5 * @package WooCommerce\Admin
6 * @version 3.3.0
7 */
8
9 defined( 'ABSPATH' ) || exit;
10
11 /**
12 * WC_Admin_Webhooks.
13 */
14 class WC_Admin_Webhooks {
15
16 /**
17 * Initialize the webhooks admin actions.
18 */
19 public function __construct() {
20 add_action( 'admin_init', array( $this, 'actions' ) );
21 add_action( 'woocommerce_settings_page_init', array( $this, 'screen_option' ) );
22 add_filter( 'woocommerce_save_settings_advanced_webhooks', array( $this, 'allow_save_settings' ) );
23 }
24
25 /**
26 * Check if should allow save settings.
27 * This prevents "Your settings have been saved." notices on the table list.
28 *
29 * @param bool $allow If allow save settings.
30 * @return bool
31 */
32 public function allow_save_settings( $allow ) {
33 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
34 if ( ! isset( $_GET['edit-webhook'] ) ) {
35 return false;
36 }
37
38 return $allow;
39 }
40
41 /**
42 * Check if is webhook settings page.
43 *
44 * @return bool
45 */
46 private function is_webhook_settings_page() {
47 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
48 return isset( $_GET['page'], $_GET['tab'], $_GET['section'] ) && 'wc-settings' === $_GET['page'] && 'advanced' === $_GET['tab'] && 'webhooks' === $_GET['section'];
49 }
50
51 /**
52 * Save method.
53 */
54 private function save() {
55 check_admin_referer( 'woocommerce-settings' );
56
57 if ( ! current_user_can( 'manage_woocommerce' ) ) {
58 wp_die( esc_html__( 'You do not have permission to update Webhooks', 'woocommerce' ) );
59 }
60
61 $errors = array();
62 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
63 $webhook_id = isset( $_POST['webhook_id'] ) ? absint( $_POST['webhook_id'] ) : 0;
64 $webhook = new WC_Webhook( $webhook_id );
65
66 // Name.
67 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
68 if ( ! empty( $_POST['webhook_name'] ) ) {
69 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
70 $name = sanitize_text_field( wp_unslash( $_POST['webhook_name'] ) );
71 } else {
72 $name = sprintf(
73 /* translators: %s: date */
74 __( 'Webhook created on %s', 'woocommerce' ),
75 // @codingStandardsIgnoreStart
76 (new DateTime('now'))->format( _x( 'M d, Y @ h:i A', 'Webhook created on date parsed by DateTime::format', 'woocommerce' ) )
77 // @codingStandardsIgnoreEnd
78 );
79 }
80
81 $webhook->set_name( $name );
82
83 if ( ! $webhook->get_user_id() ) {
84 $webhook->set_user_id( get_current_user_id() );
85 }
86
87 // Status.
88 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
89 $webhook->set_status( ! empty( $_POST['webhook_status'] ) ? sanitize_text_field( wp_unslash( $_POST['webhook_status'] ) ) : 'disabled' );
90
91 // Delivery URL.
92 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
93 $delivery_url = ! empty( $_POST['webhook_delivery_url'] ) ? esc_url_raw( wp_unslash( $_POST['webhook_delivery_url'] ) ) : '';
94
95 if ( wc_is_valid_url( $delivery_url ) ) {
96 $webhook->set_delivery_url( $delivery_url );
97 }
98
99 // Secret.
100 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
101 $secret = ! empty( $_POST['webhook_secret'] ) ? sanitize_text_field( wp_unslash( $_POST['webhook_secret'] ) ) : wp_generate_password( 50, true, true );
102 $webhook->set_secret( $secret );
103
104 // Topic.
105 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
106 if ( ! empty( $_POST['webhook_topic'] ) ) {
107 $resource = '';
108 $event = '';
109
110 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
111 switch ( $_POST['webhook_topic'] ) {
112 case 'action':
113 $resource = 'action';
114 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
115 $event = ! empty( $_POST['webhook_action_event'] ) ? sanitize_text_field( wp_unslash( $_POST['webhook_action_event'] ) ) : '';
116 break;
117
118 default:
119 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
120 list( $resource, $event ) = explode( '.', sanitize_text_field( wp_unslash( $_POST['webhook_topic'] ) ) );
121 break;
122 }
123
124 $topic = $resource . '.' . $event;
125
126 if ( wc_is_webhook_valid_topic( $topic ) ) {
127 $webhook->set_topic( $topic );
128 } else {
129 $errors[] = __( 'Webhook topic unknown. Please select a valid topic.', 'woocommerce' );
130 }
131 }
132
133 // API version.
134 $rest_api_versions = wc_get_webhook_rest_api_versions();
135 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
136 $webhook->set_api_version( ! empty( $_POST['webhook_api_version'] ) ? sanitize_text_field( wp_unslash( $_POST['webhook_api_version'] ) ) : end( $rest_api_versions ) );
137
138 $webhook->save();
139
140 // Run actions.
141 do_action( 'woocommerce_webhook_options_save', $webhook->get_id() );
142 if ( $errors ) {
143 // Redirect to webhook edit page to avoid settings save actions.
144 wp_safe_redirect( admin_url( 'admin.php?page=wc-settings&tab=advanced&section=webhooks&edit-webhook=' . $webhook->get_id() . '&error=' . rawurlencode( implode( '|', $errors ) ) ) );
145 exit();
146 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
147 } elseif ( isset( $_POST['webhook_status'] ) && 'active' === $_POST['webhook_status'] && $webhook->get_pending_delivery() ) {
148 // Ping the webhook at the first time that is activated.
149 $result = $webhook->deliver_ping();
150
151 if ( is_wp_error( $result ) ) {
152 // Redirect to webhook edit page to avoid settings save actions.
153 wp_safe_redirect( admin_url( 'admin.php?page=wc-settings&tab=advanced&section=webhooks&edit-webhook=' . $webhook->get_id() . '&error=' . rawurlencode( $result->get_error_message() ) ) );
154 exit();
155 }
156 }
157
158 // Redirect to webhook edit page to avoid settings save actions.
159 wp_safe_redirect( admin_url( 'admin.php?page=wc-settings&tab=advanced&section=webhooks&edit-webhook=' . $webhook->get_id() . '&updated=1' ) );
160 exit();
161 }
162
163 /**
164 * Bulk delete.
165 *
166 * @param array $webhooks List of webhooks IDs.
167 */
168 public static function bulk_delete( $webhooks ) {
169 foreach ( $webhooks as $webhook_id ) {
170 $webhook = new WC_Webhook( (int) $webhook_id );
171 $webhook->delete( true );
172 }
173
174 $qty = count( $webhooks );
175 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
176 $status = isset( $_GET['status'] ) ? '&status=' . sanitize_text_field( wp_unslash( $_GET['status'] ) ) : '';
177
178 // Redirect to webhooks page.
179 wp_safe_redirect( admin_url( 'admin.php?page=wc-settings&tab=advanced&section=webhooks' . $status . '&deleted=' . $qty ) );
180 exit();
181 }
182
183 /**
184 * Delete webhook.
185 */
186 private function delete() {
187 check_admin_referer( 'delete-webhook' );
188
189 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
190 if ( isset( $_GET['delete'] ) ) {
191 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
192 $webhook_id = absint( $_GET['delete'] );
193
194 if ( $webhook_id ) {
195 $this->bulk_delete( array( $webhook_id ) );
196 }
197 }
198 }
199
200 /**
201 * Webhooks admin actions.
202 */
203 public function actions() {
204 if ( $this->is_webhook_settings_page() ) {
205 // Save.
206 // phpcs:ignore WordPress.Security.NonceVerification.Missing
207 if ( isset( $_POST['save'] ) && isset( $_POST['webhook_id'] ) ) {
208 $this->save();
209 }
210
211 // Delete webhook.
212 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
213 if ( isset( $_GET['delete'] ) ) {
214 $this->delete();
215 }
216 }
217 }
218
219 /**
220 * Page output.
221 */
222 public static function page_output() {
223 // Hide the save button.
224 $GLOBALS['hide_save_button'] = true;
225
226 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
227 if ( isset( $_GET['edit-webhook'] ) ) {
228 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
229 $webhook_id = absint( $_GET['edit-webhook'] );
230 $webhook = new WC_Webhook( $webhook_id );
231
232 include __DIR__ . '/settings/views/html-webhooks-edit.php';
233 return;
234 }
235
236 self::table_list_output();
237 }
238
239 /**
240 * Notices.
241 */
242 public static function notices() {
243 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
244 if ( isset( $_GET['deleted'] ) ) {
245 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
246 $deleted = absint( $_GET['deleted'] );
247
248 /* translators: %d: count */
249 WC_Admin_Settings::add_message( sprintf( _n( '%d webhook permanently deleted.', '%d webhooks permanently deleted.', $deleted, 'woocommerce' ), $deleted ) );
250 }
251
252 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
253 if ( isset( $_GET['updated'] ) ) {
254 WC_Admin_Settings::add_message( __( 'Webhook updated successfully.', 'woocommerce' ) );
255 }
256
257 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
258 if ( isset( $_GET['created'] ) ) {
259 WC_Admin_Settings::add_message( __( 'Webhook created successfully.', 'woocommerce' ) );
260 }
261
262 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
263 if ( isset( $_GET['error'] ) ) {
264 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
265 foreach ( explode( '|', sanitize_text_field( wp_unslash( $_GET['error'] ) ) ) as $message ) {
266 WC_Admin_Settings::add_error( trim( $message ) );
267 }
268 }
269 }
270
271 /**
272 * Add screen option.
273 */
274 public function screen_option() {
275 global $webhooks_table_list;
276
277 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
278 if ( ! isset( $_GET['edit-webhook'] ) && $this->is_webhook_settings_page() ) {
279 $webhooks_table_list = new WC_Admin_Webhooks_Table_List();
280
281 // Add screen option.
282 add_screen_option(
283 'per_page',
284 array(
285 'default' => 10,
286 'option' => 'woocommerce_webhooks_per_page',
287 )
288 );
289 }
290 }
291
292 /**
293 * Table list output.
294 */
295 private static function table_list_output() {
296 global $webhooks_table_list;
297
298 echo '<h2 class="wc-table-list-header">' . esc_html__( 'Webhooks', 'woocommerce' ) . ' <a href="' . esc_url( admin_url( 'admin.php?page=wc-settings&tab=advanced&section=webhooks&edit-webhook=0' ) ) . '" class="add-new-h2">' . esc_html__( 'Add webhook', 'woocommerce' ) . '</a></h2>';
299
300 // Get the webhooks count.
301 $data_store = WC_Data_Store::load( 'webhook' );
302 $num_webhooks = $data_store->get_count_webhooks_by_status();
303 $count = array_sum( $num_webhooks );
304
305 if ( 0 < $count ) {
306 $webhooks_table_list->process_bulk_action();
307 $webhooks_table_list->prepare_items();
308
309 echo '<input type="hidden" name="page" value="wc-settings" />';
310 echo '<input type="hidden" name="tab" value="advanced" />';
311 echo '<input type="hidden" name="section" value="webhooks" />';
312
313 $webhooks_table_list->views();
314 $webhooks_table_list->search_box( __( 'Search webhooks', 'woocommerce' ), 'webhook' );
315 $webhooks_table_list->display();
316 } else {
317 echo '<div class="woocommerce-BlankState woocommerce-BlankState--webhooks">';
318 ?>
319 <h2 class="woocommerce-BlankState-message"><?php esc_html_e( 'Webhooks are event notifications sent to URLs of your choice. They can be used to integrate with third-party services which support them.', 'woocommerce' ); ?></h2>
320 <a class="woocommerce-BlankState-cta button-primary button" href="<?php echo esc_url( admin_url( 'admin.php?page=wc-settings&tab=advanced&section=webhooks&edit-webhook=0' ) ); ?>"><?php esc_html_e( 'Create a new webhook', 'woocommerce' ); ?></a>
321 <style type="text/css">#posts-filter .wp-list-table, #posts-filter .tablenav.top, .tablenav.bottom .actions { display: none; }</style>
322 <?php
323 }
324 }
325
326 /**
327 * Logs output.
328 *
329 * @deprecated 3.3.0
330 * @param WC_Webhook $webhook Deprecated.
331 */
332 public static function logs_output( $webhook = 'deprecated' ) {
333 wc_deprecated_function( 'WC_Admin_Webhooks::logs_output', '3.3' );
334 }
335
336 /**
337 * Get the webhook topic data.
338 *
339 * @param WC_Webhook $webhook Webhook instance.
340 *
341 * @return array
342 */
343 public static function get_topic_data( $webhook ) {
344 $topic = $webhook->get_topic();
345 $event = '';
346 $resource = '';
347
348 if ( $topic ) {
349 list( $resource, $event ) = explode( '.', $topic );
350
351 if ( 'action' === $resource ) {
352 $topic = 'action';
353 } elseif ( ! in_array( $resource, array( 'coupon', 'customer', 'order', 'product' ), true ) ) {
354 $topic = 'custom';
355 }
356 }
357
358 return array(
359 'topic' => $topic,
360 'event' => $event,
361 'resource' => $resource,
362 );
363 }
364
365 /**
366 * Get the logs navigation.
367 *
368 * @deprecated 3.3.0
369 * @param int $total Deprecated.
370 * @param WC_Webhook $webhook Deprecated.
371 */
372 public static function get_logs_navigation( $total, $webhook ) {
373 wc_deprecated_function( 'WC_Admin_Webhooks::get_logs_navigation', '3.3' );
374 }
375 }
376
377 new WC_Admin_Webhooks();
378