How to allow require_once () for php file in wordpress

I have a website made by wordpress and I made some php files that I want to execute and for some reason I need require_once (/wp-includes/class-phpass.php) but I got Failed opening required Error, there is an htaccess file in the root folder and it does not exist in the wp-include folder where the htaccess contains the following:

# 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 root folder as root / live

+3


source to share


2 answers


Assuming this is your literal code:

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

      

Unsurprisingly, the file was not found since it require

operates at the filesystem level, so you probably need something like /var/www/mysite/wp-includes/class-phpass.php

.



You should be able to make it work like this:

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

      

Inserts the current root path of the website before the subpath. $_SERVER['DOCUMENT_ROOT']

by default, the only visible PHP has a "root path" unless you teach it better.

+9


source


As mentioned in the comment, require is a local filesystem procedure - it does not process htaccess rules.

You are trying

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

      

this looks in your computer's root directory / wp -includes /

This will work if your wordpress is set in the documentroro document (not recommended):

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

      



But you have to use this:

$install_path = get_home_path();
require_once($install_path. '/wp-includes/class-phpass.php');

      

as stated in this codex page: http://codex.wordpress.org/Function_Reference/get_home_path

If you are creating scripts that need to use the core wordpress but are not executed from within the scope of Wordpress itself, you will need to do the following:

define('WP_USE_THEMES', false);
global $wp, $wp_query, $wp_the_query, $wp_rewrite, $wp_did_header;
require( $_SERVER['DOCUMENT_ROOT'] . '/path/to/wp-load.php');

$install_path = get_home_path();
require_once($install_path. '/wp-includes/class-phpass.php');

      

0


source







All Articles