Skip to:
Content
Pages
Categories
Search
Top
Bottom

How do I force a login?

  • Avatar of bgrun80
    bgrun80
    Participant

    @bgrun80

    Hey all,

    I tried doing things like the below example

    /* If not logged in, the user will be redirected to the registration/login page */
    if ( !is_user_logged_in() ) :
    nocache_headers();
    $destination = site_url( BP_REGISTER_SLUG . ‘/’ );
    wp_redirect( $destination, 302 );
    exit;

    else :
    index.php as normal

    but I ran into this error message every time:
    Warning: Cannot modify header information – headers already sent by (output started at C:xampplitehtdocswp-contentthemespartyhookupsindex.php:4) in C:xampplitehtdocswp-includespluggable.php on line 890

    Any ideas on how to force a redirect to register.php if I’m not allowed to touch the headers?

    Cheers,
    Ben

Viewing 4 replies - 1 through 4 (of 4 total)
  • Avatar of bgrun80
    bgrun80
    Participant

    @bgrun80

    Also, I tried doing:

    /* If not logged in, the user will be redirected to the registration/login page */
    if ( !is_user_logged_in() ) :
    include ‘registration/register.php’;
    else :
    index.php as normal

    but that didn’t work either…

    Avatar of @modemlooper
    @modemlooper
    Moderator

    @modemlooper

    Are you trying to close your sight off to all except logged in users?

    if (!is_user_logged_in() ){
    bp_core_redirect( $bp->root_domain.’/register’ );
    }

    Avatar of Jalien
    jalien
    Participant

    @jalien

    There are lots of wordpress plugins that will do this. A simple to use that redirects by role is:

    http://wordpress.org/extend/plugins/peters-login-redirect/

    Avatar of bgrun80
    bgrun80
    Participant

    @bgrun80

    Thanks for the quick replies.

    @modemlooper: When I tried your code, it gave me this…
    Warning: Division by zero in C:xampplitehtdocswp-contentthemespartyhookupsindex.php on line 10
    Warning: Cannot modify header information – headers already sent by (output started at C:xampplitehtdocswp-contentthemespartyhookupsindex.php:4) in C:xampplitehtdocswp-includespluggable.php on line 890

    @Jalien: I will give it a shot, but I’d really prefer to use my own code and keep plugins to a minimum

    I tried this and it worked, but I’m wondering if it will break something else or if it’s bad programming practice. Any thoughts?

    if ( !is_user_logged_in() ) :
    global $bp;
    $bp->signup->step = ‘request-details’;
    locate_template( array( ‘registration/register.php’ ), true );
    else :
    index.php as usual

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

You must be logged in to reply to this topic.