Forums

[resolved] In the plugin page, I can't use the function of is_user_logged_in()? (9 posts)

  1. kmvan
    Member
    Posted 1 year ago #

    WP shows a error msg: undefined the is_user_logged_in().

    something is wrong?

  2. kmvan
    Member
    Posted 1 year ago #

    to use the function of is_home() that it works.
    the is_user_logged_in doesn't work, why?

  3. kmvan
    Member
    Posted 1 year ago #

    now i write the is_user_logged_in() in the function,it works.but the outside.

  4. panahbiru
    Member
    Posted 1 year ago #

  5. kmvan
    Member
    Posted 1 year ago #

    yes.i had read. but nothing found...

  6. Joseph
    Member
    Posted 1 year ago #

    What do you mean by plugin page? functions.php?

  7. kmvan
    Member
    Posted 1 year ago #

    plugin page means the my-plugin-name.php.
    for example:
    my-plugin-name.php:

    <?php
    /*
    Plugin Name: my plugin
    Plugin URI: ....
    ...
    */
    if(is_user_logged_in()){
     function example(){
      ...
     }
    }
    ?>

    like this, it shows me a error: the is_user_logged_in() is undefined.
    but like this:

    <?php
    /*
    Plugin Name: my plugin
    Plugin URI: ....
    ...
    */
    function example(){
     if(is_user_logged_in()){
      ...
     }
    }
    ?>

    it works!
    can get me?

  8. Joseph
    Member
    Posted 1 year ago #

    I think it's because is_user_logged_in() is located in wp-includes/pluggable.php and if you open the file it says at the top:

    These functions can be replaced via plugins. If plugins do not redefine these functions, then these will be used instead.

    ie, my-plugin-name.php is been loaded before pluggable.php.

  9. kmvan
    Member
    Posted 1 year ago #

    oh, I think ur right!
    thank u.:)

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.