
Hello,
I developing custom Gutenberg blocks with ACF by using acf_register_block_type
Used this manual which is really helpful. https://www.advancedcustomfields.com/resources/acf_register_block_type/
However I did not found the best place to put logic which register hooks/filters calls.
For example, I have a block which has button and textbox and when I click on the button it needs to send data entered in the textbox to a server to do validation.
Basically I use
add_action(‘wp_ajax_nopriv_my_validation_api’, my_validation_api’);
As you can see I cannot place this action registration login into template view
‘render_template’ => ‘template-parts/blocks/my_block/template.php’
I had to put it in function.php which I think not the best place as such logic ideally needs to be incapsulated in block itself (additional php file? to do hook/filters and custom logic before rendering a block).
Also when dozens for custom blocks are created – functions.php gets messy with all hook/filter registrations.
The question is what is the best place to put such logic so it would be as a part of a block – not a part of functions.php
Thank you