I've tried reading the documentation and the definitions just elude me. I found this example that works here for my troubles -> https://stackoverflow.com/questions/50286549/how-can-i-store-the-values-from-a-wpform-in-wordpress-to-mysql-database
And while i'm happy that it works, I wish I understood why. I'm just extremely lucky that this code works out the box for my purposes
In my functions.php. I have the add_action and the function. The function does stuff. When I post my form, it works. Why?
I'm NOT using do_action anywhere, so what is it's purpose then and why is add_action working automatically where i'm just adding a hook to a custom function?
Also in the example, the do_action has more params passed. The add_action function has only one, yet i'm able to access it like an array with ease? Honestly I have no clue what is going on. This feels like magic and no attempt at reverse engineering is helping me make sense of this.
Any laymens way of explaining this? Below is reposted the code from the first answer of the question i'm linking at, for simplicity's sake.
do_action from the official plugin doc
do_action( 'wpforms_process_complete', $this->fields, $entry, $form_data, $entry_id );
add_action custom made?
add_action("wpforms_process_complete", 'function_save_custom_form_data');
function function_save_custom_form_data($params) {
foreach($params as $idx=>$item) {
$field_name = $item['name'];
$fiel_value = $item['value'];
// Do whatever you need
}
return true;
}