• Resolved ionurboz

    (@ionurboz)


    Doesn’t call user information to include “wp-load.php” in an external php file.

    require_once( dirname( dirname( __FILE__ ) ) . '/wp-load.php' );
    
    global $wpdb, $user_ID;
    
    echo $user_ID; // reruns 0, always
    
    is_user_logged_in() // returns false, always

    But I can check another one function will work. e.g. get_bloginfo('name')

    Note: I can try to require_once( dirname( dirname( __FILE__ ) ) . '/wp-config.php' ); but results is same!

    • This topic was modified 5 years, 7 months ago by ionurboz.
    • This topic was modified 5 years, 7 months ago by ionurboz.
Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    User authentication has to be through a template or admin process. Simply including wp-load.php will not cause proper authentication of the auth cookie. Including wp-load.php to execute some custom PHP is not portable to some other sites and using that method is frowned upon. Any plugins or themes doing so that are submitted to the WP repository will be rejected. If you don’t care about portability or the repository, you can include wp-load.php if you like, it’s your site.

    Because it’s frowned upon and the current user is not handled, you may as well do things the right way. Your options are limited. You can use Ajax, go through /wp-admin/admin-post.php, or place your code on a custom page template. The admin-post.php actually works very well for most needs, but it’s not very well documented. It is covered here though.

Viewing 1 replies (of 1 total)
  • The topic ‘Doesn’t call user information to include “wp-load.php” in an external php file.’ is closed to new replies.