Skip to main content

Send your add-on’s own events through Benecaster’s webhook

Free Intermediate

Your add-on gets the podcaster’s existing webhook — their URL, signing secret, retries and delivery log — without building any of it. Register each event with benecaster_register_webhook_event() from the bootstrap you pass to benecaster_register_addon(), under your own catalog slug, then send it with benecaster_send_webhook_event() when the thing happens. Put your record ID in the body so a receiver can refer back to it.

Code

<?php
add_action( 'benecaster_boot', function ( \Benecaster\Container $container ) {
    benecaster_register_addon( 'my-addon', static function (): void {
        benecaster_register_webhook_event( 'my-addon', 'my-addon.booking.confirmed', [
            'label' => __( 'A booking is confirmed', 'my-addon' ),
        ] );

        add_action( 'my_addon_booking_confirmed', static function ( int $booking_id, int $show_id, int $user_id ): void {
            benecaster_send_webhook_event( 'my-addon', 'my-addon.booking.confirmed', $show_id, [
                'booking_id' => $booking_id,             // your record id, as {noun}_id
                'starts_at'  => gmdate( 'c', (int) get_post_meta( $booking_id, 'starts_at', true ) ),
            ], $user_id );                               // 0 when no WordPress user is involved
        }, 10, 3 );
    } );
} );

View on GitHub →

Hooks Used

Need this built rather than just documented? See our services →