1

What's the best method for sending all new Wordpress Posts to an external script on another server?

It needs to include the full post information including the post content, so a simple ping is not sufficient.

I've looked at how Wordpress Plugins work (without having any past experience) and the publish_post and edit_post actions seemed to be along the right lines, but i've had a few issues with the data being sent not being up to date e.g. edit_post sends a post_id I use get_post() and the data provided is the old data.

The other rather large issue with this is that it would probably require using CURL to send the post to the external server, which not all sites will have access to.

The only other solution I can think of is to attach a function to wp_init() to intercept any requests coming from my server. To clarify this would involve my server requesting the WP index with a custom user agent such as "mysite/1.0". If this custom user agent is detected the plugin would output something itself and then exit preventing the standard WP output.

That way I could use the built in ping service to ping my server from wordpress, get the permalink from this ping and then send a request back to WP which will be intercepted by my plugin and output the post as json.

Does this sound feasible?

Is there another commonly used method to send an entire post to an external script that i'm not aware of?

I'm very new to Wordpress and don't actually use it myself, but i've been asked by people who do use Wordpress how they can get their content automatically imported to my site, so I said i'd look at creating a plugin to do so :)

1 Answer 1

2

I think the better way to handle it would be to have the other site scrape the feed for the content. Alternately, you could call an API on the receiving server with every execution of the publish_posts hook, but this would leave you with the issue of not being able to concurrently edit. Another solution is to allow your server to query the WordPress database and pull the data you need from the posts table.

3
  • The problem with this is that it requires my server requesting the wp server at regular intervals via something like a cron job, if I want to stay up to date, which I do. This would have to be done at a minimum of every 5 minutes, which could become alot of work if a large number of sites use it. My solution to this would be to accept pings and then scrape only once i've got the ping with the plugin displaying a custom json encoded page with the information I need for easier scraping. Jan 12, 2012 at 3:37
  • I should add to that, that my reason for asking the question was to see if there was a common approach that others take, to save me some work. I've looked for existing plugins that do something similar but with no luck so far. Jan 12, 2012 at 3:38
  • If that's the case I would definitely go for hooking publish_posts() to send to your server every time a post is made, you'll have to implement something on that side to receive it, but it shouldn't be bad.
    – mor7ifer
    Jan 12, 2012 at 4:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.