简体   繁体   中英

Access Wordpress user info outside Wordpress

I have Wordpress site and and now I'm building PHP App on subdomain. I need to get ID of the user who is logged in on Wordpress site.

I tried to include wp-load.php on my sub-domain and tried:

get_currentuserinfo();
echo 'Hey ' . $current_user->display_name;

But no result.

Could you please give me a hint how can I access Wordpress session info from outside Wordpress on Sub-domain and on the same server?

Thanks in advance.

Using the wordpress API would be the best way and as each case is a case it's not possible to get code ready for exactly what you say, but follow the documentation link about the api part that can help you:

https://developer.wordpress.org/rest-api/using-the-rest-api/authentication/

here you have another example of how to create endpoints for custom logins: Register/login user with Wordpress JSON API

And this other one here of how to create a php request curl on another site that in your case would be the wordpress API: https://phpenthusiast.com/blog/five-php-curl-examples

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