• 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/

Viewing 1 replies (of 1 total)
  • micelestium

    (@micelestium)

    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.