I am developing a WP Plugin.
Currently, I am making an ajax call with jquery to a standalone php file in my plugin folder.
Let’s presume that this file is called test.php.
The file is NOT loaded prior to this call, so no native wordpress functions work in this file.
As a result, I have require_once('wp.load'); in test.php.
Here stems my questions:
-
The only function I need from wordpress is $wpdb->insert. Is there a better function to include than wp-load? Something that doesn’t include so much, since all I need is this one function!
-
I understand that require_once loads the file, ONLY if it hasn’t been loaded yet. Maybe I’m overlooking the situation, but how does this work with ajax? If there is a “success” response, does test.php close, thus when its called again, it loads
wp-load.phpagain?
Thanks!
Exactly. The concept behind
require_once(orinclude_once) is to make sure you don’t reload the same functions, classes & variables into the same currently running PHP code at the same time:And since PHP scripts run only on request, what you describe is exactly how it would happen.
That said, I wouldn’t over-think the concept of loading the whole
wp.loadeach time it’s needed. I doubt it will cause such a performance hit that it would even be noticeable.