2

I want to use this service OnWebChange to monitor when a website changes and change mine accordingly. It would notify me via a URL callback to my website URL with a HTTP POST method. What tools/API/plugins do I use to "catch" those POST's? Have searched a lot and found only how to make POST, but not "catch" them when POST comes from another website. If I had access to apache I could install a module to dump POST, however I'm using Wordpress with no access to it.

  • What does the URL look like? You can probably accomplish this by creating a page template that will read the url, parse the values, and insert into a post. I doubt that you will find some plugin that works out of the box. – gdaniel May 15 '15 at 19:44
  • It will be my website's URL. The thing is I don't know what that OnWebChange service will send me with that POST. I just don't know how to "catch" those POSTs. It's ok if there's no plugin, I need anything because I'm stuck. – user2879175 May 15 '15 at 19:55
  • I did this before by installing a module to apache to dump POSTs to a file. However now I don't have access to apache. – user2879175 May 15 '15 at 19:58
  • It's hard to help if you don't know what the URL looks like or how their system works. Try gathering information from their support first and then come back and post it here. Otherwise the question become irrelevant because its not about WordPress but about a third-party service. – gdaniel May 15 '15 at 19:58
  • As far as I understand I don't really need to understand much about their system. I just need to know when I receive a POST. To put it simply... If I make a CURL --data "someText" www.mywebsite.com. How do I retrieve that someText when I get it in WP? – user2879175 May 15 '15 at 20:02
2

That's pretty simple, just use your website home url :)

After that, just fire an action when the page is loaded via POST HTTP method and hook with a callback.

add_action( 'wp_loaded', function() {
   if ( $_SERVER['REQUEST_METHOD'] === 'POST' ) {
      // fire the custom action
      do_action('onchangeapi', new PostListener($_POST));
   }
} );

And now the listener class

class PostListener {

   private $valid = false;

   /**
    * @param array $postdata $_POST array
    */
   public function __construct(array $postdata) {
       $this->valid = $this->validatePostData($postdata);
   }

   /**
    * Runs on 'onchangeapi' action
    */
   public function __invoke() {
      if ($this->valid) {
          // do whatever you need to do 
          exit();
      }
   }

   /**
    * @param array $postdata $_POST array
    * @return bool
    */
   private function validatePostData(array $postdata) {
      // check here the $_POST data, e.g. if the post data actually comes
      // from the api, autentication and so on
   } 
}
| improve this answer | |

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.