WordPress.org

Ready to get started?Download WordPress

Forums

Simple Facebook Connect
[resolved] How To Create If Else Statement (5 posts)

  1. jtdesign00
    Member
    Posted 3 years ago #

    I'm trying to create an If Else statement, where the site reads if the user is logged into FB Connect it shows one thing, and if a user is not logged into FB Connect, it shows another. I've been through the plugin code (as well as Google) to look for examples, but I haven't found anything that has been helpful. I'm sure this is quite simple for someone with more FB Connect experience than I have.

    Thanks in advance!

    http://wordpress.org/extend/plugins/simple-facebook-connect/

  2. Samuel Wood (Otto)
    Tech Ninja
    Plugin Author

    Posted 3 years ago #

    if (sfc_get_user()) {
    // user is connected
    } else {
    // user is not connected
    }
  3. jtdesign00
    Member
    Posted 3 years ago #

    Hi Otto,
    thanks for the quick response! I apologize for my ignorance, but I'm not 100% on how to implement that then.

    This is what I've tried so far just as something simple and it doesn't return anything.

    <div id="profile">If Profile</div>
    <div id="guest">If Guest</div>
    
    <script>
    if (sfc_get_user()) {
    	document.getElementById('guest').style.display = "none"; //hide guest
    	document.getElementById('profile').style.display = "block"; //show profile
    } else {
    	document.getElementById('guest').style.display = "block"; //show guest
    	document.getElementById('profile').style.display = "none"; //hide profile
    }
    </script>

    Thank you again and thanks for the awesome plugin!

  4. Samuel Wood (Otto)
    Tech Ninja
    Plugin Author

    Posted 3 years ago #

    No, that's PHP code, not javascript. You'd need to encapsulate it in PHP blocks.

    <div id="profile">If Profile</div>
    <div id="guest">If Guest</div>
    
    <script>
    <?php if (sfc_get_user()) { ?>
    	document.getElementById('guest').style.display = "none"; //hide guest
    	document.getElementById('profile').style.display = "block"; //show profile
    <?php } else { ?>
    	document.getElementById('guest').style.display = "block"; //show guest
    	document.getElementById('profile').style.display = "none"; //hide profile
    <?php } ?>
    </script>
  5. jtdesign00
    Member
    Posted 3 years ago #

    Beautiful! Works perfectly. Sorry again for my ignorance on the subject.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic