views:

160

answers:

3

hey there

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

apacheWWW/wordpress/jtpc

in my application i want the wordpress current user id

i am able to do this in one page but in the other i get an error

this is what i am doing 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' );

the error says

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

what dose he wants with the wp-admin , and why he is looking for it in the wrong directory , its suppose to be under

   D:/programming/apacheWWW/wordpress/

its working for one page, (i am uploading file and creating a directory for this user id)

but for the other page i send an ajax request to delete files by user request so i need to id again but there he throws the error

thank you

A: 

You may want to try one of the following two lines:

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

or

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 path, while TEMPLATEPATH will be the parent theme path.

boxoft
i am getting error for this PHP Notice: Use of undefined constant STYLESHEETPATH - assumed 'STYLESHEETPATH' in D:\\programming\\apacheWWW\\wordpress\\jtpc\\ajaxHandlers\\addon_handler.php on line 22, referer: http://localhost/wordpress/?page_id=23AND [error] [client 127.0.0.1] PHP Notice: Use of undefined constant TEMPLATEPATH - assumed 'TEMPLATEPATH' in D:\\programming\\apacheWWW\\wordpress\\jtpc\\ajaxHandlers\\addon_handler.php on line 22, referer: http://localhost/wordpress/?page_id=23
shay
Something wrong with your settings. You may want to install XAMPP on your PC and try WordPress.
boxoft
A: 

This is how you can get current user:

global $current_user;
$current_user = wp_get_current_user();

After that, you can use $current_user->ID where you want.

More Info:

Sarfraz
also error here PHP Fatal error: Call to undefined function wp_get_current_user() in D:\\programming\\apacheWWW\\wordpress\\jtpc\\ajaxHandlers\\addon_handler.php on line 24, referer: http://localhost/wordpress/?page_id=23
shay
A: 

ok got i working i put

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

at the top of the page and not inside the function

shay