WordPress – how to use authentication for other code?

I want to setup WordPress and use it’s authentication for outside scripts.

For example, I’ll have a script here:

Read More
http://www.domain.com/simplescript

Instead of adding custom user and password login, I thought it would be great simply to add a line at the top of the code, something like a is_user_logged_in check.

I read somewhere this can be done, the only extra being to add require_once($_SERVER['DOCUMENT_ROOT'].'/wp-blog-header.php'); at the top…

BUT… the page says the code has to be in the theme folder – which I would prefer not to have this restriction. I want to have my code anywhere on the website.

My code isn’t all that complex – but does need other files + may or may not need folders and sub folders

Any ideas on how I can do what I need?

Related posts

Leave a Reply

1 comment

  1. You only need to require ‘wp-load.php’ in your seperate PHP file. wp-load.php is in the root of your WordPress installation. You should modify the path if the script is somewhere else. Like this,

    <?php
    
        require_once 'wp-load.php';
    
        if( is_user_logged_in() ) {
            // true
        } else {
            // false
        }
    
    ?>