Support Forum

Trying to call Simplepress profile and avatar into a CBox chat box

NA Nate
Nate
Member

I use a chat box on my website called CBox (www.cbox.ws) and it allows WordPress user integration and also avatar and profile integration. I don’t know if this is possible but I would like to call the profile and avatar from Simplepress into the chat box.

Here’s the code they gave me http://pastebin.com/K0Pc8nYZ 
There’s 2 instances of each: $avatar_url and $profile_url and in these places I’m supposed to “Change $avatar_url and $profile_url to the correct variables for the context.” Any idea what simplepress code I should put in these places or is this not going to work?

35 Answers

New Answer

MP Mr Papa
Mr Papa
Member

assuming you wanted to do this for logged in users only, take a look at this:

http://codex.simple-press.com/codex/api/template-functions-and-the-api/display-template-functions/common-view/sp_useravatar/

its how you get the current users avatar… since it will be on non forum pages, I would call it with:

global $current_user; $avatar = sp_UserAvatar(‘get=1&context=user’, $current_user->ID)

then replace $avatar_url with $avatar->url in their code…

for the $profile_url, simply use http://yoursite.com/forum/profile

of course, replace http://yoursite.com/forum with the actual url of your forum main page…

NA Nate
Nate
Member

Thanks for the reply. Neither the avatar or profile works. This is what the CBox admin said:

Change this block: <?php global $user_ID, $user_identity ?>

to: <?php global $user_ID, $user_identity; $profile_url = “http://www.rockitpro.com/sf-forum/profile/” ?>

And then replace both instances of http://www.rockitpro.com/sf-forum/profile/ later in your code with $profile_url

Also, as it stands the profile URL will be the same for every user. You probably want to append some variable to the end of the URL to specify which profile to link. I’m not sure how it works for your setup, but it may be something like:

<?php global $user_ID, $user_identity; $profile_url = “http://www.rockitpro.com/sf-forum/profile/?user=“.$user_ID; ?>

Is there a simplepress variable I need to use along with the profile link? I logged into several names to test and when I click on a name in the chatbox, it takes me to MY profile edit page, not the page to view the user’s profile I clicked.

MP Mr Papa
Mr Papa
Member

this all gets back to what I asked originally…  is this for the current logged in user??? 

a profile url IS THE SAME for all logged in users…  when you are logged in, under whatever account, the logged in user profile is http://yoursite.com/forum/profile

but if you dont want the current user and want a specific user, you would do something like:

http://yoursite.com/forum/profile/user-login

just replace the user-login with the user login for the desired user…  keep in mind, if you dont have access to view that profile, you wont be able to…  permission is based on your settings…  by default it would be allowed…

but lets step back a minute…   you have a really old url structure there… just want to make sure you are running sp version 5.x (since you posted in that forum)…  version 4.x and 5.x are quite different here…  and it almost seems as if you are trying to reference 4.x or the chat folks remember working with 4.x… but since you posted in the 5.x forum, I am giving you 5.x answer…

can you provide more info on the avatar?

NA Nate
Nate
Member

I recently updated from 4.0 to 5.2.6 a couple of weeks ago so my url structure is still sf-forum. Let me try to word this better, I basically need the call/code to view other people’s profile.

CBox is not a plugin but has a WordPress User Integration option on their site that I enabled, it checks to see if a user of your WordPress site is logged in and then allows that user to post a message in the chat box without having to log into the chat box separately. So when a user logs into my site they are also logged into the chat box.

If a logged in user says something in the chat box, I want their username to link to their SimplePress profile so that other members can view the profiles. I just need a code that checks the user that’s logged in and then links their username to their specific profile. It’s like when you click a username in the forum, the popup profile pops up and there’s a link at the bottom of the popup to “View Full Profile For UsernameHere”, I need that in the chatbox…not the popup (unless it’s possible without adding more scripts to my non-forum page) but the direct link to the user’s profile.

As for the avatar, I’m going to speak to the CBox admin and see what he says, he forgot to tell me more about that issue.

MP Mr Papa
Mr Papa
Member

so yeah, then use the last one I gave you:

http://yoursite.com/sf-forum/profile/user-login…

if you need some code, try:

global $current_user;
sp_forum_api_support();
$profile_url = sp_url().urlencode($current_user->data->user_login);

NA Nate
Nate
Member

Using this code http://pastebin.com/tbYbYrgL and it doesn’t work, it still links the chatbox poster’s username to http://www.rockitpro.com/sf-forum/profile/ which obviously takes me to my own edit profile page, I’m not that knowledgeable in coding really so I’m probably doing something wrong lol. I feel like I need something like:

<?php global $user_ID, $user_identity; $profile_url = "http://www.rockitpro.com/sf-forum/profile/<?php echo get_the_author(); ?>" ?>

Not that but in that style so it grabs the user that posted the message and displays that user’s specific profile link.

MP Mr Papa
Mr Papa
Member

the code in your pastebin is trashing (overwriting) the code I gave you….

$profile_url = “http://www.rockitpro.com/sf-forum/profile/user-login” ?

overwrites the correct $profile_url from above that I gave you…  remove it…

and I dont see the code I gave your $avatar_url either…

MP Mr Papa
Mr Papa
Member

to be clear, use this at top – before the begin cbox stuff…

    <?php 
    global $current_user;
    sp_forum_api_support();
    $profile_url = sp_url().urlencode($current_user->data->user_login);
    $avatar = sp_UserAvatar('get=1&context=user', $current_user->ID);
    $avatar_url = $avatar->url;
    global $user_ID, $user_identity; 
    ?>
NA Nate
Nate
Member

So this? http://pastebin.com/Ams6ZhqH
I put that code in but it still links the username to http://www.rockitpro.com/sf-forum/profile/ and not for example http://www.rockitpro.com/sf-forum/profile/Sho-Down and doesn’t show avatars ( testing on the sidebar on this page http://www.rockitpro.com/testimonies/ )

I’m chalking this up to a problem with the CBox, I’ll run this new code (if I did it correctly) by the CBox admin and see what he says on why it doesn’t work. Thanks for the help.

MP Mr Papa
Mr Papa
Member

is this on a standard page within the wp hierarchy???  if so, that wp global should be available… you could try using the SP global instead which should be set up by the api call…

    <?php 
    sp_forum_api_support();
    global $spThisUser;
    $profile_url = sp_url().urlencode($spThisUser->user_login);
    $avatar = sp_UserAvatar('get=1&context=user', $spThisUser->ID);
    $avatar_url = $avatar->url;
    global $user_ID, $user_identity; 
    ?>
NA Nate
Nate
Member

It’s in the sidebar303.php on this page http://www.rockitpro.com/testimonies/ (right sidebar)

I tried your latest code and that didn’t work either. I’ve spent all day on this so I think I’m going to bow out lol, I’ve been defeated.

MP Mr Papa
Mr Papa
Member

defeated?  never…  but looking at that page, and what is actually going on, I am going to go back to my very first question… is this for the logged in user???

now I can see the answer is no…  so whole different ball game…

not sure where some of the variables in your code come from – should be cbox… so try this:

    <?php 
    global $user_ID, $user_identity; 
    sp_forum_api_support();
    $user_login = get_user_meta($user_ID, 'user_login', true);
    $profile_url = sp_url().urlencode($user_login);
    $avatar = sp_UserAvatar('get=1&context=user', $user_ID);
    $avatar_url = $avatar->url;
    ?>

lol, would be a lot easier if I was on the server and could inspect stuff! ;)

NA Nate
Nate
Member

I guess you’re right, guests can see the chat box and see all users that have posted in it, the guests just can’t post a message in the chat box until they log in to my website.

That new code doesn’t change anything. I can send you my sidebar303.php file if you give me an email or a way to send through here.

The chat box settings are in my account on www.CBox.ws, so the only cbox code on my website is what I posted in my last pastebin and this is the integration page in my cbox account:

cbox settings
MP Mr Papa
Mr Papa
Member

well, still not sure we are talking apples to apples…  what is $user_id???  is the id of the user INSIDE the chatbox that you want a profile for?  its going to be up to the cbox to tell us the ID of that user within the chatbox who posted…  given that variable – and I have been assuming you are saying its $user_ID – I can create the urls for you… 

but from the last post, I cannot tell if that is true…

at this point, easiest thing to do, if you are willing, is to send me via pm, a temp wp admin account for the site and ftp credentials…  then I can play and debug and try to get it working…