Advertisement
Guest User

Password Content Shortcode mod

a guest
Sep 30th, 2014
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.23 KB | None | 0 0
  1. function cspassword_shortcode($atts, $content = null) {
  2.     if (!isset($_SESSION)) session_start();
  3.     extract(shortcode_atts(array(
  4.         'password' => ''
  5.     ), $atts));
  6.  
  7.     $csp_text   = get_option('cspassword_text', __("Content with a password", "cs-password"));
  8.     $csp_submit = get_option('cspassword_submit', __("Access", "cs-password"));
  9.     $csp_error  = get_option('cspassword_error', __("Access Denied", "cs-password"));
  10.  
  11.     $form = '
  12.     <form action="#csp_form" method="post" class="csp_form" id="csp_form">
  13.         '.$csp_text.'
  14.         <input type="password" size="20" name="csp_input">
  15.         <input type="submit" name="csp_submit" value="'.$csp_submit.'">
  16.     </form>
  17.     ';
  18.  
  19.     if (isset($_POST['csp_submit'])) {
  20.         if ($_POST['csp_input'] == $password AND $password != '') {
  21.             $_SESSION['cclc_full_post_access_' . $post->ID] = true; //added by dbrellis
  22.         }
  23.         else {
  24.             $_SESSION['cclc_full_post_access_' . $post->ID] = false; //added by dbrellis
  25.             return '
  26.             '.$form.'
  27.             <strong>
  28.             '.$csp_error.'
  29.             </strong>
  30.             ';
  31.         }
  32.     }
  33.     if($_SESSION['cclc_full_post_access_' . $post->ID] === true)
  34.         return '<div id="csp_form" style="display:none;"></div>'. do_shortcode($content);
  35.     else return $form;
  36.  
  37.    
  38. }
  39. add_shortcode('cspasswordcode', 'cspassword_shortcode');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement