I’m trying to create a function to redirect users to the login page if they are not logged in for some pages, this is my code:
add_action( 'init', function() { if ( is_user_logged_in()) //déjà identifié return; if (preg_match('#secured-page#', $_SERVER['REQUEST_URI'])) { header( 'location: /wp-login.php' ); exit(); } });
As it didn’t work and I tried every simplifications I tried to add a print "hello"
at the beginning of the parent and child theme functions.php
nothing is printed if the user is not logged in.
Aren’t theme functions supposed to be called everywhere ?
Advertisement
Answer
I forgot I had a cache extension, then when I was logged in the cache was not used but in the other case the server was serving me the cached page which looked like if the function.php was not called. The solution was to clear the cache.