php - WordPress current user -


I can not currently enter the user in the local host root folder in the WordPress directory and the API directory is I Api / index. I am trying to log in user with php file but it is not working.

api / index.php

  & lt ;? Php define ('WP_USE_THEMES', incorrect); '../wordpress/wp-blog-header.php' is required; Global $ current_user; Var_dump ($ current_user);  

Result:

  object (WP_User) [2369] public 'data' = & gt; Blank Public 'ID' = & gt; Int'l Public 'Caps' = & gt; Array (size = 0) below public 'cap_key' = & gt; Nulled public 'roles' = & gt; Array (size = 0) empty public 'allcaps' = & gt; Array (size = 0) below public 'filter' = & gt; Blank  

I also tried:

  & lt; Php define ('WP_USE_THEMES', incorrect); '../wordpress/wp-blog-header.php' is required; Var_dump (wp_login ('Admin', 'Admin')); Global $ current_user; Var_dump ($ current_user);  

Result:

  Boolean True Object (WP_User) [2369] Public 'Data' = & gt; Blank Public 'ID' = & gt; Int'l Public 'Caps' = & gt; Array (size = 0) below public 'cap_key' = & gt; Nulled public 'roles' = & gt; Array (size = 0) empty public 'allcaps' = & gt; Array (size = 0) below public 'filter' = & gt; Empty  

I have tried to use the root cookie plugin, but it is not working.

>

edit

This problem was repeated in a local environment. I suspect that your requirement path is not correct. What worked for me was:

  define ('WP_USE_THEMES', wrong); Required ('../wp-blog- header.php'); Global $ current_user; Echo '& lt; Pre & gt; '; Var_dump ($ current_user); Echo & lt; / Pre & gt; ';  

You should use the following function to get the current user.

  wp_get_current_user ();  

If you want to access attributes from the current user, you can do so by doing this:

  $ current_user = wp_get_current_user (); Echo 'Username:' $ Current_user- & gt; User_login '& lt; Br / & gt; ';  

More information can be found


Comments