Topic-icon Coding example to conditionally show/hide button?

Active Subscriptions:

None
13 years 4 months ago #30447 by davlar
Hi,

I wonder if you could help me with (hopefully) little coding example. I was hoping to conditionally show/hide the bespoke JFBConnect button here if the user has already connected fb: profr.me/subscribe. Some users who have already connected, return to this page to change or upgrade their plan. At the moment it shows to everyone, including those who have already connected which doesn't really make sense.

Many thanks in advance.

David
The topic has been locked.
Support Specialist
13 years 4 months ago #30473 by alzander
David,
Unrelated, but worth pointing out, the error message at the top of that page says: "Either you do not have subscribed any plan or your subscription has been expired. Please subscribe a plan to access this link."
I'd recommend updating that as the first part, "Either you do not have subscribed" is confusing.

As to your question, the following PHP should be what you're looking for:
<?php $jfbcLibrary = JFBConnectFacebookLibrary::getInstance();
if ($jfbcLibrary->userIsConnected())
   echo 'Your text or HTML here for when a user is connected";
else
   echo "Your text or HTML here for when a user is NOT connected";
?>
Of course test, and let us know how that goes. Hopefully, that's all you need, but if not, we'll help how we can.

Thanks,
Alex
The topic has been locked.
Active Subscriptions:

None
13 years 4 months ago #30483 by davlar
Yes - that's some PayPlans default language, which is awful, I agree. A lot of their language file is terribly bad English and needs to be completely rewritten. It's on the list! :rolleyes:

Many thanks for the code - will test and report back.
The topic has been locked.
Active Subscriptions:

None
13 years 4 months ago #30485 by davlar
Works great. I went with this, but same same:
<?php $jfbcLibrary = JFBConnectFacebookLibrary::getInstance(); 
if ($jfbcLibrary->userIsConnected()):?>
<h3>You are connected with Facebook</h3>
<?php else:?>
<h3>1: Connect with Facebook (optional):<a href="javascript:void(0)" onclick="jfbc.login.login_custom();"><img src="button.png" /></a> for fast and secure sign up.</h3>
<h3>2: Select an option</h3>
<?php endif;?>

Any tips on how to get the user's name in there. E.g. "You are connected with Facebook as Dick Cheney"?
The topic has been locked.
Support Specialist
13 years 4 months ago #30495 by alzander
David,
Getting their name is really easy. However, and I can't stress this enough, what's posted below is going to change in the 5.0 release, coming out in mid-February. So, if you implement this and upgrade, any pages using it will likely break after the upgrade...

So, to get name 'n stuff, you can do the following:
<?php $jfbcLibrary = JFBConnectFacebookLibrary::getInstance();
$fields = array('first_name', 'last_name');
$profile = $getUserProfile($jfbcLibrary->getFbUserId(), $fields);
echo $profile['first_name']." ".$profile['last_name'];
In 5.0, the above code will mostly work (though won't be the best way to do it, honestly). The main change you'd need is to access the $profile variable like $profile->get('first_name'); Small change, but required.

Hope that helps, again, but if you need anything else, let us know,
Alex
The topic has been locked.