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, referrer: 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 , It's suppose to be under
D:/programming/apacheWWW/wordpress/
It's 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
This is how you can get current user:
After that, you can use
$current_user->ID
where you want.More Info:
You may want to try one of the following two lines:
or
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.
ok got i working i put
at the top of the page and not inside the function
My issue is that I've set up a standalone ajax controller for my plugin's admin. In hindsight, I wish I didn't, because now I need $current_user->ID on a particular method.
using the following code gives me undefined function errors:
same when I use this:
I've used GREP to trace the spaghetti function calls, and was able to get stable using the following chain of includes within my ajax_request method of my base controller:
(I have defined my own APP_ROOT, which is the include path to the base of the whole application.)
This eliminates my errors, but I am still getting a user id of 0, and data is NULL, which doesn't solve my problem.
Surely there is a better way to do this. Has anyone deciphered the cookie or session variables for direct access?
Any and all suggestions would be welcome. I know I'm asking a lot for wordpress to work like normal OOP/MVC code...
In addition, I have deployed a CodeIgniter front-end, and I am using WordPress solely for the back-end. I highly recommend this for ultimate flexibility if you are forced to use WordPress. Front-end hooks are a pain, and really kind of "hacky". Here's where I got the idea:
http://jidd.jimisaacs.com/post/wordigniter-wordpress-codeigniter/
So if anyone has any questions about that, I bet I could help.
Best regards, happy coding.