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
Assuming this is your literal code:
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:
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.WordPress 5.x compatible:
This can be used for example to
functions.php
of your theme:As mentioned in the comment, require is a filesystem-local procedure – it doesn’t process the htaccess rules.
You are trying to
this is looking in your machines root for /wp-includes/
This would work if your wordpress is installed in the document_root (burt is not the recommended way):
But you should use this:
as referenced from this codex page: http://codex.wordpress.org/Function_Reference/get_home_path
If you are making scripts that need to use the wordpress core, but aren’t executed from within the scope of wordpress itself, then you would need to do the following: