wc_is_webhook_valid_topic()
Check if the given topic is a valid webhook topic, a topic is valid if:
- starts with action.woocommerce_ or action.wc_.
- it has a valid resource & event.
Возвращает
true|false.
Использование
wc_is_webhook_valid_topic( $topic );
- $topic(строка) (обязательный)
- Webhook topic.
Список изменений
| С версии 2.2.0 | Введена. |
Код wc_is_webhook_valid_topic() wc is webhook valid topic WC 10.4.2
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;
}