How to run flush_rewrite_rules on activation after i register my custom post type using WordPress Boilerplate Plugin

I have created a plugin that register a new CPT but it doesnt work because i have to flush_rewrite_rules()
(i can do this by going into the permalink setting page and save, but its not the right way)

I have read inside the wordpress codex that i have to flush_rewrite_rules() on activation, but its not working cuz flush_rewrite_rules() runs before i register the CPT, to work it must run after…

I am using this

And it has a class that runs on activation of the plugin i have added there this flush_rewrite_rules()


The boilerplate i have used is already structured with activation/deactivation classes, for example

and inside class-l-erbario-activator.php i have


/admin/class-l-erbario-admin.php -> here i register the CPT

/includes/class-l-erbario.php -> and here i add the add_action with the CPT