Install
Upload it under Plugins → Add New Plugin → Upload Plugin, then activate.
Install straight from GitHub with WP-CLI:
wp plugin install https://github.com/shakewellagency/shakewell-nextjs-revalidate/releases/download/v0.1.0/shakewell-nextjs-revalidate.zipMade by Shakewell. Free and open source, built and maintained by the Shakewell team.
Free, GPL-2.0-or-later WordPress plugin for headless sites. When an editor publishes, updates, unpublishes, trashes or deletes content, or changes a menu, a site setting, a term or a media item, it tells your Next.js front end which pages and content types to revalidate, with one signed request per save. Setup, every setting and the External services statement are in readme.txt.
Not affiliated with, endorsed by or sponsored by Vercel. "Next.js" is a trademark of Vercel, Inc., used here only to say which front end the plugin talks to.
What it does
- Collects the changes of a PHP request and sends one signed
POSTat shutdown, after the editor's response is finished when PHP-FPM allows, so a save never waits for it and an error in it cannot break it. - Fails closed: with no endpoint or secret it sends nothing.
- Never logs the secret or the request body. The log line has counts, scope, HTTP status, reason and event id.
- Retries an uncertain send up to three times through wp-cron, with the same event id and body, so the front end can treat it as a repeat.
- Names what changed in a body the front end can act on:
{"scope":"page","paths":[...],"items":[...],"types":[...]},{"scope":"items"},{"scope":"types"},{"scope":"menus"}or{"scope":"all"}, plus log-only detail.
Quick start
In wp-config.php or the environment:
define( 'SHAKEWELL_NEXTJS_REVALIDATE_URL', 'https://frontend.example/api/revalidate' );
define( 'SHAKEWELL_NEXTJS_REVALIDATE_SECRET', '<a random secret of at least 32 characters>' );
define( 'SHAKEWELL_NEXTJS_REVALIDATE_ENVIRONMENT', 'production' ); // part of the signed message, default wp_get_environment_type()
Then tell it which pages a content type also appears on:
add_filter( 'shakewell_nextjs_revalidate_listings', fn() => array( 'book' => array( '/books/' ) ) );
The request is signed as sha256= plus the hex HMAC-SHA256 of <environment>.<timestamp>.<event>. followed by the exact body, with the headers x-revalidate-timestamp, x-revalidate-event and x-revalidate-signature. The full list of settings is in readme.txt.
Work on it
composer install
npm ci
npm run env:start # WordPress at http://localhost:8922
npm test # PHPUnit in the test container, fake HTTP, no network
composer lint
npm run plugin-check
Release
- Bump the version in the plugin header,
readme.txt(Stable tag) and theVERSIONconstant, and add a changelog line. - Tag
vX.Y.Zand push. The release workflow checks the three versions match and attachesshakewell-nextjs-revalidate.zipto a GitHub release.
Made by Shakewell
This plugin is one of a family of free WordPress plugins from Shakewell. Each one does one job, keeps its dependencies small and is released under GPL-2.0-or-later.
Use it, fork it and send fixes. To have it set up on your site, or to have a plugin built, talk to Shakewell.
More from Shakewell:
- Shakewell Activity Log
- Shakewell Multiple Authors
- Shakewell Clone Posts
- Shakewell Connector for Klaviyo and Gravity Forms
- Shakewell Media Offload for Amazon S3
- Shakewell Redirects
- Shakewell Two-way Relationships for ACF
- Shakewell Single Sign-On (SAML)
- Shakewell Mailer for Amazon SES
- Shakewell Sitemap
- Shakewell Error Reporting for Sentry
- Shakewell plugin template, the starting point for every plugin
Releases
1 release. Each count is every asset in that release; expand a row for the breakdown.