how to allow require_once() to php file in wordpress

Samad picture Samad · Oct 16, 2014 · Viewed 26.2k times · Source

I have a web site made by wordpress and I made some php files that i want to execute and for some reason I need to require_once(/wp-includes/class-phpass.php) but I got Failed opening required Error, there is a htaccess file in root folder and it doesn't exist in wp-includes folder the htaccess contain this:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

so how to solve this problem?! , Thanks

Edit

my wordpress is not installed in the root folder it's like root/live

Answer

Niels Keurentjes picture Niels Keurentjes · Oct 16, 2014

Assuming this is your literal code:

require_once('/wp-includes/class-phpass.php');

No wonder the file can't be found, as require operates on the filesystem level, so you probably need something like /var/www/mysite/wp-includes/class-phpass.php instead.

You should be able to get it work like this:

require_once $_SERVER['DOCUMENT_ROOT'] . '/wp-includes/class-phpass.php';

This inserts the current root path of the web site before the subpath. $_SERVER['DOCUMENT_ROOT'] is by default the only semblance PHP has of a 'root path' unless you teach it better.