Skip to:
Content
Pages
Categories
Search
Top
Bottom

[Resolved] forcing users to login from the root

Viewing 7 replies - 1 through 7 (of 7 total)

  • Paul Wong-Gibbs
    Keymaster

    @djpaul

    It starts, as most stories do, at the beginning.

    Once upon a time, there was a function called wp_loginout(). It happily printed links to allow the user to log in or out, depending on whether the user was already logged in or not. It was so popular, other kids like the Default WPMU theme used it, and lived in a small cottage in the town of /wp-includes/general-template.php.

    wp_loginout()’s most popular attribute, however, wasn’t its fantastic collection of designer shoes, nor golden rings, but its filter called loginout. This let its very closest friends have access to its link string.

    One controversy that springs to mind, after skipping over a few minor details, happened in /wp-includes/link-template.php street, in site_url‘s house. Its cousin, get_option(‘siteurl’), got around a bit – I’m sure you can imagine, but when it was in one place it was saying one thing, and when it was in another, another thing; it had its own confusingly-named filter site_url, but perhaps this filter was less suited than the other. Needless to say, Mrs. get_option(‘siteurl’) eventually found out about this behaviour and took things into her own hand – she got out some string function, and chopped it up small – ouch!

    I think I might still have the original newspaper article here, let me go look. I think it had a picture.


    Aron Jay
    Participant

    @aronjay

    I don’t understand. :D


    checkm840
    Participant

    @checkm840

    A non storybook/sarcastic walk through would definitively help.


    jazgold
    Participant

    @jazgold

    hmmm i’m a little late on this, but i wrote a basic plugin for myself to do this. basically anyone who comes to your buddypress site will be directed to the login page, if they’re not already logged in. if they log in successfully, they will be taken to whatever page they had been trying to access ( i.e. not simply the backend editing area, or the front page ). to use it just paste it into a .php file, put it in your plugin folder, and activate

    //  whenever a page is loaded, make sure the user is logged in
    function catch_anons(){
    	global $user_ID;
    	get_currentuserinfo();
    		$login_page = get_bloginfo('url') .'/wp-login.php';
    			if ( '' == $user_ID && strrpos( curPageURL(), $login_page)===false ) {
    					$redirect = "?redirect_to=" . urlencode(curPageURL());
    				header( 'Location:' . $login_page . $redirect  );
    		die();
    			}
    }
    add_action('init','catch_anons'); 
    
    //once they log in,send them to their original destination
    function login(  ) {
    $first_stop = '/';       
    	//if there's no 'redirect_to' send them to "Home.php"
    	if ( $_REQUEST['redirect_to'] )
    		$first_stop =  $_REQUEST['redirect_to'];
    		header( 'Location:' . $first_stop );
    	die();
    }
    add_action('wp_login','login');
    
    //build the current URL  wish i could say where i grabbed this, a long time ago...
    
    function curPageURL() {
    	$pageURL = 'http';
    	if ($_SERVER["HTTPS"] == "on") {	$pageURL .= "s";	}
    		$pageURL .= "<img src="smileys/irritated.gif" width="" height="" alt=":/" title=":/" class="bbcode_smiley" />/";
    	if ($_SERVER["SERVER_PORT"] != "80") {
    		$pageURL .= $_SERVER["SERVER_NAME"]. "<img src="smileys/irritated.gif" width="" height="" alt=":" title=":" class="bbcode_smiley" />" . $_SERVER["SERVER_PORT"] . $_SERVER["REQUEST_URI"];
    	} else {
    		$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
    		}
    return $pageURL;
    }

    Tore
    Participant

    @toregus

    @ jazgold

    This is just what I was looking for. Or something like it. But I want to have a splash-page for the non-registered (so that they can get some info on how to register, etc). Is it possible to create a splash-page with this solution?


    jazgold
    Participant

    @jazgold

    @Tore

    cool, glad it helps…

    i imagine that any time someone isn’t logged in, they will all go to the same place… you don’t know if they’re returning and not logged in yet, or if they’ve never been to the site before and need extra info.

    so the splash page should be the login page, it seems.

    what if you just modified the login page to make it look like a more welcoming splash page?

    if you don’t want to put your own stuff directly into the core files, and i guess that’s a LAST, LAST resort, then you can add things to the login page using the related actions and filters. i’m going to have to do this in my next project actually, so thanks for asking:)

    here’s a tutorial that looks about right. looks kosher on first glance:)

    http://www.thinkinginwordpress.com/2008/12/customized-wordpress-login-page-plugin/

    basically, you can use it to inject HTML, or load up some jquery or whatever you want, and then you can CSS the crap out of everything. if you’re having problems with the default wordpress CSS taking precedence, you can always use the !important CSS attribute.

    and i just noticed actually that the code above needs a small tweak. it was breaking the flash uploader for posts somehow. bad bad.

    so, i needed to add an if statement to the catch_anons function. replace the whole function with this one:

    function catch_anons(){
    if ( !is_admin() ){ // if it's the admin area, it already checks
    // ( and the following breaks the flash uploader )
    global $user_ID;
    get_currentuserinfo();

    $login_page = get_bloginfo('url') .'/wp-login.php';

    if ( '' == $user_ID && strrpos( curPageURL(), $login_page)===false ) {

    $redirect = "?redirect_to=" . urlencode(curPageURL());

    header( 'Location:' . $login_page . $redirect );
    die();
    }
    }
    }
    add_action('init','catch_anons');

    cool. hope it works out for you.


    jazgold
    Participant

    @jazgold

    @Tore

    I just noticed that at the bottom of the page, they actually give you a plugin to help with the additions:)

    nice

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘[Resolved] forcing users to login from the root’ is closed to new replies.
Skip to toolbar