This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!

Member Shortcodes

By: Ipstenu on Jul 4th, 2012  |  syntax: PHP  |  size: 1.72 KB  |  views: 61  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <?php
  2.  
  3. /*
  4. Plugin Name: Logged In and Out Shortcodes
  5. Description: Shortcodes for users logged in and out.
  6. Version: 1.0
  7. Author: Ipstenu (Mika Epstein)
  8. License: MIT
  9.  
  10. Initial shortcode lifted from Justin Tadlock's Members plugin - http://wordpress.org/extend/plugins/members/
  11.  
  12. */
  13.  
  14. // [loggedin_message]This content is only shown to logged-in users.[/is_user_logged_in]
  15. // Shows content to logged in users
  16.  
  17. add_shortcode( 'loggedin_message', 'ippy_loggedin_message_shortcode' );
  18. function ippy_loggedin_message_shortcode( $attr, $content = null ) {
  19.  
  20.         /* If it is a feed or the user is not logged in, return nothing. */
  21.         if ( is_feed() || !is_user_logged_in() || is_null( $content ) )
  22.                 return '';
  23.  
  24.         /* Return the content. */
  25.         return do_shortcode( $content );
  26. }
  27.  
  28.  
  29. // [loggedout_message]This content is only shown to logged-in users.[/is_user_logged_in]
  30. // Shows content to logged out users :)
  31.  
  32. add_shortcode( 'loggedout_message', 'ippy_loggedout_message_shortcode' );
  33. function ippy_loggedout_message_shortcode( $attr, $content = null ) {
  34.  
  35.         /* If it is a feed or the user is not logged in, return nothing. */
  36.         if ( is_user_logged_in() || is_null( $content ) )
  37.                 return '';
  38.  
  39.         /* Return the content. */
  40.         return do_shortcode( $content );
  41. }
  42.  
  43. // [loginform]
  44. // Shows an inline login form.
  45.  
  46. function ippy_loginform_shortcode( $atts, $content = null ) {
  47.  
  48.         extract( shortcode_atts( array(
  49.       'redirect' => ''
  50.       ), $atts ) );
  51.  
  52.         if (!is_user_logged_in()) {
  53.                 if($redirect) {
  54.                         $redirect_url = $redirect;
  55.                 } else {
  56.                         $redirect_url = get_permalink();
  57.                 }
  58.                 $form = wp_login_form(array('echo' => false, 'redirect' => $redirect_url ));
  59.         }
  60.         return $form;
  61. }
  62. add_shortcode('loginform', 'ippy_loginform_shortcode');
clone this paste RAW Paste Data