user validation and redirect cause blank page
-
Hi,
I’m trying to tweak my wordpress installation to perform a validation for logged in user and redirect them to the proper page in case.
My main purpose is to guarantee that different roles can have a different minimum of required profile fields (ie. I might need to know the phone number of my editors while I don’t need to know the phone number of my subscribers)
After looking around docs, tutorials and forum I came out with the following solution:
function validate_user_profile(){ //Check user membership if(is_user_logged_in() && pmpro_hasMembershipLevel(2) && !is_page( 'Account' )){ //Required fields $field_to_check = array('codice_fiscale','citta_nascita','data_nascita','citta_residenza','telefono','cap','via'); $user_ID = get_current_user_id(); for($i = 0; $i < count($field_to_check); ++$i) { $field_value = get_user_meta($user_ID, $field_to_check[$i], 'TRUE'); //Retrieve field value if(empty($field_value)) wp_redirect(get_permalink(get_page_by_title('Account')->ID)); //Redirect to profile page if value is missing exit; } } } add_action('wp_head', 'validate_user_profile');
The code above added in the active theme functions.php file did the trick but just partially: when I log in with a user that has to be redirected to the account page the page is loaded correctly, but if the redirect is not executed I can see only a blank page.
My understanding was that if the code is not executed wordpress should work without interferences, but this doesn’t appear to be the case.
Can you please help me understand what I am missing in my code snippet?
Should an explicit redirect to the referer be the solution?
Thanks and regards
- The topic ‘user validation and redirect cause blank page’ is closed to new replies.