Skip to:
Content
Pages
Categories
Search
Top
Bottom

Any idea to integrate wp and bb login forms?

  • After integrating wp and bb and having wordpress header, footer and sidebar for both, wp and bb, I have these wordpress functions in my sidebar;

    <?php wp_register(”); ?>

    <?php wp_loginout(); ?>

    <?php wp_meta(); ?>

    And in bb press frontpage I have this one;

    <?php login_form(); ?>

    First, I thought I could replace wp functions in the sidebar for bbpress’ <?php login_form(); ?> but this function it is not defined for wordpress and I have got an error.

    Besides there are two other problems;

    * if users register through bbpress, their roles are not defined in wordpress

    * if I remove wordpress meta functions from the sidebar I lose the link to the admin control panel.

    Well, another option would be using the wp functions for login;

    <?php wp_register(”); ?>

    <?php wp_loginout(); ?>

    <?php wp_meta(); ?>

    and then changing their beaviour so;

    * whenever you login you are not taken to the control panel unless you are the admin

    * whenever you are an user and you click in “site admin” link wich appears above the log-out link, you are taken to the bbpress profile.php

    My questions are; first of all, do you find any sense in all of this or is it just crap? :)

    does anybody know where is defined wordpress login meta links so I can change them?

    and finally, does anybody have a better idea?

Viewing 25 replies - 1 through 25 (of 25 total)
  • I’m not sure what you’re trying to do. What do you mean by “integrating” these forms – making them look the same? Making them log you in to both bb and WP at the same time, or what?

    Personally I don’t link to the admin panel; what’s the point? People can’t do anything interesting there, unless they’re authors in which case they can bookmark the link.

    “I’m not sure what you’re trying to do. “

    -> I’ll try to explain better :) My web will be made with wordpress and bbpress. Only registered users can comment wp blog entries and post topics in the bbpress forum.

    Login tables are integrated and bbpress is inside the wordpress interface. When you go to bbpress you can see there the wordpress header, footer and sidebar.

    So, right now users could log in through two gates; wordpress sidebar or through bbpress frontpage.

    Well, I want to get rid of of these two gates and I want to avoid users can access wordpress dashboard and profile because the interface of these two pages is different. However, admin still needs access to wp control panel.

    You’re the admin, right? You could just bookmark the page.

    Otherwise I suggest you write a plugin that uses the WP wp_login hook and changes the hopefully global $redirect_to depending on whether or not the user is admin. That’s for wp. bb default login behaviour is okay?

    “You’re the admin, right? You could just bookmark the page.”

    -> Well, this is an option that I have in mind, but then all users that registered through bbpress will appear with “undefined” role in wordpress. And I can’t insert bbpress <?php login_form(); ?> in wordpress sidebar because it doesn’t work :(

    “Otherwise I suggest you write a plugin that uses the WP wp_login hook and changes the hopefully global $redirect_to depending on whether or not the user is admin. That’s for wp. bb default login behaviour is okay?”

    -> Unfortunately, I have no idea of how to write a plugin or a simple function :( I can badly modify already made code.

    Well, I have think in a more elegant solution, but this is for wordpress users that inserted bbpress in their wordpress interface. I have it half working though. First of all, my wp-login and wp-registering forms are integrated in my custom theme because I hacked wb-login.php.

    Whenever you login in wordpress there is a function in the sidebar, that displays two links;

    Site Admin -> link to wp profile.php

    Logout

    This links are defined in /wp-includes/general-template.php -> line 50

    $link = $before . '<a href="' . get_option('siteurl') . '/wp-admin/">' . __('Site Admin') . '</a>' . $after;

    You can change /wp-admin/ for bbpress/profile.php

    The first failure of this theory is that bbpress uses an id to show user profiles; bbpress/profile.php?id=1 and I have no idea how to add this id to the link plus I don’t know if bbpress user id are the same that in wordpress.

    The second failure is that if you are the admin you should get the original link to /wp-admin/

    this should be something like if user = admin then “link to /wp-admin/” else “link to /wp-admin/profile.php?id=n user”

    but since I have no idea of how to code all this I can’t go further

    :)

    I hope you’re keeping wp-login.php up to date! If you’re not comfortable writing a plugin I’d be worried about hacking core files.

    wp user IDs are the same as bb user IDs.

    It is something like that.

    if( current_user_can('administrate') ) {
    $redirect_to = "/wp-admin";
    } else {
    $redirect_to = $bb_profile_link;
    }

    That would be all the code you need (although you have to generate $bb_profile_link. Not hard). Tell me you can’t read and understand that. And this explains all about hooks. We all make a start somewhere. I learnt PHP through WordPress just back in December.

    Hey fel64! thanks for the answer;

    “If you’re not comfortable writing a plugin I’d be worried about hacking core files.”

    -> I’m not skilled enough, I’m learning like you, through wordpress, but it is too much for just half month and I’d like to upload the new web by the end of next week.

    Regarding the code, I asked this same question in wp forums and user whooami told me that;

    “youre doing that assbackwards. The smart way to do what you want to do is to use an if/else statement inside your theme.”

    :)

    The original code is like this;

    function wp_register( $before = '<li>', $after = '</li>' ) {

    if ( ! is_user_logged_in() ) {
    if ( get_option('users_can_register') )
    $link = $before . '<a href="' . get_option('siteurl') . '/wp-login.php?action=register">' . __('Register') . '</a>' . $after;
    else
    $link = '';
    } else {
    $link = $before . '<a href="' . get_option('siteurl') . '/wp-admin/">' . __('Site Admin') . '</a>' . $after;
    }

    echo apply_filters('register', $link);
    }

    so bearing in mind the code you provided and guessing that I need to generate both links in the same way;

    function wp_register( $before = '<li>', $after = '</li>' ) {

    if ( ! is_user_logged_in() ) {
    if ( get_option('users_can_register') )
    $link = $before . '<a href="' . get_option('siteurl') . '/wp-login.php?action=register">' . __('Register') . '</a>' . $after;
    else
    $link = '';
    } else { if( current_user_can('administrate') ) {
    $link = $before . '<a href="' . get_option('siteurl') . '/wp-admin/">' . __('Site Admin') . '</a>' . $after;}
    else { $redirect_to = $bb_profile_link;
    }
    }

    echo apply_filters('register', $link);
    }

    or replacing that $redirect_to = $bb_profile_link; for;

    $link = $before . '<a href="' . get_option('siteurl') . '/bbpress/profile.php<!--call id user here --> ">' . __('Profile') . '</a>' . $after;

    What I don’t know is how to add the id user to the link ??? Since it is the same id user than in wordpress the must be a way

    Ah, whooami. She’s a pleasant one. What she probably meant is, you could not use wp_register() and do your own new function in your theme that does what you want; that’s probably a better solution than changing core code. It’s easy; you could just copy all of wp_register() into your theme (everything from function wp_register() { to the final }, change its name and then make the changes you want, and use that instead. Probably worthwhile, too.

    There’s a very easy way! WordPress sets $id to be the user ID. It should be available, so just try it. If it’s not, you will need to put global: $id; in the line of code above it, so it knows you mean the global variable $id and not a new one.

    “you could just copy all of wp_register() into your theme (everything from function wp_register() { to the final }”

    -> do you mean copying in my theme functions.php file and then calling the fuction in the sidebar?

    “WordPress sets $id to be the user ID. It should be available, so just try it. If it’s not, you will need to put global: $id; in the line of code above it, so it knows you mean the global variable $id and not a new one.”

    -> I didn’t understand this. Do you mean something like this?

    global: $id;

    $link = $before . '<a href="' . get_option('siteurl') . '/bbpress/profile.php$id">' . __('Profile') . '</a>' . $after;

    Yeah, you could copy the wp_register() function into your functions.php file, modify it (and its name), and then use the modified function instead.

    Actually it should be

    global $id;

    Sorry. And for the last line, you have the right idea but you have to use the string concatenation (putting together into one) operator: the dot . This part is gonna be a bit more complicated, but solution at the bottom.

    Strings are indicated by using apostrophes ' ... ' or quotation marks " ... ". If you start a string with one of them, the other one doesn’t affect anything. Variable names inside the quotation marks " will be replaced with their value, but inside ' they will not. The strings here are made using apostrophes ', so you can have valid HTML code without problems: '<a href="..."' works, but "<a href="..."" doesn’t. But that means variable names inside the string won’t get replaced with their value. So you have to concatenate the strings, like this: '<a href="...' . $id . '"> ...';

    $link = $before . '<a href="' . get_option('siteurl') . '/bbpress/profile.php?id=' . $id . '">' . __('Profile') . '</a>' . $after;

    Should work. Bit tired and therefore also inclined to ramble; sorry about that.

    Hi fel64, thanks for the explanation.

    I tested and the function works but there are two errors in the code.

    First, the id user line displays “21″ for every user

    global $id; $link = $before . '<a href="' . get_option('siteurl') . '/bbpress/profile.php?id=' . $id . '">' . __('Profile') . '</a>' . $after;

    Next, if( current_user_can('administrate') doesn’t seem to work because it display a link to bbpress profile instead to /wp-admin/

    This is the whole function so far;

    function wp_registro( $before = '<li>', $after = '</li>' ) {

    if ( ! is_user_logged_in() ) {
    if ( get_option('users_can_register') )
    $link = $before . '<a href="' . get_option('siteurl') . '/wp-login.php?action=register">' . __('Register') . '</a>' . $after;
    else
    $link = '';
    } else { if( current_user_can('administrate') ) {
    $link = $before . '<a href="' . get_option('siteurl') . '/wp-admin/">' . __('Site Admin') . '</a>' . $after;}

    else {global $id; $link = $before . '<a href="' . get_option('siteurl') . '/bbpress/profile.php?id=' . $id . '">' . __('Profile') . '</a>' . $after;
    }
    }

    echo apply_filters('register', $link);
    }

    did I made a mistake in the second “else” ?

    Turns out administrate isn’t a capability. Woooops. Sorry! Thought bb and WP would be equivalent.

    Take your pick of capabilities:

    • switch_themes
    • edit_themes
    • activate_plugins
    • edit_plugins
    • edit_users
    • edit_files
    • manage_options
    • moderate_comments
    • manage_categories
    • manage_links
    • upload_files
    • import
    • unfiltered_html
    • edit_posts
    • edit_others_posts
    • edit_published_posts
    • publish_posts
    • edit_pages
    • read

    :)

    I tried “activate_plugins” and it works great! The only thing left is fixing the id number because it is showing “21″.

    is” global $id” ok?

    It really should be, might have made another one of the silly little mistakes I’m so fond of. Try

    global $user;

    and use $user->ID instead.

    Nop, it doesn’t work; this line

    global $user; $link = $before . '<a href="' . get_option('siteurl') . '/bbpress/profile.php?id=' . $user . '">' . __('Profile') . '</a>' . $after;

    links to /bbpress/profile.php?id= it is not catching the user id

    These two do not display anyting either;

    /bbpress/profile.php?id=' . ID . '">'

    /bbpress/profile.php?id=' . $user->ID . '">'

    Try this one.

    global $user_ID;
    get_currentuserinfo();

    ... bbpress/profile.php?id=' . $user_id . '">' . ...

    Nop but I think I got it;

    global $current_user and then $current_user->ID

    let me test with several users…

    It works!!!!!!

    The working whole code is;

    function wp_registro( $before = '<li>', $after = '</li>' ) {

    if ( ! is_user_logged_in() ) {
    if ( get_option('users_can_register') )
    $link = $before . '<a href="' . get_option('siteurl') . '/wp-login.php?action=register">' . __('Register') . '</a>' . $after;
    else
    $link = '';
    } else { if( current_user_can('activate_plugins') ) {
    $link = $before . '<a href="' . get_option('siteurl') . '/wp-admin/">' . __('Site Admin') . '</a>' . $after;}

    else {global $current_user; $link = $before . '<a href="' . get_option('siteurl') . '/bbpress/profile.php?id=' . $current_user->ID . '">' . __('Profile') . '</a>' . $after;
    }
    }

    echo apply_filters('register', $link);
    }

    Now when any user logs in, wordpress sidebar displays a link to his profile in bb, but when is the admin the one who logs in he get a link to wp control panel. :)

    Thanks a lot fel64!

    This $current_user seems to be quite useful.

    How can you insert $current_user here to replace Profile?;

    . __('Profile') .

    for “UserName’s Profile”, is there any call using $current_user?

    $current_user->NAME didn’t work

    got it, it is $current_user->display_name

    so even more elegant; now when an user logs in has his nickname displayed in the sidebar

    :)

    Very nice, sorry my ‘help’ wasn’t that useful :P

    “Very nice, sorry my ‘help’ wasn’t that useful :P

    -> Not at all, without you this integration wouldn’t have been possible!


    Marcomail
    Member

    @marcomail

    How you can do for registration ? Have you disable wp or bbpress registration ?

    there is a way for add in this function the form of login?instead use a link to wp-login.php have a form where put user and pass?

    So we can have on wordpress sidebar the Form for login, the link for register when user isn’t logged and whe can have a link to admin dashboard or a link to the profile page when the user is logged

    thank you

    kikko088

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

You must be logged in to reply to this topic.