Skip to content

Broadcasts: Use Webhooks - #1247

Open
n7studios wants to merge 9 commits into
mainfrom
webhooks-broadcasts
Open

n7studios wants to merge 9 commits into
mainfrom
webhooks-broadcasts

Conversation

@n7studios

Copy link
Copy Markdown
Contributor

Summary

Replaces the hourly WordPress Cron event (that imported Broadcasts) with a Kit webhook, so Broadcasts are imported as soon as they're published in Kit. This also removes the reliance on WordPress Cron, which doesn't run reliably on low-traffic sites or when DISABLE_WP_CRON is set.

Screenshot 2026-10-19 at 12 45 55
  • Adds a kit/v1/broadcasts/webhook REST API route. It receives post.published events from Kit, verifies the signature, ignores duplicate events and imports new Broadcasts.
  • Registers the webhook endpoint in Kit when the Broadcasts import is enabled. Deletes it when the import is disabled, the Plugin is disconnected from Kit or the Plugin is deactivated.
  • Settings > Kit > Broadcasts:
    • adds a Webhook field showing the endpoint's status in Kit, with a Register / Re-register webhook button;
    • Import now imports Broadcasts immediately, instead of scheduling a Cron event.
  • Removes ConvertKit_Cron and the convertkit_resource_refresh_posts Cron event; the event is unscheduled on Plugin update.

Testing

  • BroadcastsWebhookTest: registration, deletion, status, receiving events (valid, duplicate, invalid/expired signature, import disabled) and Plugin update routines.
  • BroadcastsToPostsCest: uses Import now instead of running the Cron event.
  • BroadcastsToPostsSettingsCest: checks the Webhook field, and that registration fails gracefully on a local site.
  • Removed Cron-related tests, the WPCron helper, and wp-crontrol from the test group.

Checklist

@n7studios n7studios added this to the 3.4.8 milestone Oct 19, 2026
@n7studios n7studios self-assigned this Oct 19, 2026
@github-actions

Copy link
Copy Markdown

WordPress Playground

🚀 Your PR has been built and is ready for testing in WordPress Playground!

Click here to test your changes in WordPress Playground

@n7studios
n7studios marked this pull request as ready for review October 20, 2026 06:33
@n7studios
n7studios requested review from a team, ciccio-kit and noelherrick and removed request for a team October 20, 2026 06:33
// Check that we're using the Kit WordPress Libraries 2.8.0 or higher.
$api = new ConvertKit_API_V4( CONVERTKIT_OAUTH_CLIENT_ID, CONVERTKIT_OAUTH_CLIENT_REDIRECT_URI );
if ( ! method_exists( $api, 'verify_webhook_signature' ) ) { // @phpstan-ignore-line Older WordPress Libraries won't have this function.
return new WP_REST_Response( null, 503 );

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

503s are temporary errors - shouldn't this be a 501?


// Refresh the Posts resource, which imports new Broadcasts.
if ( $import ) {
$posts = new ConvertKit_Resource_Posts( 'broadcasts_webhook' );

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How heavy is this call vs. something that imports it one by one or with a list of IDs? We have the post(s) to import

@n7studios n7studios modified the milestones: 3.4.8, 3.5.0 Nov 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants