Skip to content
This repository has been archived by the owner on Sep 27, 2022. It is now read-only.

Added a is_user_not_logged_in shortcode #30

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 24 additions & 1 deletion components/shortcodes/shortcodes.php
Expand Up @@ -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' );
}
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -168,4 +191,4 @@ function members_login_form_shortcode() {
return wp_login_form( array( 'echo' => false ) );
}

?>
?>
22 changes: 21 additions & 1 deletion includes/shortcodes.php
Expand Up @@ -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' );
Expand All @@ -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.
*
Expand Down Expand Up @@ -141,4 +161,4 @@ function members_login_form_shortcode() {
return wp_login_form( array( 'echo' => false ) );
}

?>
?>