Skip to content

Instantly share code, notes, and snippets.

@PabloVallejo
Created August 1, 2013 15:02
Show Gist options
  • Save PabloVallejo/6132227 to your computer and use it in GitHub Desktop.
Save PabloVallejo/6132227 to your computer and use it in GitHub Desktop.
logged_in_class
diff --git a/application/helpers/user.php b/application/helpers/user.php
index ce949c5..bf40944 100644
--- a/application/helpers/user.php
+++ b/application/helpers/user.php
@@ -1,4 +1,4 @@
-<?php
+<?php
/**
*
* Helper functions are intended for being accessible
@@ -14,12 +14,34 @@
|--------------------------------------------
|
| function foo( $a ) {
-| // Do stuff...
+| // Do stuff...
| }
-|
+|
+*/
+
+/**
+* Echoes classes if the user is logged in
+*
+* @param { string } class to add when user logged in
+* @param { string } class to add when user is not logged in
+* @return { null } echoes the string
*/
+function logged_in_class( $logged_in = "", $not_logged_in = "" ) {
+
+ if ( ! is_string( $logged_in ) && ! is_numeric( $logged_in ) )
+ return;
+
+ if ( ! is_string( $not_logged_in ) && ! is_numeric( $not_logged_in ) )
+ return;
+
+ // Is user logged in?
+ if ( is_user_logged_in() )
+ echo $logged_in;
+ else
+ echo $not_logged_in;
+}
?>
\ No newline at end of file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment