• So I’m just trying to setup my first custom actions and I can’t get the $identifier parameter to work right.

    if( $identifier !== 'employee_clock_out' ){
        return $return_args;
    }

    Is the code I’m using to determine whether or not to execute the function.

    If my webhook name is ’employee-clock-out’, do I use that or ’employee_clock_out’ or what? Cause I’ve tried both and nothings working. When I remove the identifier statement the rest of the function works just fine.

Viewing 10 replies - 1 through 10 (of 10 total)
  • Plugin Contributor Ironikus

    (@ironikus)

    Hey @engineer614 – thank you for reaching out to us, as well as for using our plugin.
    The identifier is a custom string that is either defined within the query parameters of your webhook URL or within the payload of the request you send.
    In other words: It is independent from the webhook name.
    This is the case since it allows you to use the same callback with multiple definitions within the same webhook URL.

    To make it work, simply define the wpwh_identifier argument either within the URL or within the payload of your request. As a value, you can use an identifier that you check within your if clause.

    If you have any further questions, please let me know. ??

    Thread Starter engineer614

    (@engineer614)

    What’s the format for the custom string?

    `&action=custom_action&wpwh_identifier=”new_shipstation_order”‘

    is this correct? what would my identifier be? because I cant get it to work lol

    Plugin Contributor Ironikus

    (@ironikus)

    As an identifier, you can choose whatever you would like. ?? You just need to check against it within the if clause you wrote.

    From the example you provided, simply remove the double quotes since they’re not necessary:
    &action=custom_action&wpwh_identifier=new_shipstation_order

    As given by your example string, the if clause would look something like this:

    if( $identifier !== 'new_shipstation_order' ){
        return $return_args;
    }
    Thread Starter engineer614

    (@engineer614)

    Thank you very much for the help! Main reason I bought the Pro version of your plugin is because of how I’ve seen you respond to people not only here but across the internet.

    Keep it up customer satisfaction is key!

    Thread Starter engineer614

    (@engineer614)

    You should consider maybe sprucing up the documentation you have for making a custom extension for WP Webhooks, I’m using it to help make a internal business management site for my startup and I feel as though I’ll eventually have quite a handful of custom actions.

    Thread Starter engineer614

    (@engineer614)

    Weird I’m still occasionally having trouble getting the identifier to work…

    ?wpwhpro_action=employee-clock-out&wpwhpro_api_key=SECRET&action=custom_action&wpwh_identifier=update_clockout'
    
    

    /*
    * Function to run when WebHook recieves data
    */
    add_filter( ‘wpwhpro/run/actions/custom_action/return_args’, ‘shiftreport_update_clockout’, 10, 3 );
    function shiftreport_update_clockout( $return_args, $identifier, $response_body ) {

    $DebugEnabled = TRUE;
    if ($DebugEnabled) {
    echo ‘Beginning of Function – ‘;
    }

    /*******************************************************
    * If the identifier doesn’t match, exit the function
    *******************************************************/
    if( $identifier !== ‘update_clockout’ ){
    echo ‘Identifier is not valid’;
    return $return_args;
    }

    if ($DebugEnabled) {
    echo ‘Identifier Successfully Validated – ‘;
    }
    `
    I’m using Postman to send test data to the webhook

    https://ibb.co/DYF1G5P

    Here’s a screenshot of the data sent and the response from the webhook

    Thread Starter engineer614

    (@engineer614)

    Well to make things even weirder check this out.

    
    /*
    *  Function to run when WebHook recieves data
    */
    add_filter( 'wpwhpro/run/actions/custom_action/return_args', 'shiftreport_update_clockout', 10, 3 );
    function shiftreport_update_clockout( $return_args, $identifier, $response_body ) {
    	
    	$DebugEnabled = TRUE;
    	if ($DebugEnabled) {
    		echo 'Beginning of Function - ';
    	}
    	
    	echo 'The identifier that was received is: ';
    	echo $identifier;
    	echo '';
    	
    	/*******************************************************
    	 * 	If the identifier doesn't match, exit the function
    	 *******************************************************/
    	if( $identifier !== 'update_clockout' ){
    		echo 'Identifier is not valid';
    		return $return_args;
    	}
    	
    	if ($DebugEnabled) {
    		echo 'Identifier Successfully Validated - ';
    	}
    
    


    ?wpwhpro_action=employee-clock-out&wpwhpro_api_key=SECRET&action=custom_action&wpwh_identifier=update_clockout

    
    Beginning of Function - The identifier that was received is: update_clockout
    Identifier is not valid{
        "success": true,
        "msg": "Custom action was successfully fired."
    }
    
    • This reply was modified 4 years, 3 months ago by engineer614.
    Plugin Contributor Ironikus

    (@ironikus)

    Hey @engineer614 – thanks for sharing all of the details. The last issue is indeed strange and one guess I have might be some kind of PHP/object cache.
    Do you use any caching plugin such as W3T?
    If so, try to turn all of them off and give it a try then – My guess is that there’s some caching in place that returns pre-executed variables.
    Thanks already a lot.

    Thread Starter engineer614

    (@engineer614)

    So I’m running this on a site meant for internal use by me and my employees only so there’s no caching or optimization plugins whatsoever, I will try turning off the standard wordpress caching and see if that helps.

    I really don’t have too many plugins on this site either. For the most part I just have BuddyPress, bbPress, AutomatorWP, Gravity Forms and Pods. Couple random plugins but nothing that does anything crazy functionality-wise.

    I am running this on an Amazon EC2 server which is a bit different than your average WordPress user. Since I install all the server’s software packages and whatnot myself there’s definitely the possibility that I could be missing a package, although unlikely.

    If you want I can make a temporary admin account for you and you can take a look.

    Plugin Contributor Ironikus

    (@ironikus)

    Thanks for the feedback @engineer614 – In case we can’t make it work this way, I think there must be anything related to the server config/caching.
    I have this belief since the code above looks correct and the odd of not firing correctly on your check must either be related to that or a weird way of PHP checking the variable in some kind of a different state.

    What you can try to do is to really loosen the if statement:

    if( (string) $identifier != (string) 'update_clockout' ){
    	echo 'Identifier is not valid';
    	return $return_args;
    }

    Please change that part within your code and give it another try.
    If you have any further questions, feel free to let me know. ??

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘[Pro] how to use $identifier with custom action’ is closed to new replies.