diff --git a/components/shortcodes/shortcodes.php b/components/shortcodes/shortcodes.php index 9e647a7..ffbe7fd 100644 --- a/components/shortcodes/shortcodes.php +++ b/components/shortcodes/shortcodes.php @@ -22,6 +22,7 @@ function members_component_shortcodes_register_shortcodes() { add_shortcode( 'access', 'members_access_check_shortcode' ); add_shortcode( 'feed', 'members_access_check_shortcode' ); add_shortcode( 'is_user_logged_in', 'members_is_user_logged_in_shortcode' ); + add_shortcode( 'is_user_not_logged_in', 'members_is_user_not_logged_in_shortcode' ); add_shortcode( 'get_avatar', 'members_get_avatar_shortcode' ); add_shortcode( 'avatar', 'members_get_avatar_shortcode' ); } @@ -88,6 +89,28 @@ function members_is_user_logged_in_shortcode( $attr, $content = null ) { return do_shortcode( $content ); } +/** + * Displays content if the user viewing it is currently not logged in. + * + * Content needs to be wrapped with this shortcode like + * [is_user_not_logged_in]This is content.[/is_user_not_logged_in]. + * + * @since 0.1 + * @uses is_user_logged_in() Checks if the current user is logged in. + * @param $attr array Attributes for the shortcode (not usefule here). + * @param $content string The content located between the opening and closing of the shortcode. + * @return $content string The content to be shown. + */ +function members_is_user_not_logged_in_shortcode( $attr, $content = null ) { + + /* If it is a feed or the user is not logged in, return nothing. */ + if (is_user_logged_in() ) + return ''; + + /* Return the content. */ + return do_shortcode( $content ); +} + /** * Content that should only be shown in feed readers. Can be useful for * displaying feed-specific items. @@ -168,4 +191,4 @@ function members_login_form_shortcode() { return wp_login_form( array( 'echo' => false ) ); } -?> \ No newline at end of file +?> diff --git a/includes/shortcodes.php b/includes/shortcodes.php index 6672e49..5b3b080 100644 --- a/includes/shortcodes.php +++ b/includes/shortcodes.php @@ -28,6 +28,9 @@ function members_register_shortcodes() { /* Add the [is_user_logged_in] shortcode. */ add_shortcode( 'is_user_logged_in', 'members_is_user_logged_in_shortcode' ); + /* Add the [is_user_not_logged_in] shortcode. */ + add_shortcode( 'is_user_not_logged_in', 'members_is_user_not_logged_in_shortcode' ); + /* @deprecated 0.2.0. */ add_shortcode( 'get_avatar', 'members_get_avatar_shortcode' ); add_shortcode( 'avatar', 'members_get_avatar_shortcode' ); @@ -53,6 +56,23 @@ function members_is_user_logged_in_shortcode( $attr, $content = null ) { return do_shortcode( $content ); } +/** + * Displays content if the user viewing it is currently not logged in. + * + * @param $attr array Attributes for the shortcode (not used). + * @param $content string The content located between the opening and closing of the shortcode. + * @return $content string The content to be shown. + */ +function members_is_user_not_logged_in_shortcode( $attr, $content = null ) { + + /* If it is a feed or the user is not logged in, return nothing. */ + if (is_user_logged_in() || is_null( $content ) ) + return ''; + + /* Return the content. */ + return do_shortcode( $content ); +} + /** * Content that should only be shown in feed readers. Can be useful for displaying feed-specific items. * @@ -141,4 +161,4 @@ function members_login_form_shortcode() { return wp_login_form( array( 'echo' => false ) ); } -?> \ No newline at end of file +?>