Wordpress get current user

I have a directory inside my wordpress directory for some template application

apacheWWW/wordpress/jtpc 

In my application, I want wordpress current user id

I can do this on one page, but in another I get an error

This is what I do to get the user id:

require_once( '/../../wp-load.php' );
global $current_user;
get_currentuserinfo();
$user_id = $current_user->ID;

but I get an error on this line

 require_once( '/../../wp-load.php' );

Error says

 File does not exist: D:/programming/apacheWWW/wordpress/jtpc/ajaxHandlers/wp-admin, referrer: http://localhost/wordpress/?page_id=23

what dose does he want with wp-admin, and why is he looking for it in the wrong directory, suppose it is under

   D:/programming/apacheWWW/wordpress/

Works on one page (I upload a file and create a directory for this user ID)

but for another page I send an ajax request to delete files at the user's request so I need to specify id again, but there it gives an error

+3
4

ok

  require_once( '/../../wp-load.php' );

+3

, ajax . , , , $current_user- > ID .

, undefined :

global $current_user;
get_currentuserinfo();

, :

$current_user = wp_get_current_user();

GREP , ajax_request :

include APP_ROOT.'wp-includes'.DS.'meta.php';
include APP_ROOT.'wp-includes'.DS.'plugin.php';
include APP_ROOT.'wp-includes'.DS.'user.php';
include APP_ROOT.'wp-includes'.DS.'capabilities.php';
include APP_ROOT.'wp-includes'.DS.'load.php';
include APP_ROOT.'wp-includes'.DS.'functions.php';
include APP_ROOT.'wp-includes'.DS.'pluggable.php';

( APP_ROOT, .)

, 0, NULL, .

, . - cookie ?

. , Wordpress OOP/MVC...

, front-end CodeIgniter, WordPress . , WordPress. - , "". , :

http://jidd.jimisaacs.com/post/wordigniter-wordpress-codeigniter/

, - - , , .

, .

+2

:

require_once STYLESHEETPATH . '/wp-load.php';

require_once TEMPLATEPATH . '/wp-load.php';

There is a slight difference between the STYLESHEETPATH ​​constant and the TEMPLATEPATH constant. If you are developing a child theme, STYLESHEETPATH ​​will be the child theme, and TEMPLATEPATH will be the parent tag.

0
source

Here's how you can get the current user:

global $current_user;
$current_user = wp_get_current_user();

After that you can use $current_user->IDwherever you want.

Additional Information:

0
source

Source: https://habr.com/ru/post/1757503/


All Articles