wc_is_webhook_valid_topic

Check if the given topic is a valid webhook topic, a topic is valid if:.

Description

wc_is_webhook_valid_topic( (string) $topic ); 

+ starts with action.woocommerce_ or action.wc_.. + it has a valid resource & event.

Parameters (1)

0. $topic (string)
Webhook topic

Usage

  1. if ( !function_exists( 'wc_is_webhook_valid_topic' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'woocommerce/includes/wc-conditional-functions.php'; 
  3.  
  4. // webhook topic 
  5. $topic = ''; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = wc_is_webhook_valid_topic($topic); 
  9.  

Defined (1)

The function is defined in the following location(s).

/includes/wc-conditional-functions.php  
  1. function wc_is_webhook_valid_topic( $topic ) { 
  2.  
  3. // Custom topics are prefixed with woocommerce_ or wc_ are valid 
  4. if ( 0 === strpos( $topic, 'action.woocommerce_' ) || 0 === strpos( $topic, 'action.wc_' ) ) { 
  5. return true; 
  6.  
  7. @list( $resource, $event ) = explode( '.', $topic ); 
  8.  
  9. if ( ! isset( $resource ) || ! isset( $event ) ) { 
  10. return false; 
  11.  
  12. $valid_resources = apply_filters( 'woocommerce_valid_webhook_resources', array( 'coupon', 'customer', 'order', 'product' ) ); 
  13. $valid_events = apply_filters( 'woocommerce_valid_webhook_events', array( 'created', 'updated', 'deleted' ) ); 
  14.  
  15. if ( in_array( $resource, $valid_resources ) && in_array( $event, $valid_events ) ) { 
  16. return true; 
  17.  
  18. return false;