• I’ve set up a firebase account so that when a post is made, an alert can show up on our iOS/android apps. The entire sequence works fine, but I can’t figure out how to make it work with wordpress.

    What I need to cause is that when a post is made, the post title and post body (limited to 30 characters or so) get passed to a specific file/URL: https://mydomain.com/sendNotification.php.

    I’ve installed an application on my iMac called Postman. From that app, I can send the “title” and the “body” to that URL and cause the alerts to function.

    I need help or an example to make this happen from within wordpress.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator bcworkz

    (@bcworkz)

    You can use the WP_Http class to make external requests. Do so from a callback hooked to the “{$old_status}_to_{$new_status}” action if you only want notifications of newly published posts (and not updates). I believe the dynamic values resolve to “draft_to_publish”, but I’ve not double checked this.

    Thread Starter steigw

    (@steigw)

    Where would I do this? Is this a PHP script I’d want to run? Or CSS I’d put in? or is there a specific file I should edit to do this? I’m sort of technical, but a pretty basic programmer, so the more detail you can give me the better! Thank you!

    Moderator bcworkz

    (@bcworkz)

    It would be PHP code. As with any custom PHP code, it could go in your theme’s functions.php file, but even better would be a the same file for a child theme. Alternately, custom PHP code can reside in your own custom plugin. It’s actually even easier to create a new plugin than it is a new child theme. A new file in /wp-content/plugins/ with the appropriate comment header and your PHP code is all that’s needed.

    Specifically for hooking actions, check out the Plugin Handbook. This would also apply equally to themes or child themes. It’s often useful to see how the action is applied in source code. In this case it’s done at line 4458 of wp_transition_post_status().

    For reference, the methods for WP_Http class are listed. You would probably use either get() or post(). Sadly, the docs are quite sparse, mainly useful for examining source code. Hopefully you can find more information through searches. I’m of no help in this respect.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Passing Post data to external file’ is closed to new replies.