Changeset 951684
- Timestamp:
- 07/19/2014 09:14:33 PM (12 years ago)
- Location:
- protected-posts-logout-button
- Files:
-
- 6 edited
- 1 copied
-
tags/1.3.1 (copied) (copied from protected-posts-logout-button/trunk)
-
tags/1.3.1/logout.js (modified) (1 diff)
-
tags/1.3.1/pplb_logout_button.php (modified) (7 diffs)
-
tags/1.3.1/readme.txt (modified) (3 diffs)
-
trunk/logout.js (modified) (1 diff)
-
trunk/pplb_logout_button.php (modified) (7 diffs)
-
trunk/readme.txt (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
protected-posts-logout-button/tags/1.3.1/logout.js
r545060 r951684 1 1 jQuery(document).ready(function($){ 2 2 $('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 4 4 Plugin URI: http://omfgitsnater.com/protected-posts-logout-button/ 5 5 Description: A plugin built to add a logout button automatically to protected posts. 6 Version: 1.3 6 Version: 1.3.1 7 7 Author: Nate Reist 8 8 Author URI: http://omfgitsnater.com … … 18 18 19 19 //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() ){ 21 21 //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() ) ) { 23 23 //add the logout button to the output. 24 24 $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'] : ''; 26 26 $html .= ' <input type="button" class="button logout '.esc_attr($class).'" value="logout">'; 27 27 } … … 40 40 $html = ''; 41 41 // Check if the post has a password 42 if (!empty($qpost->post_password)){42 if ( !empty( $qpost->post_password ) ) { 43 43 // Check to see if the password has been provided. 44 44 if(!post_password_required($qid)){ … … 58 58 function pplb_protected_logout(){ 59 59 // 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 ); 61 61 $options = get_option('pplb_options'); 62 62 $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 */ 83 function 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 */ 92 function pplb_change_postpass_expires( $expire ){ 93 $new_expire = get_option( 'pplb_pass_expires', false ); 94 if( $new_expire !== false ){ 95 return time() + $new_expire; 65 96 } 66 97 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 } 101 add_filter( 'post_password_expires','pplb_change_postpass_expires', 10, 1 ); 80 102 81 103 /* … … 83 105 */ 84 106 function pplb_settings_page(){ 85 if (isset($_POST['pplb_action'])){107 if ( isset( $_POST['pplb_action'] ) ) { 86 108 //update the option. 87 109 $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'] ); 90 112 $options['pplb_button_class'] = esc_attr($_POST['pplb_button_class']); 91 113 update_option('pplb_options', $options); 92 114 115 $expire = ( isset( $_POST['pplb_pass_expires'] ) && $_POST['pplb_pass_expires'] != '' ) ? $_POST['pplb_pass_expires']: false; 116 update_option('pplb_pass_expires', $expire ); 117 93 118 $filter = isset($_POST['pplb_button_filter']) ? $_POST['pplb_button_filter']: 'yes'; 94 119 update_option('pplb_button_filter', $filter); 95 120 } 96 121 $new_options = get_option('pplb_options'); 97 if (is_array($new_options)){122 if ( is_array($new_options ) ) { 98 123 extract($new_options); 99 124 } … … 119 144 <th><label>Automatically add button to protected pages:</label></th><td> 120 145 <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> 123 148 </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> 124 199 </td> 125 200 </tr> … … 174 249 */ 175 250 function add_pplb_filter(){ 176 if (!get_option('pplb_button_filter')){251 if ( !get_option( 'pplb_button_filter' ) ) { 177 252 // if the option isn't set, assume we want it there. 178 253 update_option('pplb_button_filter', 'yes'); 179 254 } 180 255 $add_filter = get_option('pplb_button_filter'); 181 if ($add_filter == 'yes'){256 if ( $add_filter == 'yes' ) { 182 257 add_filter('the_content', 'pplb_logout_filter', 9999, 1); // adds the button. 183 258 } -
protected-posts-logout-button/tags/1.3.1/readme.txt
r666044 r951684 4 4 Tags: logout, password protected posts logout button, wordpress security 5 5 Requires at least: 2.8 6 Tested up to: 3. 5.17 Stable tag: 1.3 6 Tested up to: 3.9.1 7 Stable tag: 1.3.1 8 8 License: GPLv2 or later 9 9 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 19 19 * Has a simple settings page to make everything easier. 20 20 * Allows you to alert user they have logged out. 21 22 23 21 24 22 == Installation == … … 54 52 == Changelog == 55 53 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. 56 57 = 1.3 = 57 58 * Added conditional logic to the allow admin to disable the automatic filter. -
protected-posts-logout-button/trunk/logout.js
r545060 r951684 1 1 jQuery(document).ready(function($){ 2 2 $('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 4 4 Plugin URI: http://omfgitsnater.com/protected-posts-logout-button/ 5 5 Description: A plugin built to add a logout button automatically to protected posts. 6 Version: 1.3 6 Version: 1.3.1 7 7 Author: Nate Reist 8 8 Author URI: http://omfgitsnater.com … … 18 18 19 19 //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() ){ 21 21 //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() ) ) { 23 23 //add the logout button to the output. 24 24 $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'] : ''; 26 26 $html .= ' <input type="button" class="button logout '.esc_attr($class).'" value="logout">'; 27 27 } … … 40 40 $html = ''; 41 41 // Check if the post has a password 42 if (!empty($qpost->post_password)){42 if ( !empty( $qpost->post_password ) ) { 43 43 // Check to see if the password has been provided. 44 44 if(!post_password_required($qid)){ … … 58 58 function pplb_protected_logout(){ 59 59 // 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 ); 61 61 $options = get_option('pplb_options'); 62 62 $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 */ 83 function 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 */ 92 function pplb_change_postpass_expires( $expire ){ 93 $new_expire = get_option( 'pplb_pass_expires', false ); 94 if( $new_expire !== false ){ 95 return time() + $new_expire; 65 96 } 66 97 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 } 101 add_filter( 'post_password_expires','pplb_change_postpass_expires', 10, 1 ); 80 102 81 103 /* … … 83 105 */ 84 106 function pplb_settings_page(){ 85 if (isset($_POST['pplb_action'])){107 if ( isset( $_POST['pplb_action'] ) ) { 86 108 //update the option. 87 109 $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'] ); 90 112 $options['pplb_button_class'] = esc_attr($_POST['pplb_button_class']); 91 113 update_option('pplb_options', $options); 92 114 115 $expire = ( isset( $_POST['pplb_pass_expires'] ) && $_POST['pplb_pass_expires'] != '' ) ? $_POST['pplb_pass_expires']: false; 116 update_option('pplb_pass_expires', $expire ); 117 93 118 $filter = isset($_POST['pplb_button_filter']) ? $_POST['pplb_button_filter']: 'yes'; 94 119 update_option('pplb_button_filter', $filter); 95 120 } 96 121 $new_options = get_option('pplb_options'); 97 if (is_array($new_options)){122 if ( is_array($new_options ) ) { 98 123 extract($new_options); 99 124 } … … 119 144 <th><label>Automatically add button to protected pages:</label></th><td> 120 145 <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> 123 148 </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> 124 199 </td> 125 200 </tr> … … 174 249 */ 175 250 function add_pplb_filter(){ 176 if (!get_option('pplb_button_filter')){251 if ( !get_option( 'pplb_button_filter' ) ) { 177 252 // if the option isn't set, assume we want it there. 178 253 update_option('pplb_button_filter', 'yes'); 179 254 } 180 255 $add_filter = get_option('pplb_button_filter'); 181 if ($add_filter == 'yes'){256 if ( $add_filter == 'yes' ) { 182 257 add_filter('the_content', 'pplb_logout_filter', 9999, 1); // adds the button. 183 258 } -
protected-posts-logout-button/trunk/readme.txt
r666044 r951684 4 4 Tags: logout, password protected posts logout button, wordpress security 5 5 Requires at least: 2.8 6 Tested up to: 3. 5.17 Stable tag: 1.3 6 Tested up to: 3.9.1 7 Stable tag: 1.3.1 8 8 License: GPLv2 or later 9 9 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 19 19 * Has a simple settings page to make everything easier. 20 20 * Allows you to alert user they have logged out. 21 22 23 21 24 22 == Installation == … … 54 52 == Changelog == 55 53 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. 56 57 = 1.3 = 57 58 * Added conditional logic to the allow admin to disable the automatic filter.
Note: See TracChangeset
for help on using the changeset viewer.