Members Only Content Shortcode

This shotcode allows you to write a private content in a post. For non-members, the login form will appear.

Usage:

[mem] ..content.. [/mem]

Code Snippet:

function member( $atts, $content = null ) {
       if  ( is_user_logged_in() && !is_null( $content ) && !is_feed() ) {
              return $content;
              return '';
       } else {
 
       $yonlendir = get_permalink();
              $form = wp_login_form(array('echo' => false, 'redirect' => $yonlendir ));
              return $form;
       }
}
add_shortcode( 'mem', 'member' );

Posted in Snippets