wc_is_webhook_valid_topic( string $topic )
Check if the given topic is a valid webhook topic, a topic is valid if:
Description Description
- starts with
action.woocommerce_oraction.wc_. - it has a valid resource & event.
Parameters Parameters
- $topic
-
(Required) Webhook topic.
Return Return
(bool)
Source Source
File: includes/wc-webhook-functions.php
function wc_is_webhook_valid_topic( $topic ) {
$invalid_topics = array(
'action.woocommerce_login_credentials',
'action.woocommerce_product_csv_importer_check_import_file_path',
'action.woocommerce_webhook_should_deliver',
);
if ( in_array( $topic, $invalid_topics, true ) ) {
return false;
}
// Custom topics are prefixed with woocommerce_ or wc_ are valid.
if ( 0 === strpos( $topic, 'action.woocommerce_' ) || 0 === strpos( $topic, 'action.wc_' ) ) {
return true;
}
$data = explode( '.', $topic );
if ( ! isset( $data[0] ) || ! isset( $data[1] ) ) {
return false;
}
$valid_resources = apply_filters( 'woocommerce_valid_webhook_resources', array( 'coupon', 'customer', 'order', 'product' ) );
$valid_events = apply_filters( 'woocommerce_valid_webhook_events', array( 'created', 'updated', 'deleted', 'restored' ) );
if ( in_array( $data[0], $valid_resources, true ) && in_array( $data[1], $valid_events, true ) ) {
return true;
}
return false;
}
Changelog Changelog
| Version | Description |
|---|---|
| 2.2.0 | Introduced. |