Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to allow require_once() to php file in wordpress

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

like image 672
Samad Avatar asked Oct 16 '14 21:10

Samad


2 Answers

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.

like image 162
Niels Keurentjes Avatar answered Oct 16 '22 22:10

Niels Keurentjes


Wordpress 5.x compatible:

This can be used for example to functions.php of your theme:

if (!defined("MY_THEME_DIR")) define("MY_THEME_DIR", trailingslashit( get_template_directory() ));

  require_once MY_THEME_DIR.'includes/bs4navwalker.php';
like image 33
Alessandro Ornano Avatar answered Oct 17 '22 00:10

Alessandro Ornano