How to run custom action with XenForo Webhooks

As of XFtoWP 1.6, your WordPress website can now be configured to receive Webhooks from your connected XenForo community.

Think of Webhooks as messages sent from your XF site to your WP site when something happens, like when a new message is posted. This enables your websites to stay more closely connected and run more powerful sync actions.

The plugin’s native settings use Webhooks for various features, and you too can run your own custom functions during any Webhook action.

Simply create your own custom function and hook it to the xfwp_webhook_$content_type_$event hook.

The name of this hook is dynamic and can be changed based on the type of content being sent over the Webhook and which action is being taken (new post, deleted post, edited post, etc.).

The example below checks the post content type on the insert event to print a message to the WP Debug Log when a new message is posted on your forums:

/**
 * Print a message to the debug log when an XF Webhook is received.
 */

function my_custom_xf_webhook( $request ) {
	error_log( 'A new post was made!' );
	error_log( print_r( $request, true ) );
}

add_action( 'xfwp_webhook_post_insert', 'my_custom_xf_webhook' );

This function comes with the $request parameter, which contains the data Object from the received Webhook message.

To see all of the content types and events you can capture, edit the Webhooks settings from XenForo to find the keywords under the “Send only specific events” list

Other hook examples:

xfwp_webhook_post_bookmark

xfwp_webhook_user_upgrade_purchase_complete

xfwp_webhook_user_update