• I am building a dashboard for my place of employment and I built a page which I want to make available only to the same group of people that have posting privileges on WordPress. Is there anyway to use the WordPress credentials to force users to login in order to view html and php documents which I created and aren’t part of wordpress?

    I would assume that if it’s possible, it’s only made possible by an extension. Anybody have any ideas?

Viewing 7 replies - 1 through 7 (of 7 total)
  • You can query user level with code like:

    <?php global $user_ID, $user_identity, $user_level ?>
        <?php if ( $user_ID ) : ?>
            <?php if ( $user_level >= 1 ) : ?>
              <?php print $user_identity. "is an admin"; ?>
        <?php endif ?>
    <?php endif ?>

    That should work I would think, It’s a common bit of code I use for admin widgets and such.

    Thread Starter thewpworkdb

    (@thewpworkdb)

    Sorry, I’m still kind of new to wordpress, how would I make use of this bit of php?

    Put whatever you want to be hidden to normal users inside the if which determines user level, it will check if the logged in user is an admin (or change 1 to lower for different user levels, I don’t know which is which).

    Thread Starter thewpworkdb

    (@thewpworkdb)

    If I’m not mistaken, don’t I also need to include a database connection for those variables to have meaning?

    If you get the page to be called from wordpress it will load all the connections in for you rather than having a dashboard completely external to wordpress.

    If you did want someething completely external then you will want to create your database connection, query username and password with user level and add session data and if a result is returned allow them the session data to log in or whatever way you want.

    The first way will be the easiest though and will allow you to use the code I pasted above.

    Thread Starter thewpworkdb

    (@thewpworkdb)

    Can you elaborate a bit on what you mean by the term “called from?” Using a php require?

    The requires are in reverse if wordpress calls your page template. So for example if you wanted an admin page, the way one might go about it would be to make a new page template for the admin.

    To do this you would put maybe create an adminPanel.php in your themes folder

    <?php
    /*
    Template Name: Admin Panel
    */
    ?>
    
    <?php global $user_ID, $user_identity, $user_level ?>
        <?php if ( $user_ID ) : ?>
            <?php if ( $user_level >= 1 ) : ?>
             //Put your full admin page in here
        <?php endif ?>
    <?php endif ?>

    Then you would create a new page with this template, whether it display any content in it or not. Then that page will already have access without needing any includes. You could also manually include some files but would be more difficult I suppose.

    There are a few ways to go about it though, just do whichever suits your needs more.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Is it possible to use WordPress Authentication for non-WP pages ?’ is closed to new replies.