BuddyPress Variable Help Please

I'm new to all this and could really do with some help. I'm trying to integrate a 3rd party chat room into my BuddyPress site so that logged in members can access the chat room without having to re-enter their login details.

The vendor has said that this is possible by knowing the global values that BuddPress uses for both 'username' and userid'

Here's the information I've got:

// INTEGRATION NOTES FOR CUSTOM DEVELOPERS

// You can insert your existing CMS user Global values into the
// login procedure. Simply replace the values $_FOO['username']
// and $_FOO['userid'] with your SESSION, COOKIE or MySQL results.

// Example:

// define(‘C_CUSTOM_LOGIN’,’1?); // 0 OFF, 1 ON
// define(‘C_CUSTOM_USERNAME’,$_FOO['username']); // username
// define(‘C_CUSTOM_USERID’,$_FOO['userid']); // userid

Please can somebody tell me what I should change the following to:

define(‘C_CUSTOM_USERNAME’,$_FOO['username']); // username
define(‘C_CUSTOM_USERID’,$_FOO['userid']); // userid

Appreciate any help here please?

  • Mason

    Hiya godrob,

    You'll want to integrate what they have with this function get_currentuserinfo()

    here's information on it from the codex:
    http://codex.wordpress.org/Function_Reference/get_currentuserinfo

    I'd also just mention that we have a chat plugin that you could combine with a check for is_user_loggedin() so that only logged in users would have access - and then not have to log in again.

    Hope this helps. Thanks!

  • godrob

    Mason and Richie, thank you very much for your help with this, but I'm afraid I still can't get it to work...

    The vedor hasn't provided any further information on how to integrate their Chat Room with BuddyPress, yet they have provided examples on how to do this with Wordpress and Worpdress 2.6.x

    Is any of the following of any help to get this working with BuddyPress?

    Wordpress:

    WordPress file to edit: wp-content/themes/YOUR_THEME/header.php
    
    1) Scroll down the file until you see the following code,
    
    global $options;
    
    2) Replace with this code instead,
    
    global $options,$user_identity,$user_ID;
    
    3) Scroll down a few lines until you see the code,
    
    ?>
    
    4) Directly underneath add the code below,
    
    <?php if($user_identity){?>
    <script language="JavaScript">
    <!--
    var userName = "<?php echo $user_identity;?>";
    var userID = "<?php echo $user_ID;?>";
    var roomID = "Lobby";
    // -->
    </script>
    <script language="JavaScript" type="text/javascript" src="prochatrooms/chat.js"></script>
    <?php }?>
    
    5) Scroll down the file until you see,
    
    <li class="page_item"><a href="<?php echo get_option('home'); ?>/">Home</a></li>
    
    6) Now add the code below underneath,
    
    <?php if($user_identity){?>
    <li class="page_item"><a href="javascript:launchChat();">Live Chat</a></li>
    <?php }else{?>
    <li class="page_item"><a href="javascript:alert('Members Only!');">Live Chat</a></li>
    <?php }?>
    
    Thats it! You can now auto-login to your Pro Chat Rooms by clicking the link 'Live Chat'.

    Wordpress 2.6.x:

    WordPress file to edit: wordpress/wp-admin/admin-header.php
    
    1) Scroll down the file until you see the following code,
    
    </head>
    
    2) Directly above </head> add the code below,
    
    <script language="JavaScript">
    <!--
    var userName = "<?php echo $user_identity;?>";
    var userID = "-1";
    var roomID = "Lobby";
    // -->
    </script>
    <script language="JavaScript" type="text/javascript" src="http://www.YOURWEBSITE.com/prochatrooms/chat.js"></script>
    
    3) Scroll down the file until you see the code below (approx line 133),
    
    <div id="user_info"><p><?php printf(__('Howdy, <a href="%1$s">%2$s</a>!'), 'profile.php', $user_identity) ?> |
    
    4) Add the code below after the last ?> | characters in the code above,
    
    <a href="javascript:void(0)" onClick="launchChat()" title="Chat Room">Chat Room</a> |

    Is there anything I can do from the integration examples above to get this working with BuddyPress. Once again, I really appreciate any help with this, thanks

    Rob.

  • godrob

    Again, thank you for your help. I'm getting nearer, I think...

    In the code below, for security reasons I have replaced my actual domain name with 'http://www.mydomain.com'

    The code was added to the <head> section of my BuddyPress themes 'header.php' file

    Here's what's happening:

    <?php
    	global $current_user;
            get_currentuserinfo();
    ?>
    		<script language="JavaScript">
    		<!--
    		var userName = "<?php echo $user_login;?>";
    		var userID = "<?php echo $user_ID;?>";
    		var roomID = "Lobby";
    		// -->
    		</script>
    
    <script language="JavaScript" type="text/javascript" src="http://www.mydomian.com/chatroom/chat.js"></script>

    I've created a new BuddyPress page that links to the chat room with the following code:

    <a href="javascript:void(0)" onClick="launchChat()" title="Chat Room">Chat Room</a>

    I am logged into my BuddyPress site as 'Admin' and when I click on the Chat Room link a new page opens which should be the chatroom, but it's blank... The URL that gets displayed is:

    http://www.mydomain.com/chatroom/index.php?uid=1&uname=&room=Lobby

    As you will see the URL above isn't parsing the 'uname' variable for some reason. However, If I manually modify the URL to read:

    http://www.mydomain.com/chatroom/index.php?uid=1&uname=admin&room=Lobby

    Then it works!

    In header.php I have tried a combination of:

    var userName = "<?php echo $user_identity;?>";
    var userName = "<?php echo $display_name;?>";
    var userName = "<?php echo $user_login;?>";

    ...But nothing seems to parse the logged in username

    What am I doing wrong, any help appreciated.

    Thanks
    Rob.

  • godrob

    I finally got this working. So, many thanks for all the pointers and help here. In the end, adding the following to my theme's 'header.php' file resolved the issue

    <?php
    		global $current_user;
            get_currentuserinfo();?>
    
    		<script language="JavaScript">
    		<!--
    		var userName = "<?php echo $current_user->user_login;?>";
    		var userID = "<?php echo $user_ID;?>";
    		var roomID = "Lobby";
    		// -->
    		</script>
    
            <script language="JavaScript" type="text/javascript" src="http://www.mydomian.com/chatroom/chat.js"></script>

    Thanks again
    Rob

  • philipjcowan

    On a related but different issue, I too am pretty new to BuddyPress. I am setting up a Social Network stie for teachers and lecturers, focussing on Media and Journalism, although eLearning might be another topics I would include.

    At the moment, my two main issues are the following:

    1. I am having trouble editing the tabs along the top of the site. I simply want: Home, Blogs, Members, Forums and Help.

    Activity doesn't mean anything to anyone but it won't go, no matter what I do. Blogs can have child pages, according to members and topics, as can some of the others, but I am not too fussed about that at the moment. I really just want rid of Activities and to have Blogs in there instead.

    2. I need members to be able to sign in and upload materials. This can be done in Forums (which is fine, though not ideal) but my current plugin is restricts the size of the upload to 500kb, which is not enough for many files.

    Any suggestions? Be cool if some of you could join the site — I really need members!

    Philip Cowan

  • Mason

    Hiya Philip,

    First off welcome to WPMU DEV!

    I'd just point out firstly that sometimes these older threads get over-looked. Your best bet for support is to open a new thread - unless you're having the exact issue and the thread is currently active :slight_smile:

    That being said, I see you're using the default BuddyPress template. At the moment, it doesn't support custom menu navigation. That means you'll need to create a child theme and edit some of the code to re-arrange or remove the nav links.

    Alternatively, you can browse through our BuddyPress themes here. Almost all of them now support custom menu navigation and may better suit your needs here.
    https://premium.wpmudev.org/buddypress-themes/

    The studio theme: https://premium.wpmudev.org/project/studio-theme
    and educlean theme: https://premium.wpmudev.org/project/the-edublogs-homepage-theme
    are two of my favorites. Both of them allow you to create your own menu from within the WordPress Admin area.

    Hope this helps!

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.