Support » Fixing WordPress » [Plugin: Simple Facebook Connect] How To Create If Else Statement

  • Resolved jtdesign00

    (@jtdesign00)


    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/

Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator Samuel Wood (Otto)

    (@otto42)

    WordPress.org Admin

    if (sfc_get_user()) {
    // user is connected
    } else {
    // user is not connected
    }

    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!

    Moderator Samuel Wood (Otto)

    (@otto42)

    WordPress.org Admin

    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>

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

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘[Plugin: Simple Facebook Connect] How To Create If Else Statement’ is closed to new replies.