Wordpress - Send post data to external (3rd party) service

Wordpress - Send post data to external (3rd party) service

Did you ever want to send Wordpress post data as soon as a post is created, or published, or updated? Maybe even when the post is trashed or deleted? Using Wordpress hooks it's very easy to create a custom wordpress plugin, activate it from the administration area and immediately start sending the data to a 3rd (third) party or a custom external service.

Here's how.

Check out the available Wordpress hooks for your version of Wordpress by clicking here ( https://codex.wordpress.org/Plugin_API/Action_Reference ). In my case I am using version 4.4.

Basically I used the following hooks:

publish_post which is fired every time a post is published.

post_updated is fired whenever the post is updated.

trash_post is fired whenever the post is trashed.

untrash_post is fired whenever the post is restored from the trash.

In certain hooks we have the post object/array so we just need to either relay specific information or the whole post information, which is what I am doing in this case as I want all the information I can get from the post.

Within the hooks it is also possible to get some extra information about the post that might not be provided such as author information, categories, tags, meta information or any other data that might be handled by a plugin and it's not in the post data provided by Wordpress.

After getting and formatting all the data in an array in this case we can forward the data to a custom function so that we can use CURL to post the data to the external service, were we can then parse the data and save it in a database for example or do anything else with it.

Besides the above hooks there are more, maybe even better, hooks that can be used to achieve a specific goal. Refer to the Wordpress API documentation, experiment and test. I used requestb.in to test my POST data and check the information I was sending via Wordpress.

Let me know in the comments if you encounter any issues.