Skip to:
Content
Pages
Categories
Search
Top
Bottom

Custom Login Page in BuddyPress


  • jordashtalon
    Member

    @jordashtalon

    The Default Buddypress theme has a custom Login Page, how do I achieve the same effect with a custom theme? I know of plugins like Customize your community but I figured BuddyPress would have something built in like the register page.

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

  • 21cdb
    Participant

    @21cdb

    Put this in your bp-custom.php and create a file “login.php” in your custom theme diretory.

    login.php must contain your custom login html.

    It will restrict the access to your communitiy to logged in members and redirects automatically to your custom login page.

    function restrict_access() {

    global $bp, $bp_unfiltered_uri;

    if (!is_user_logged_in() && (BP_REGISTER_SLUG != $bp->current_component) && (BP_LOGIN_SLUG != $bp->current_component)) {

    //bp_core_redirect( $bp->root_domain );
    bp_core_redirect( $bp->root_domain . '/' . BP_LOGIN_SLUG );

    }
    }

    add_action( 'wp', 'restrict_access', 3 );

    define('BP_LOGIN_SLUG', 'login');

    function example_page_setup_root_component()
    {
    bp_core_add_root_component( BP_LOGIN_SLUG );
    }
    add_action( 'plugins_loaded', 'example_page_setup_root_component', 2 );

    function bp_show_login_page() {
    global $bp, $current_blog;

    if ( $bp->current_component == BP_LOGIN_SLUG && $bp->current_action == '' ) {
    // The first variable here must match the name of your template file below
    bp_core_load_template( 'login', true );
    }
    }
    add_action( 'wp', 'bp_show_login_page', 2 );


    jordashtalon
    Member

    @jordashtalon

    Hi 21cdb, I added your code to my bp-custom.php file (which I created and added to the /plugins folder)

    And it caused an infinite Redirect if the user was not logged in.

    What i’m trying to do is a custom login page, I do want anyone to have access to every part of the website whether they are registered or not, (except for if they aren’t registered they can’t make posts or replies)

    What code would I put in the login.php?


    Brajesh Singh
    Participant

    @sbrajesh

    try this one

    define("BP_LOGIN_SLUG","login");
    function bl_setup_component(){
    bp_core_add_root_component( BP_LOGIN_SLUG );
    }
    add_action( 'bp_setup_root_components', 'bl_setup_component', 2 );

    //handle the screen
    function bl_screen_handler(){
    global $bp;
    if ( $bp->current_component != BP_LOGIN_SLUG) )
    return;//return the control back

    if(is_user_logged_in())
    bp_core_redirect(bp_get_root_domain());

    //load template
    bp_core_load_template("/registration/login",true);
    }
    add_action("wp","bl_screen_handler",3);

    Put a template file login.php with the form in your registration folder and it will work as you have mentioned.


    jordashtalon
    Member

    @jordashtalon

    Brajesh, that doesn’t quite work, when I go to http://domain.com/login it redirects back to the homepage. Instead of to the login.php


    Brajesh Singh
    Participant

    @sbrajesh

    It will redirect back to home page if you are logged in as a logged in member should not be able to access that page.

    Try to logout and then visit that page.


    jordashtalon
    Member

    @jordashtalon

    I have been trying it in a browser where I am not logged in.


    Brajesh Singh
    Participant

    @sbrajesh

    hi there

    there was an extra ) by mistake on this line

    if ( $bp->current_component != BP_LOGIN_SLUG) )

    It should be

    if ( $bp->current_component != BP_LOGIN_SLUG)

    Then put login.php in youractive-theme/registration/login.php and check out,. it must work.

    btw, are you putting the code in bp-custom.php or somewhere else?


    jordashtalon
    Member

    @jordashtalon

    Cool it’s working now,

    That’s weird I fixed the syntax error before, but I must’ve taken out too much because it wasn’t working before, thanks a ton for your help.


    Brajesh Singh
    Participant

    @sbrajesh

    You are most welcome. Please make sure to mark this thread as resolved :)


    Jens Wedin
    Participant

    @jedisthlm

    @jordashtalon: What did you put in the login.php file? Tried quickly just to add the same code as the wp-login.php file but did not work.


    nickhammond
    Participant

    @nickhammond

    @jens this line:
    bp_core_load_template("/registration/login",true);

    Is the reference to the file that you would like to load for the login page. For instance, this file would be wp-content/themes/YOUR_THEME/registration/login.php.

    Also, if this file doesn’t exist then it will always redirect the user to the homepage.

    @sbrajesh – I placed your code in my bp-custom.php (should it go in my functions.php?) and I created a new login.php file, but when clicking on “You must be logged in to post a comment.” (“logged in” is a link) I still ended up on the standard wordpress login screen (it even included the redirect back to the post), …/wp-login.php?redirect_to=http… Am I doing something wrong or am I misunderstanding what this code is supposed to do?

    @nickhammond can you post what you put into your login.php file on pastebin? I do not 100% understand your response to @jedisthlm

    Thanks for the help,

    Kalman


    chouxpastry2002
    Participant

    @chouxpastry2002

    i am also trying it but its not redirecting to the custom page. Please tell me what could be the problem. I will manage the custom php form for login.

    Please tell me guys.


    chouxpastry2002
    Participant

    @chouxpastry2002

    it works for me when i type the url in address bar.

    But when i type a wrong username password in my login form it takes me to same wp-login.php page which is we all don want.

    Please provide any solution.


    xavieremerson
    Member

    @xavieremerson

    bp_custom page?
    where is it?
    I’m new to buddypress. I don’t have that page,
    I’m also trying to integrate stand alone login page
    I am also integrated buddypress private community plugin

    healp me please..

    Thankz in advance

    @sbrajesh Thanks for information. Your code worked perfectly!


    Cidade Sonho
    Participant

    @somdefabrica

    @sbrajesh I have a facebook login.

    When login with facebook it redirects back to the wp-login.

    I use this code in my bp-custom.php

    <?php

    // **** Privacy ********
    function restrict_access(){
    global $bp, $bp_unfiltered_uri;

    // If user is not logged in and
    if (!is_user_logged_in() &&

    (
    // The current page is not register or activation
    !bp_is_register_page() &&
    !bp_is_activation_page()

    )

    ) {
    // Redirect to registration page. Change /join to your register page slug
    bp_core_redirect( get_option('home') . '/wp-login.php' );
    }
    }

    add_action( 'wp', 'restrict_access', 3 );

    What Should I do to login with facebook work 100% ?

    Thanks!


    Paulo Vieira
    Participant

    @gopaulo

    I know this has been a while but for some reason $bp->current_component was coming back empty . I saw some people asking around and if you change
    if ( $bp->current_component != BP_LOGIN_SLUG)

    for

    if ($bp->unfiltered_uri[0] != BP_LOGIN_SLUG)

    in Brajesh Singh it should work. just remember to place bp-custom.php in the right folder and to create the login.php file inside of registration (within your active theme)


    makbeta
    Participant

    @makbeta

    I had no luck with any code here. I used Theme My Login plugin and it worked like a charm. The custom page is displayed even on error.

Viewing 19 replies - 1 through 19 (of 19 total)
  • The topic ‘Custom Login Page in BuddyPress’ is closed to new replies.
Skip to toolbar