0

This post is origin post at https://stackoverflow.com/q/40018619/306719, but got no attention, and I found this site, so I think here maybe the right place, and I will apply for a redirection for the origin post.


I want to provide a http based service to insert new post with extra information, I think wordpress plugin maybe the right place.

However I am not sure how to get started event I read the plugin reference from wordpress.

I think there should be some action like request_recieve where I can registered to intercept the request and do my own job, but I can not find that. Also how to avoid blocking the normal wordpress request.

  • http based service? May be you can try WP rest api. – bravokeyl Oct 14 '16 at 7:21
  • Wordpress provide HTTP_API. Check it. – AddWeb Solution Pvt Ltd Oct 14 '16 at 7:24
  • @bravokeyl: The rest api can not meet my requirement. When I receive a request not only I will validate/insert it to the database but also I will have to do some extra job. And return different response to the client. – hguser Oct 14 '16 at 7:32
  • @AddWebSolutionPvtLtd: I am not going to send http request from wordpress but receive request. – hguser Oct 14 '16 at 7:33
  • @hguser: HTTP_API, all about http transports(i.e. send, retrieve) not only send. Hope you checked Helper Functions section from given HTTP_API link. – AddWeb Solution Pvt Ltd Oct 14 '16 at 7:43
0

Now I use the init hook to add my own process for the request, and then check the request should be handled by the plugin, if yes, process and exit, if not do nothing. Like this:

add_action('init',function(){
  if(should_intercepte_the_request()){
    //process that.
    //exit
    die("foo");
  }else{
    //do nothing
  }
});

Then you can access the http by: http://localhost

It is recommended that you check the request method, and some access token to make sure the requests are sent by a trusted source.

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.