Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<blockquote> <p>My question is... what exactly is in this <code>wp-load.php</code> file that it needs to be required by the code?</p> </blockquote> <p>All of the core WordPress functionality. This includes the theme files, all the files of active plugins, etc. <strong>BUT</strong> loading WordPress in this way doesn't parse the requested URL and doesn't run the WordPress query(by initializing the WP object, nor the WP_Query objects).</p> <blockquote> <p>By looking at it, all I understand is that it loads crucial core wordpress files for the site to be running correctly (<code>functions.php</code>, <code>wp-settings.php</code>, <code>wp-config.php</code> etc...)</p> </blockquote> <p>Yes, you've understood correctly. </p> <blockquote> <p>Doesn't the fact that the plugin runs already means wp-load.php is loaded?</p> </blockquote> <p>If the plugin code was invoked by WordPress(for instance in order to display an admin page, or it was included by the initially loaded plugin file) - then yes, it means that <code>wp-load.php</code> has already been loaded.</p> <p>Sometimes though, plugins direct requests to single files(for instance <code>http://example.com/wp-content/plugins/my-plugin/sample.php</code>), instead of to some WordPress-powered page(for instance <code>http://example.com/?my_plugin_action=sample</code> or <code>http://example.com/wp-admin/admin-ajax.php</code>). </p> <p>See how the first URL references a specific file in the <code>my-plugin</code> plugin directory and the second one goes to the home page of the site with a specific query argument added, or the third example, where the referenced file is <code>admin-ajax.php</code> in the <code>wp-admin</code> directory - this is a special file, which makes it easy for plugins to make AJAX request(this file also loads the WordPress core and fires some action hooks).</p> <p>In the case of the first reference, if the plugin wants to use some WordPress functionality(for referencing the database, manipulating posts, etc), it needs to load the WordPress core files by including <code>wp-load.php</code>.</p> <blockquote> <p>Also it's a complete waste of resources since it includes so many files that may include other files as well and it's like an endless loop of required files, each within another, which are being loaded twice.. (or even more if other plugins use this kind of method too)</p> </blockquote> <p>Note the <code>_once</code> part in <code>require_once(...</code> - this tells PHP to include the file <strong>only</strong> if it hasn't been included already. Therefore no conflicts will occur, and not too much memory will be used by PHP. Although - if you are in a context where WordPress has already been started, you shouldn't call the <code>require</code> function. </p> <hr> <p>So, basically the plugin author expects some requests to be made to the plugin file in which you found this code. Since the author wants to use WordPress functionality in this file, he invokes the <code>wp-load.php</code> file in order to load the core functions. </p> <p>I assume, that this is done in order to reduce load on the server, although with a couple of hooks that run on the <code>plugins_loaded</code> action hook and a custom <code>$_GET</code> parameter added to the home url, the result should still be pretty close.</p> <p>I personally prefer the second option, but like I said, including <code>wp-load.php</code> <strong>will</strong> prevent WordPress from running some complex stuff(URL parsing and database query/ies).</p> <p>If there is still something, that you don't quite understand about that - post a comment here and I'll try to explain further.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload