Setting a custom header doesn’t work for all requests
-
Hi
I’m trying to save the authenticated user in a header, but this is not done for all requests; it will be only done for the rendered html pages, but not for the images, css, and other type of media.
I have tried several filters and functions, but the only one that is partially working is this one:
add_action('init', 'add_auth_user_header'); function add_auth_user_header() { $auth_user = wp_get_current_user(); $auth_user_login = 'Anonymous'; if ($auth_user->ID != 0) { $auth_user_login = $auth_user->user_login; } header( 'X-WPUser: ' . $auth_user_login); }
First I put that action into a “Code Snippet” (WordPress plugin); the header was as I said partially set. So, I tried to directly put the code into the functions.php file of the WordPress theme, but the results were the same. Please also note that I completely disabled all the cache mechanism; I heard that catching may be an issue.
I now that there are also places for actions and filters for setting headers: send_headers and wp_headers, but none of them worked for me. The header wasn’t set.
Does anybody have an idea?
Thanks in advanced
Best regards
Josef
- The topic ‘Setting a custom header doesn’t work for all requests’ is closed to new replies.