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

Read More

Edit

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

Related posts

Leave a Reply

3 comments

  1. 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.

  2. 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';
    
  3. As mentioned in the comment, require is a filesystem-local procedure – it doesn’t process the htaccess rules.

    You are trying to

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

    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):

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

    But you should use this:

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

    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:

    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');