I'm running a PHP script called by an AJAX function. I do not want to use the built-in WordPress AJAX API because it would take way too long, since I'm uploading a lot of images. I'm using SHORTINIT to do a partial WordPress load like this: https://wordpress.stackexchange.com/questions/173002/how-declare-ajax-functions-ussing-shortinit
I need to check the username of the current logged-in user. Can someone list the files I need to include/require in my custom PHP file and the order they should be in? Thanks!
As I cant comment (new user). The final soultion (single WP install) I use for making
is_user_logged_in()
andcurrent_user_can()
work, is as follow below. Werequire('wp-load.php')
first (to skip wp() in load-blog-header.php), and getABSPATH
constant then, manually includes exactly all the stuff needed.Using
define('SHORTINIT', true)
+require('wp-load.php')
+ manually includes:Pageload: 1.05 sek - included files: 43 files
Comparing: Using ONLY
require('wp-load.php')
:Pageload: 1.35 sek - included files: 419 files
The time difference (0.3 sek) might differ from installs and PHP engines, but while validating many requests on one pageload -things adds up!
Remember to use relative call to WP installed dir. From a Wordpress custom plugin dir, inside one subdir level, normal install, a path should be like:
Then:
After this, user validation is accessable. For other task, running on one or two requests, tracking down other needed files is not worth 0.3 sek. Skip the
SHORTINIT
constant and manually clutter.Maybe a bit late but I will post it here so it might be useful to other people.
I needed a quick light weight way to load the minimum of Wordpress to figure out the user in a separate API next to the Wordpress install. For me this code works with Wordpress 4.8
NOTE: it is only used in this way. It can be that if you need to do more Wordpress things, you are missing some includes.
I used the code here as a starting point but that didn't work under the current Wordpress version for me: https://wordpress.stackexchange.com/questions/28342/is-there-a-way-to-use-the-wordpress-users-but-without-loading-the-entire-wordpre