I assume it is best to have webhooks that run from like say thrivecart, or other processors, execute code from a plugin, so that updates do not overwrite custom coding...

I've never created a plugin before, and just learned how to create a very basic plugin.

So I've done that. My question is, how do I have a webhook execute it on callback?

Say something like S2member does it:

google.com/?s2membersomethingorother=1 (removed the https to keep it from creating a link)

is that the way, then have WP listen for that value, and if it exists, execute that code in the plugin?

But how do I get WP to listen and not quit listening after updates?

Is there a best practice for it?

I need a simple few lines of code to check if the user is valid then upgrade their membership role. I have the code for S2Member to check it all, but no idea how to get WP to execute it.

Can someone point me to a resource where I can learn that?

I've scoured the API and scripting stuff, but cannot seem to find what I'm looking for.

I'd appreciate any assistance you can offer.

My best, -Richard

  • I forgot about mu-plugins - would it be best to put the code in there? if so, how do I get a hook to execute it? – Rich Sep 19 '19 at 17:00
  • I think I got it... I can put any file in the mu-plugins folder... then have it check if $_REQUEST['whateveriwant'] exists, if it does, then execute code. If not, then it is not a call from the webhook... and just do nothing... that is a simple check, and should not bog down the system... I don't think... what do you think? – Rich Sep 19 '19 at 18:55

You don't need to create an extra file for that. Simply place something like the following into your themes functions.php file:

function grab_my_very_own_webhook(){

    if( ! isset( $_GET['whateveriwant'] ) ){

    //create your own logic here

add_action( 'init', 'grab_my_very_own_webhook' );

In case you want to grab some data that is sent by the webhook, you need to catch it and validate it properly. There's a plugin that takes that work from you nicely: WP Webhooks

WP Webhooks will catch the data for you and you simply need to write an extension where you handle the data you want to use. They have a custom plugin template available, which you can use to create your own endpoint to use the validated data.

| 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.