The MU forums have moved to WordPress.org

Moving log-in "page" to be part of header template? (10 posts)

  1. JsonB123
    Member
    Posted 14 years ago #

    I want to embed the sign in box for users of my MU site to the header...but I wasn't sure if there is an easier way of doing this than copying/pasting and modifying the code in wp-login.php?

    I was hoping for a quick template tag...but that doesn't seem to exist, anyone know of any good plug-ins or work arounds that can help?

  2. dsader
    Member
    Posted 14 years ago #

    Ron's Login Widget should help. http://wpmututorials.com/plugins/login-widget/

  3. JsonB123
    Member
    Posted 14 years ago #

    Thanks dsader...that indeed does what I asked for :-).

    I haven't tried hacking it at all to achieve what I really want, which is perhaps a two-step process.
    1. Have the log-in on the main page (accomplished)
    2. Still reroute to that user's blog, while bypassing the dashboard.

    Step two is the real clincher here. With this plugin you pointed out, we stay on the main blog page, but I'd like to forward automatically and pass over the dashboard for that user's blog at the same time.

    I've set up the back-end so that user is subscribing to that new blog only and not the main blog. So without any plug-ins, it does forward to the user's blog, but it goes to the dashboard. So I've basically swapped one of my three issues to solve another one with the login widget plugin. I've sacrificed going directly to the user's blog but don't need to go to the log in page (ugh).

  4. dsader
    Member
    Posted 14 years ago #

    You can make Ron's login widget redirect wherever you like can't you?
    $url = $_SERVER['REQUEST_URI'];

  5. andrea_r
    Moderator
    Posted 14 years ago #

    Yep.

  6. JsonB123
    Member
    Posted 14 years ago #

    Ah, yes. I see that... the last piece what my problem is that in wp-login.php there is the code chunk:

    if ( !is_wp_error($user) ) {
    		// If the user can't edit posts, send them to their profile.
    		if ( !$user->has_cap('edit_posts') && ( empty( $redirect_to ) || $redirect_to == 'wp-admin/' || $redirect_to == admin_url() ) )
    			$redirect_to = admin_url('profile.php');
    		wp_safe_redirect($redirect_to);
    		exit();
    	}

    where the key part of that is the $redirect_to = admin_url('profile.php');

    This is what handles the forwarding for user's attached to their blogs. So basically I need to change that to something that forwards to the user's blog homepage instead of the dashboard. I'm having trouble locating a similar tag or function to admin_url that will go to the home page (or whatever template page specified) for that user. Other than that, Ron's login widget works like a charm :-), thanks!

  7. JsonB123
    Member
    Posted 14 years ago #

    I've tried site_url, get_option('siteurl'). All of these just point to the main blog.

  8. andrea_r
    Moderator
    Posted 14 years ago #

    I'll turn around and nudge Ron to see if he'll come in here. :D

  9. wpmuguru
    Member
    Posted 14 years ago #

    You can get the user's primary blog with

    $primary_blog = get_usermeta($current_user->ID, 'primary_blog');

    Then you can find the url of the blog with

    $bloginfo = get_blog_details($primary_blog);
    $url = 'http://' . $bloginfo->domain . $bloginfo->path;

  10. JsonB123
    Member
    Posted 14 years ago #

    Ah yes, that'll do it! Thanks :D! I've hacked around a bit with Ron's login widget and what you've given me so that users with the level of subscriber log in, they go directly to their primary blog's homepage, while everyone else goes to their primary blog's Dashboard. Also, subscribers are completely cut off from the Dashboard, when they try to get there, they just get routed to their homepage again. In mu-plugins/redirect-primary.php:

    <?php
    
    // Block Dashboard from Subscribers & forward them to their primary blog
    function redirect_to_primary_blog() {
    	if (!is_site_admin()) {
    		global $current_user;
    
    		if (!$current_user->has_cap('edit_posts') && (empty($redirect_to) || $redirect_to == 'wp-admin/' || $redirect_to == admin_url() ) ) {
    			get_currentuserinfo();
    			$blog_details = get_blog_details(get_usermeta($current_user->ID, 'primary_blog'));
    			header('Location: '. $blog_details->siteurl);
    		}
    	}
    }
    
    add_action('admin_init', 'redirect_to_primary_blog');
    ?>

    I've also embedded the plug-in script into a separate php file called by my header template and swapped out the logout submit button with an anchor tag that calls wp_logout_url with a redirect so it appears to stay on the site and not go to that dedicated login/logout page. login-box.php:

    <?php
    		global $user_ID;
    		global $current_user;
    		get_currentuserinfo();
    
    		if ('' == $user_ID) {
    ?>
    	<form name="loginform" id="loginform" action="wp-login.php" method="post">
    		<p><label>Username:<br />
    			<input type="text" name="log" id="log" value="" size="20" tabindex="1" />
    		</label></p>
    		<p><label>Password:<br />
    			<input type="password" name="pwd" id="pwd" value="" size="20" tabindex="2" />
    		</label></p>
    		<p><label>
    			<input name="rememberme" type="checkbox" id="rememberme" value="forever" tabindex="3" /> Remember me
    		</label></p>
    		<p class="submit">
    			<input type="submit" name="submit" id="submit" value="Login &raquo;" tabindex="4" />
    		</p>
    	</form>
    
    <?php
    			wp_register();
    		} else {
    ?>
    		<p>Welcome <span><?php echo $current_user->display_name; ?></span></p>
    
    		<p class="submit">
    			<a href="<?php echo wp_logout_url( get_blogaddress_by_id(1) ); ?>" title="Logout">Logout</a>
    		</p>
    <?php } ?>

    Thanks for all the help guys! Now I'm onto my next task of figuring out a way to automatically import SQL to newly created blogs on the MU site. I'll be posting here with any questions or successes. I haven't found any conclusive information on that subject in the forums here...yet.

About this Topic

  • Started 14 years ago by JsonB123
  • Latest reply from JsonB123