WordPress Hook of the week #1:
Docs: https://developer.wordpress.org/reference/hooks/init/
init
What it does: fires after WordPress has finished loading but before headers are sent.
php
add_action( 'init', function() { // your magic } );

WordPress Developer Resourcesinit – Hook | Developer.WordPress.orgFires after WordPress has finished loading but before any headers are sent.
commit 9b5f82c