Headers already sent error after upgrading wordpress to 4.2.2

Use wp_redirect() function instead of header().

Here is the code example:

wp_redirect($redirect);