简体   繁体   中英

How can I access the currently logged in Wordpress user from a separate PHP file?

I have a simple separate PHP page hosted in the same directory as my Wordpress blog. This page is standalone so it knows nothing of Wordpress, but will of course receive the same cookies since it's on the same host.

The question is simple: How do I access the logged in Wordpress user's ID from this standalone page?

I know you can access logged in user data via get_currentuserinfo , but that assumes you're running within Wordpress. How do I access this info on a PHP page that isn't delivered from Wordpress, but is on the same host?

Add the include header from the wordpress's site.

<?php
    define('WP_USE_THEMES', false);
    require('wp-blog-header.php');
?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM