Plugin Directory

Changeset 951684


Ignore:
Timestamp:
07/19/2014 09:14:33 PM (12 years ago)
Author:
natereist
Message:

Adding new functionality for modifying the default wordpress expiration postpass cookie and cleaning up some login and code. Updated stable tag and version number.

Location:
protected-posts-logout-button
Files:
6 edited
1 copied

Legend:

Unmodified
Added
Removed
  • protected-posts-logout-button/tags/1.3.1/logout.js

    r545060 r951684  
    11jQuery(document).ready(function($){
    22    $('input.button.logout').click(function(){
    3                 var data = {
    4                     action : "pplb_logout"
    5                 }
    6                
    7                 $.post(MyAjax.ajaxurl, data, function(response) {
    8                     if(response == '0'){
    9                        
    10                     }
    11                     else{
    12                         $('body').append('<p style="display:none;" id="pplb-message">'+response+'<p>');
    13                         var text = $('#pplb-message').text();
    14                         alert(text);
    15                     }
    16                     document.location.href = document.location.href;
    17                 });
    18             });
    19         });
     3        var data = {
     4            action : "pplb_logout"
     5        }
     6       
     7        $.post( pplb_ajax.ajaxurl, data, function( response ) {
     8            if( response.status == 0 ){
     9                // nothing hanppens
     10            }
     11            else{
     12                alert( response.message );
     13            }
     14            document.location.href = document.location.href;
     15        }, "JSON" );
     16    });
     17});
  • protected-posts-logout-button/tags/1.3.1/pplb_logout_button.php

    r666044 r951684  
    44    Plugin URI: http://omfgitsnater.com/protected-posts-logout-button/
    55    Description: A plugin built to add a logout button automatically to protected posts.
    6     Version: 1.3
     6    Version: 1.3.1
    77    Author: Nate Reist
    88    Author URI: http://omfgitsnater.com
     
    1818   
    1919    //Check if the post has a password and we are inside the loop.
    20     if(!empty($post->post_password) && in_the_loop()){
     20    if ( !empty( $post->post_password) && in_the_loop() ){
    2121        //Check to see if the password has been provided.
    22         if(!post_password_required(get_the_ID())){
     22        if ( !post_password_required( get_the_ID() ) ) {
    2323            //add the logout button to the output.
    2424            $options = get_option('pplb_options');
    25             $class = (array_key_exists('pplb_button_class', $options)) ? $options['pplb_button_class'] : '';
     25            $class = ( array_key_exists('pplb_button_class', $options) ) ? $options['pplb_button_class'] : '';
    2626            $html .= ' <input type="button" class="button logout '.esc_attr($class).'" value="logout">';
    2727        }
     
    4040    $html = '';
    4141    // Check if the post has a password
    42     if(!empty($qpost->post_password)){
     42    if ( !empty( $qpost->post_password ) ) {
    4343        // Check to see if the password has been provided.
    4444        if(!post_password_required($qid)){
     
    5858function pplb_protected_logout(){
    5959    // Set the cookie to expire ten days ago... instantly logged out.
    60     setcookie('wp-postpass_' . COOKIEHASH, stripslashes( '' ), time() - 864000, COOKIEPATH);
     60    setcookie( 'wp-postpass_' . COOKIEHASH, stripslashes( '' ), time() - 864000, COOKIEPATH );
    6161    $options = get_option('pplb_options');
    6262    $pplb_alert = (array_key_exists('pplb_alert', $options)) ? $options['pplb_alert'] : 'no';
    63     if($pplb_alert == 'yes'){
    64         echo stripslashes($options['pplb_message']);
     63   
     64    $response = array(
     65        'status'    => 0,
     66        'message'   => ''
     67    );
     68   
     69    if ( $pplb_alert == 'yes' ) {
     70        $response['status'] = 1;
     71        $response['message'] = stripslashes( $options['pplb_message'] );
     72    }
     73    else {
     74        $response['status'] = 0;
     75        $response['message'] = '';
     76    }
     77    wp_send_json( $response );
     78}
     79
     80/*
     81    Enqueue the scripts.
     82*/
     83function pplb_logout_js(){
     84    wp_register_script( 'pplb_logout_js', plugins_url( '/logout.js', __FILE__ ), array('jquery'), null );
     85    wp_enqueue_script( 'pplb_logout_js' );
     86    wp_localize_script( 'pplb_logout_js', 'pplb_ajax', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) );
     87}
     88
     89/*
     90    Filter the expiration time if necessary based upon the option.
     91*/
     92function pplb_change_postpass_expires( $expire ){
     93    $new_expire = get_option( 'pplb_pass_expires', false );
     94    if( $new_expire !== false ){
     95        return time() + $new_expire;
    6596    }
    6697    else{
    67         echo 0;
    68     }
    69     die();
    70 }
    71 
    72 /*
    73     Enqueue the scripts.
    74 */
    75 function pplb_logout_js(){
    76     wp_register_script('pplb_logout_js', plugins_url('/logout.js', __FILE__), array('jquery'));
    77     wp_enqueue_script('pplb_logout_js');
    78     wp_localize_script( 'pplb_logout_js', 'MyAjax', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) );
    79 }
     98        return $expire;
     99    }
     100}
     101add_filter( 'post_password_expires','pplb_change_postpass_expires', 10, 1 );
    80102
    81103/*
     
    83105*/
    84106function pplb_settings_page(){
    85     if(isset($_POST['pplb_action'])){
     107    if ( isset( $_POST['pplb_action'] ) ) {
    86108        //update the option.
    87109        $options = array();
    88         $options['pplb_alert'] = (array_key_exists('pplb_alert', $_POST)) ? $_POST['pplb_alert']: 'no';
    89         $options['pplb_message'] = esc_js($_POST['pplb_message']);
     110        $options['pplb_alert'] = ( array_key_exists('pplb_alert', $_POST) ) ? $_POST['pplb_alert']: 'no';
     111        $options['pplb_message'] = esc_js( $_POST['pplb_message'] );
    90112        $options['pplb_button_class'] = esc_attr($_POST['pplb_button_class']);
    91113        update_option('pplb_options', $options);
    92114       
     115        $expire = ( isset( $_POST['pplb_pass_expires'] ) && $_POST['pplb_pass_expires'] != '' ) ? $_POST['pplb_pass_expires']: false;
     116        update_option('pplb_pass_expires', $expire );
     117       
    93118        $filter = isset($_POST['pplb_button_filter']) ? $_POST['pplb_button_filter']: 'yes';
    94119        update_option('pplb_button_filter', $filter);
    95120    }
    96121    $new_options = get_option('pplb_options');
    97     if(is_array($new_options)){
     122    if ( is_array($new_options ) ) {
    98123        extract($new_options); 
    99124    }
     
    119144                        <th><label>Automatically add button to protected pages:</label></th><td>
    120145                        <select name="pplb_button_filter">
    121                             <option value='yes' <?php selected(get_option('pplb_button_filter'), 'yes'); ?>>Yes</option>
    122                             <option value='no' <?php selected(get_option('pplb_button_filter'), 'no'); ?>>No</option>
     146                            <option value='yes' <?php selected( get_option('pplb_button_filter'), 'yes'); ?>>Yes</option>
     147                            <option value='no' <?php selected( get_option('pplb_button_filter'), 'no'); ?>>No</option>
    123148                        </select>
     149                        </td>
     150                    </tr>
     151                    <tr>
     152                        <?php $expire = get_option('pplb_pass_expires'); ?>
     153                        <th>
     154                            <label>Change the default cookie expire time for WordPress Protected Posts:</label>
     155                            <br />
     156                            <span class="description">In seconds, leave blank for default</span>
     157                        </th>
     158                        <td>
     159                            <input type="number" name="pplb_pass_expires" value="<?php echo $expire; ?>"> seconds = <span id="expire-human"></span>
     160                            <script type="text/javascript">
     161                                jQuery( document ).ready(function($){
     162                                    $( 'input[name="pplb_pass_expires"]' ).change( function(){
     163                                        if( $(this).val().length == 0 ){
     164                                            $('span#expire-human').text( '10 days (default value)' )
     165                                        }
     166                                        else{
     167                                            var word = 'minutes';
     168                                            var v = $( this ).val();
     169                                            if( v > ( 24 * 60 * 60 ) ){
     170                                                word = 'days';
     171                                            }
     172                                            else if( v > ( 60 * 60 ) ){
     173                                                word = 'hours';
     174                                            }
     175                                           
     176                                            switch( word ){
     177                                                case 'minutes':
     178                                                    conversion = v / 60;
     179                                                    break;
     180                                                case 'hours':
     181                                                    conversion = v / 60 / 60;
     182                                                    break;
     183                                                case 'days':
     184                                                    conversion = v / 60 / 60 / 24;
     185                                                    break;
     186                                                default:
     187                                                    conversion = v;
     188                                                    break;
     189                                            }
     190                                           
     191                                            var humanReadable = conversion + ' ' + word;
     192                                       
     193                                            $('span#expire-human').text( humanReadable );
     194                                        }
     195                                    } );
     196                                    $( 'input[name="pplb_pass_expires"]' ).trigger( 'change' );
     197                                });
     198                            </script>
    124199                        </td>
    125200                    </tr>
     
    174249*/
    175250function add_pplb_filter(){
    176     if(!get_option('pplb_button_filter')){
     251    if ( !get_option( 'pplb_button_filter' ) ) {
    177252        // if the option isn't set, assume we want it there.
    178253        update_option('pplb_button_filter', 'yes');
    179254    }
    180255    $add_filter = get_option('pplb_button_filter');
    181     if($add_filter == 'yes'){
     256    if ( $add_filter == 'yes' ) {
    182257        add_filter('the_content', 'pplb_logout_filter', 9999, 1);   // adds the button.
    183258    }
  • protected-posts-logout-button/tags/1.3.1/readme.txt

    r666044 r951684  
    44Tags: logout, password protected posts logout button, wordpress security
    55Requires at least: 2.8
    6 Tested up to: 3.5.1
    7 Stable tag: 1.3
     6Tested up to: 3.9.1
     7Stable tag: 1.3.1
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    1919* Has a simple settings page to make everything easier.
    2020* Allows you to alert user they have logged out.
    21 
    22 
    2321
    2422== Installation ==
     
    5452== Changelog ==
    5553
     54= 1.3.1 =
     55* Added the ability to change the default WordPress postpass cookie in the admin area.
     56* Cleaned up some logic and php code.
    5657= 1.3 =
    5758* Added conditional logic to the allow admin to disable the automatic filter.
  • protected-posts-logout-button/trunk/logout.js

    r545060 r951684  
    11jQuery(document).ready(function($){
    22    $('input.button.logout').click(function(){
    3                 var data = {
    4                     action : "pplb_logout"
    5                 }
    6                
    7                 $.post(MyAjax.ajaxurl, data, function(response) {
    8                     if(response == '0'){
    9                        
    10                     }
    11                     else{
    12                         $('body').append('<p style="display:none;" id="pplb-message">'+response+'<p>');
    13                         var text = $('#pplb-message').text();
    14                         alert(text);
    15                     }
    16                     document.location.href = document.location.href;
    17                 });
    18             });
    19         });
     3        var data = {
     4            action : "pplb_logout"
     5        }
     6       
     7        $.post( pplb_ajax.ajaxurl, data, function( response ) {
     8            if( response.status == 0 ){
     9                // nothing hanppens
     10            }
     11            else{
     12                alert( response.message );
     13            }
     14            document.location.href = document.location.href;
     15        }, "JSON" );
     16    });
     17});
  • protected-posts-logout-button/trunk/pplb_logout_button.php

    r666044 r951684  
    44    Plugin URI: http://omfgitsnater.com/protected-posts-logout-button/
    55    Description: A plugin built to add a logout button automatically to protected posts.
    6     Version: 1.3
     6    Version: 1.3.1
    77    Author: Nate Reist
    88    Author URI: http://omfgitsnater.com
     
    1818   
    1919    //Check if the post has a password and we are inside the loop.
    20     if(!empty($post->post_password) && in_the_loop()){
     20    if ( !empty( $post->post_password) && in_the_loop() ){
    2121        //Check to see if the password has been provided.
    22         if(!post_password_required(get_the_ID())){
     22        if ( !post_password_required( get_the_ID() ) ) {
    2323            //add the logout button to the output.
    2424            $options = get_option('pplb_options');
    25             $class = (array_key_exists('pplb_button_class', $options)) ? $options['pplb_button_class'] : '';
     25            $class = ( array_key_exists('pplb_button_class', $options) ) ? $options['pplb_button_class'] : '';
    2626            $html .= ' <input type="button" class="button logout '.esc_attr($class).'" value="logout">';
    2727        }
     
    4040    $html = '';
    4141    // Check if the post has a password
    42     if(!empty($qpost->post_password)){
     42    if ( !empty( $qpost->post_password ) ) {
    4343        // Check to see if the password has been provided.
    4444        if(!post_password_required($qid)){
     
    5858function pplb_protected_logout(){
    5959    // Set the cookie to expire ten days ago... instantly logged out.
    60     setcookie('wp-postpass_' . COOKIEHASH, stripslashes( '' ), time() - 864000, COOKIEPATH);
     60    setcookie( 'wp-postpass_' . COOKIEHASH, stripslashes( '' ), time() - 864000, COOKIEPATH );
    6161    $options = get_option('pplb_options');
    6262    $pplb_alert = (array_key_exists('pplb_alert', $options)) ? $options['pplb_alert'] : 'no';
    63     if($pplb_alert == 'yes'){
    64         echo stripslashes($options['pplb_message']);
     63   
     64    $response = array(
     65        'status'    => 0,
     66        'message'   => ''
     67    );
     68   
     69    if ( $pplb_alert == 'yes' ) {
     70        $response['status'] = 1;
     71        $response['message'] = stripslashes( $options['pplb_message'] );
     72    }
     73    else {
     74        $response['status'] = 0;
     75        $response['message'] = '';
     76    }
     77    wp_send_json( $response );
     78}
     79
     80/*
     81    Enqueue the scripts.
     82*/
     83function pplb_logout_js(){
     84    wp_register_script( 'pplb_logout_js', plugins_url( '/logout.js', __FILE__ ), array('jquery'), null );
     85    wp_enqueue_script( 'pplb_logout_js' );
     86    wp_localize_script( 'pplb_logout_js', 'pplb_ajax', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) );
     87}
     88
     89/*
     90    Filter the expiration time if necessary based upon the option.
     91*/
     92function pplb_change_postpass_expires( $expire ){
     93    $new_expire = get_option( 'pplb_pass_expires', false );
     94    if( $new_expire !== false ){
     95        return time() + $new_expire;
    6596    }
    6697    else{
    67         echo 0;
    68     }
    69     die();
    70 }
    71 
    72 /*
    73     Enqueue the scripts.
    74 */
    75 function pplb_logout_js(){
    76     wp_register_script('pplb_logout_js', plugins_url('/logout.js', __FILE__), array('jquery'));
    77     wp_enqueue_script('pplb_logout_js');
    78     wp_localize_script( 'pplb_logout_js', 'MyAjax', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) );
    79 }
     98        return $expire;
     99    }
     100}
     101add_filter( 'post_password_expires','pplb_change_postpass_expires', 10, 1 );
    80102
    81103/*
     
    83105*/
    84106function pplb_settings_page(){
    85     if(isset($_POST['pplb_action'])){
     107    if ( isset( $_POST['pplb_action'] ) ) {
    86108        //update the option.
    87109        $options = array();
    88         $options['pplb_alert'] = (array_key_exists('pplb_alert', $_POST)) ? $_POST['pplb_alert']: 'no';
    89         $options['pplb_message'] = esc_js($_POST['pplb_message']);
     110        $options['pplb_alert'] = ( array_key_exists('pplb_alert', $_POST) ) ? $_POST['pplb_alert']: 'no';
     111        $options['pplb_message'] = esc_js( $_POST['pplb_message'] );
    90112        $options['pplb_button_class'] = esc_attr($_POST['pplb_button_class']);
    91113        update_option('pplb_options', $options);
    92114       
     115        $expire = ( isset( $_POST['pplb_pass_expires'] ) && $_POST['pplb_pass_expires'] != '' ) ? $_POST['pplb_pass_expires']: false;
     116        update_option('pplb_pass_expires', $expire );
     117       
    93118        $filter = isset($_POST['pplb_button_filter']) ? $_POST['pplb_button_filter']: 'yes';
    94119        update_option('pplb_button_filter', $filter);
    95120    }
    96121    $new_options = get_option('pplb_options');
    97     if(is_array($new_options)){
     122    if ( is_array($new_options ) ) {
    98123        extract($new_options); 
    99124    }
     
    119144                        <th><label>Automatically add button to protected pages:</label></th><td>
    120145                        <select name="pplb_button_filter">
    121                             <option value='yes' <?php selected(get_option('pplb_button_filter'), 'yes'); ?>>Yes</option>
    122                             <option value='no' <?php selected(get_option('pplb_button_filter'), 'no'); ?>>No</option>
     146                            <option value='yes' <?php selected( get_option('pplb_button_filter'), 'yes'); ?>>Yes</option>
     147                            <option value='no' <?php selected( get_option('pplb_button_filter'), 'no'); ?>>No</option>
    123148                        </select>
     149                        </td>
     150                    </tr>
     151                    <tr>
     152                        <?php $expire = get_option('pplb_pass_expires'); ?>
     153                        <th>
     154                            <label>Change the default cookie expire time for WordPress Protected Posts:</label>
     155                            <br />
     156                            <span class="description">In seconds, leave blank for default</span>
     157                        </th>
     158                        <td>
     159                            <input type="number" name="pplb_pass_expires" value="<?php echo $expire; ?>"> seconds = <span id="expire-human"></span>
     160                            <script type="text/javascript">
     161                                jQuery( document ).ready(function($){
     162                                    $( 'input[name="pplb_pass_expires"]' ).change( function(){
     163                                        if( $(this).val().length == 0 ){
     164                                            $('span#expire-human').text( '10 days (default value)' )
     165                                        }
     166                                        else{
     167                                            var word = 'minutes';
     168                                            var v = $( this ).val();
     169                                            if( v > ( 24 * 60 * 60 ) ){
     170                                                word = 'days';
     171                                            }
     172                                            else if( v > ( 60 * 60 ) ){
     173                                                word = 'hours';
     174                                            }
     175                                           
     176                                            switch( word ){
     177                                                case 'minutes':
     178                                                    conversion = v / 60;
     179                                                    break;
     180                                                case 'hours':
     181                                                    conversion = v / 60 / 60;
     182                                                    break;
     183                                                case 'days':
     184                                                    conversion = v / 60 / 60 / 24;
     185                                                    break;
     186                                                default:
     187                                                    conversion = v;
     188                                                    break;
     189                                            }
     190                                           
     191                                            var humanReadable = conversion + ' ' + word;
     192                                       
     193                                            $('span#expire-human').text( humanReadable );
     194                                        }
     195                                    } );
     196                                    $( 'input[name="pplb_pass_expires"]' ).trigger( 'change' );
     197                                });
     198                            </script>
    124199                        </td>
    125200                    </tr>
     
    174249*/
    175250function add_pplb_filter(){
    176     if(!get_option('pplb_button_filter')){
     251    if ( !get_option( 'pplb_button_filter' ) ) {
    177252        // if the option isn't set, assume we want it there.
    178253        update_option('pplb_button_filter', 'yes');
    179254    }
    180255    $add_filter = get_option('pplb_button_filter');
    181     if($add_filter == 'yes'){
     256    if ( $add_filter == 'yes' ) {
    182257        add_filter('the_content', 'pplb_logout_filter', 9999, 1);   // adds the button.
    183258    }
  • protected-posts-logout-button/trunk/readme.txt

    r666044 r951684  
    44Tags: logout, password protected posts logout button, wordpress security
    55Requires at least: 2.8
    6 Tested up to: 3.5.1
    7 Stable tag: 1.3
     6Tested up to: 3.9.1
     7Stable tag: 1.3.1
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    1919* Has a simple settings page to make everything easier.
    2020* Allows you to alert user they have logged out.
    21 
    22 
    2321
    2422== Installation ==
     
    5452== Changelog ==
    5553
     54= 1.3.1 =
     55* Added the ability to change the default WordPress postpass cookie in the admin area.
     56* Cleaned up some logic and php code.
    5657= 1.3 =
    5758* Added conditional logic to the allow admin to disable the automatic filter.
Note: See TracChangeset for help on using the changeset viewer.