Publishing to WordPress behind a firewall: pull, don't push
If you've ever built a tool that publishes posts to someone else's WordPress site, you've probably met this bug report: "It says published, but nothing showed up." The usual setup is a push. Your service calls POST /wp-
If you've ever built a tool that publishes posts to someone else's WordPress site, you've probably met this bug report: "It says published, but nothing showed up."
The usual setup is a push. Your service calls POST /wp-json/wp/v2/posts on the customer's site, signed in with an Application Password. That works on a plain install. It breaks on a lot of real small-business sites:
- Cloudflare firewall rules that challenge or block
/wp-json/traffic from data-centre IPs - Security plugins that lock down the REST API or rate-limit it
- Managed hosts that switch Application Passwords off entirely
The request never reaches WordPress, so WordPress has nothing to log. Your side gets a 401, a 403 or a timeout. If that happens in a background job at 9:00 on a Monday, the site owner only finds out weeks later when they notice the blog went quiet.
Turn the connection around
The fix we use is to flip the direction. Instead of your server pushing into the site, a small plugin inside the site pulls from your server:
- The plugin stores a connect key (one per site), set once by the owner.
- On a schedule (WP-Cron, every 15 minutes is plenty), it calls your API: "anything due for me?"
- Your API returns the approved posts that are due: title, HTML body, slug, excerpt, meta description, categories.
- The plugin creates each post locally with
wp_insert_post(), sets the SEO fields, then reports back "published, here is the URL".
Because the request starts from inside the site and goes out over HTTPS, the firewall sees ordinary outbound traffic. Nothing to allowlist, no REST API to open, no Application Password to create.
Things that bit us
- WP-Cron only runs when someone visits. On a quiet site, "every 15 minutes" can mean hours. Tell owners how to trigger cron from a real system cron, and show the "last check" time in the plugin screen so they can see it working.
- Make it idempotent. Send a stable ID with each post and store it in post meta. If the plugin times out after inserting but before reporting back, the next run must not create a duplicate.
-
Log failures with the reason. If
wp_insert_post()returns aWP_Error, log the message on the site so the owner sees what went wrong rather than "failed". - Keep the key out of the page source. Store it as an option, never print it in full in the admin screen.
- Let the owner see what's due. A "Connected. Items due: 2" line in the plugin settings saves a lot of support email.
When push is still fine
If you control the site, or the owner can allowlist your IPs, the REST API with an Application Password is simpler and gives you instant publishing. Pull costs you a few minutes of delay. For sites behind security tools you don't control, that delay is a fair trade for posts that actually arrive.
We built this pattern into Rozzpost, where AI does a small business's weekly marketing (blog posts, social posts, review replies and Google rankings) and the owner approves it (by default). The WordPress half is a free plugin on WordPress.org: https://wordpress.org/plugins/rozzpost/ . It needs a Rozzpost account; the Free plan has AI write and publish 3 blog posts a month, no card: https://rozzpost.com/signup.html?utm_source=devto&utm_medium=article&utm_campaign=wp-plugin
Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.