How can i trigger an action manually?

I’m currently working with a Learn Management System and students can earn certificates after they completed a course. This certificate gets generated and has an “action hook” hooked to it, so i can hook in to modify it. My problem is now with the debugging:
Every time i want to test my hook i have to create a user and let them complete the course. Has anyone an idea how to trigger the action manually? This would reduce the debugging time drastically.
Thank you

1 Answer
1

Use do_action, you can just:

do_action( 'my_action');

if your action has a callback function that need arguments say:

function my_callback( $an_array ){
  //use the array for something here
   var_dump($an_array);
}
add_action( 'my_action', 'my_callback' );

you can specify it in the do_action like this:

do_action( 'my_action', array( 'array_for_callback') );

Leave a Comment