N
N
Ninja Mate2016-02-19 22:04:36
WordPress
Ninja Mate, 2016-02-19 22:04:36

Why is is_user_logged_in() on the server throws an error but works on localhost?

I am writing one plugin and a strange thing with this function

function checkLogged(){
if ( !is_user_logged_in() ) {
    wp_redirect(home_url('/wp-login') );
      exit;
}
}
add_action('wp_head', 'checkLogged');

Warning: Cannot modify header information - headers already sent by (output started at .../wp-includes/formatting.php:4583) in .../wp-includes/pluggable.php on line 1228

I recently had such a problem, but the question turned out to be in a damaged (not correct utf format) config file, now it does not work precisely because of this function. As soon as you delete everything goes.
Why?

Answer the question

In order to leave comments, you need to log in

5 answer(s)
N
Ninja Mate, 2016-02-19
@victorzadorozhnyy

Well, I asked myself and I'll answer it myself...
you need to change wp_head -> template_redirect
and everything works.

S
Stalker_RED, 2016-02-19
@Stalker_RED

Because the redirect occurs due to the sending of headers Location.
In your case, the headers cannot be sent because some information has already been output (this is written in the error message), in the file /wp-includes/formatting.phpon the 4583. You can see what happens there - the config is connected, or some file with BOM.

S
Sergey, 2014-11-07
Protko @Fesor

Product and product_translations table with all fields that can be translated and the locale field.

R
Rsa97, 2014-11-07
@Rsa97

If there are only two languages ​​and no more are expected, then there are two fields in the table. If you need to expand languages, then a separate table (`product_id`, `language`, `name`)

A
Alex, 2014-11-07
@shoomyst

More correctly so: separate tables for entities + language tables for them.
For example: products + products_i18n
In the first, all fields that do not depend on the language, in i18n - respectively, all dependent (usually text) on the language.
products: id, category_id
products_i18n: product_id, language_id, title

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question