Title: Checking user login from outside wordpress
Last modified: August 21, 2016

---

# Checking user login from outside wordpress

 *  [clearsys.net](https://wordpress.org/support/users/clearsysnet/)
 * (@clearsysnet)
 * [12 years, 1 month ago](https://wordpress.org/support/topic/checking-user-login-from-outside-wordpress/)
 * If I log in to Word press I am able to check my login status with a script like
   this.
 * However, if I login through Private Content then this will not work.
 * How can I check login from outside WordPress if the user only logs in to Private
   Content?
 *     ```
       require_once('../wp-config.php');
       require_once('../wp-includes/wp-db.php');
       require_once('../wp-includes/pluggable.php');
   
       //echo wp_get_current_user()->ID;
       $current_user = wp_get_current_user();
       /**
        * @example Safe usage: $current_user = wp_get_current_user();
        * if ( !($current_user instanceof WP_User) )
        	*     return;
       */
       echo 'Username: ' . $current_user->user_login . '<br />';
       echo 'User email: ' . $current_user->user_email . '<br />';
       echo 'User first name: ' . $current_user->user_firstname . '<br />';
       echo 'User last name: ' . $current_user->user_lastname . '<br />';
       echo 'User display name: ' . $current_user->display_name . '<br />';
       echo 'User ID: ' . $current_user->ID . '<br />';
       ```
   
 * [https://wordpress.org/plugins/wp-private/](https://wordpress.org/plugins/wp-private/)

Viewing 1 replies (of 1 total)

 *  [micelestium](https://wordpress.org/support/users/micelestium/)
 * (@micelestium)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/checking-user-login-from-outside-wordpress/#post-4890980)
 * I use this code in my main directory to display files via Htaccess and WordPress
   login:
 *     ```
       <?php
       require_once('wp-config.php');
       if( is_user_logged_in() ):
   
       $file = ABSPATH.'wp-content/uploads/'.$_GET['img'];
   
       if (file_exists($file))
       {
           $ftype = 'application/octet-stream';
           $finfo = @new finfo(FILEINFO_MIME);
           $fres = @$finfo->file($file);
           if (is_string($fres) && !empty($fres)) {
              $ftype = $fres;
           }
           header('Content-Type: ' . $ftype);
           header('Content-Length: '.filesize($file));
           header('Content-Disposition: filename='.basename($file));
           flush();
           readfile($file);
       }
       else
       {
           global $wp_query;
           $wp_query->set_404();
           status_header(404);
           include( get_query_template( '404' ) );
       }
   
       else:
           auth_redirect();
   
       endif;
   
       die();
       ?>
       ```
   
 * It works well, but it loads to slow. I’m still working on a way to speedup te
   proces and not completely load the whole init.

Viewing 1 replies (of 1 total)

The topic ‘Checking user login from outside wordpress’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/wp-private.svg)
 * [Wp-Private](https://wordpress.org/plugins/wp-private/)
 * [Support Threads](https://wordpress.org/support/plugin/wp-private/)
 * [Active Topics](https://wordpress.org/support/plugin/wp-private/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wp-private/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wp-private/reviews/)

 * 1 reply
 * 2 participants
 * Last reply from: [micelestium](https://wordpress.org/support/users/micelestium/)
 * Last activity: [11 years, 2 months ago](https://wordpress.org/support/topic/checking-user-login-from-outside-wordpress/#post-4890980)
 * Status: not resolved