I am working with Gravity Forms and the Webhooks Add-on, but those may or may not be relevant to my question.
If I have an action defined with a hook in my functions.php file, is there an easy way of triggering it manually without the actual hook happening (for debugging)?
To elaborate: I have a webhook to a 3rd party server setup with a Gravity Form. However, I am having two problems with it. The first is that I'm getting a cuRL error 60 which I have a request to DreamHost to resolve. The second is that the webhooks don't trigger when I want them to (when a callback for a Stripe/PayPal payment marks an entry as complete). I've added this code to my functions.php file:
add_action( 'gform_post_payment_completed', function ( $form, $entry_id ) {
if ( function_exists( 'gf_webhooks' ) ) {
$entry = GFAPI::get_entry( $entry_id );
gf_webhooks()->maybe_process_feed( $entry, $form );
gf_feed_processor()->save()->dispatch();
}
}, 10, 2 );
So, in trying to test/debug this, how can I trigger this action without 'gform_post_payment_completed' being called?
I am working with Gravity Forms and the Webhooks Add-on, but those may or may not be relevant to my question.
If I have an action defined with a hook in my functions.php file, is there an easy way of triggering it manually without the actual hook happening (for debugging)?
To elaborate: I have a webhook to a 3rd party server setup with a Gravity Form. However, I am having two problems with it. The first is that I'm getting a cuRL error 60 which I have a request to DreamHost to resolve. The second is that the webhooks don't trigger when I want them to (when a callback for a Stripe/PayPal payment marks an entry as complete). I've added this code to my functions.php file:
add_action( 'gform_post_payment_completed', function ( $form, $entry_id ) {
if ( function_exists( 'gf_webhooks' ) ) {
$entry = GFAPI::get_entry( $entry_id );
gf_webhooks()->maybe_process_feed( $entry, $form );
gf_feed_processor()->save()->dispatch();
}
}, 10, 2 );
So, in trying to test/debug this, how can I trigger this action without 'gform_post_payment_completed' being called?
Share Improve this question asked Apr 20, 2020 at 18:09 Nick MarquesNick Marques 111 bronze badge1 Answer
Reset to default 1You are currently using an anonymous function. The first step would be changing it to a named function so you can retrieve it from the wp_filter
global array, which holds all the registered actions and filters. You'd do it like this:
function payment_test($form, $entry_id){
if ( function_exists( 'gf_webhooks' ) ) {
$entry = GFAPI::get_entry( $entry_id );
gf_webhooks()->maybe_process_feed( $entry, $form );
gf_feed_processor()->save()->dispatch();
}
}
add_action( 'gform_post_payment_completed', 'payment_test', 10, 2 );
// Call it manually by getting the callable from the wp_filter global.
global $wp_filter;
call_user_func_array(
$wp_filter['gform_post_payment_completed']->callbacks[10]['payment_test']['function'],
$args // You have to manually provide the arguments as an array.
);