I’m trying to use the global $wpdb in a plugin to insert data into one of my tables.
From the docs it sounds like I just need to include wp-blog-header.php
However when I try to do so I’m getting an error.
PHP Fatal error: require() [function.require]: Failed opening required ‘http://localhost:8888/blog/wp-blog-header.php’ (include_path=’.:/Applications/MAMP/bin/php/php5.3.6/lib/php’) in /Applications/MAMP/htdocs/blog/wp-content/plugins/pluginname/submit/pick.php on line 4
My pluginname/submit/pick.php (which is called by AJAX) has the following code
<?php
$p = 'http://localhost:8888/blog/wp-blog-header.php';
echo $p;
require($p);
echo 'hi';
?>
If I load the pick.php, I see http://localhost:8888/blog/wp-blog-header.php and that is it. So it must be failing on the require, as the error log confirms.
The path is correct as I inserted a quick echo into wp-blog-header.php, and copy pasted the output from pick.php into the address bar and it worked.
Any help would be appreciated.
You don’t include php files via urls. What you’ll be including is the EXECUTED OUTPUT of the script. Since it’s a full-blown url, there’s no difference between your internal require() and someone hitting that url with a browser. All you’ll get is the output of the script, which is probably blank/nothing.
Including via urls, even if it’s just a local request to your own server, opens a whole can of worms in terms of security holes.
Any reason you can’t simply include it via a normal local file request, e.g.
?