Changeset 2930258
- Timestamp:
- 06/24/2023 12:52:14 AM (3 years ago)
- Location:
- comment-saver
- Files:
-
- 6 added
- 4 deleted
- 2 edited
- 1 copied
-
tags/1.5 (copied) (copied from comment-saver/trunk)
-
tags/1.5/comment-saver.js (added)
-
tags/1.5/comment-saver.php (modified) (1 diff)
-
tags/1.5/composer.json (added)
-
tags/1.5/jquery.cookie.js (deleted)
-
tags/1.5/jquery.cookie.min.js (deleted)
-
tags/1.5/phpcs.xml (added)
-
trunk/comment-saver.js (added)
-
trunk/comment-saver.php (modified) (1 diff)
-
trunk/composer.json (added)
-
trunk/jquery.cookie.js (deleted)
-
trunk/jquery.cookie.min.js (deleted)
-
trunk/phpcs.xml (added)
Legend:
- Unmodified
- Added
- Removed
-
comment-saver/tags/1.5/comment-saver.php
r156845 r2930258 1 1 <?php 2 /* 3 Plugin Name: Comment Saver 4 Description: Saves comment text in a temporary cookie before it is submitted. 5 Author: Will Norris 6 Plugin URI: http://wordpress.org/extend/plugins/comment-saver/ 7 Author URI: http://willnorris.com/ 8 Version: 1.4 9 License: Dual GPL (http://www.fsf.org/licensing/licenses/info/GPLv2.html) and Modified BSD (http://www.fsf.org/licensing/licenses/index_html#ModifiedBSD) 10 */ 2 /** 3 * Plugin Name: Comment Saver 4 * Description: Saves comment text in a temporary cookie before it is submitted. 5 * Author: Will Norris 6 * Plugin URI: http://wordpress.org/extend/plugins/comment-saver/ 7 * Author URI: http://willnorris.com/ 8 * Version: 1.4 9 * License: Dual GPL (http://www.fsf.org/licensing/licenses/info/GPLv2.html) and Modified BSD (http://www.fsf.org/licensing/licenses/index_html#ModifiedBSD) 10 * 11 * @package comment-saver 12 */ 11 13 14 add_filter( 'comment_post_redirect', 'comment_saver_cleanup', 10, 2 ); 15 add_action( 'wp_enqueue_scripts', 'comment_saver_js' ); 12 16 13 add_action('comment_form', 'comment_saver_form'); 14 add_filter('comment_post_redirect', 'comment_saver_cleanup', 10, 2); 15 add_action('wp', 'comment_saver_js'); 16 17 18 /** 19 * Get path for comment saver cookie. 17 /** 18 * Get path for comment saver cookie. 20 19 */ 21 20 function comment_saver_cookie_path() { 22 $parts = parse_url(get_option('home'));23 $path = array_key_exists('path', $parts) ? $parts['path'] : '/';21 $parts = wp_parse_url( get_option( 'home' ) ); 22 $path = array_key_exists( 'path', $parts ) ? $parts['path'] : '/'; 24 23 return $path; 25 24 } 26 25 27 28 /** 29 * Setup require javascript. 26 /** 27 * Setup require javascript. 30 28 */ 31 29 function comment_saver_js() { 32 if ( is_single() || is_comments_popup()) {33 wp_enqueue_script('jquery.cookie', plugins_url('comment-saver/jquery.cookie.min.js'), array('jquery'), false, true);30 if ( ! is_singular() ) { 31 return; 34 32 } 33 34 wp_enqueue_script( 'comment-saver', plugin_dir_url( __FILE__ ) . 'comment-saver.js', array(), '1.4', true ); 35 wp_localize_script( 36 'comment-saver', 37 'comment_saver_cookie', 38 array( 39 'name' => 'comment_saver_post' . get_the_ID(), 40 'path' => comment_saver_cookie_path(), 41 ) 42 ); 35 43 } 36 37 38 /**39 * Add jQuery actions to save and restore comment.40 */41 function comment_saver_form($id) {42 $cookieName = 'comment_saver_post' . $id;43 $path = comment_saver_cookie_path();44 45 echo '46 <script type="text/javascript">47 jQuery(function() {48 jQuery("#commentform").submit(function() {49 jQuery.cookie("' . $cookieName . '", jQuery("#comment").val(), {expires: (1/24), path: "' . $path . '"});50 });51 if (jQuery("#comment").val() == "") {52 var cookieValue = jQuery.cookie("' . $cookieName . '");53 if (cookieValue != null) {54 jQuery("#comment").val(cookieValue));55 }56 }57 });58 </script>';59 }60 61 44 62 45 /** 63 46 * Cleanup comment saver cookie. 47 * 48 * @param string $location The 'redirect_to' URI sent via $_POST. 49 * @param WP_Comment $comment Comment object. 50 * 51 * @return string 64 52 */ 65 function comment_saver_cleanup( $location, $comment) {53 function comment_saver_cleanup( $location, $comment ) { 66 54 $path = comment_saver_cookie_path(); 67 setcookie( 'comment_saver_post' . $comment->comment_post_ID, null, -1, $path);55 setcookie( 'comment_saver_post' . $comment->comment_post_ID, '', -1, $path ); 68 56 return $location; 69 57 } 70 71 ?> -
comment-saver/trunk/comment-saver.php
r156845 r2930258 1 1 <?php 2 /* 3 Plugin Name: Comment Saver 4 Description: Saves comment text in a temporary cookie before it is submitted. 5 Author: Will Norris 6 Plugin URI: http://wordpress.org/extend/plugins/comment-saver/ 7 Author URI: http://willnorris.com/ 8 Version: 1.4 9 License: Dual GPL (http://www.fsf.org/licensing/licenses/info/GPLv2.html) and Modified BSD (http://www.fsf.org/licensing/licenses/index_html#ModifiedBSD) 10 */ 2 /** 3 * Plugin Name: Comment Saver 4 * Description: Saves comment text in a temporary cookie before it is submitted. 5 * Author: Will Norris 6 * Plugin URI: http://wordpress.org/extend/plugins/comment-saver/ 7 * Author URI: http://willnorris.com/ 8 * Version: 1.4 9 * License: Dual GPL (http://www.fsf.org/licensing/licenses/info/GPLv2.html) and Modified BSD (http://www.fsf.org/licensing/licenses/index_html#ModifiedBSD) 10 * 11 * @package comment-saver 12 */ 11 13 14 add_filter( 'comment_post_redirect', 'comment_saver_cleanup', 10, 2 ); 15 add_action( 'wp_enqueue_scripts', 'comment_saver_js' ); 12 16 13 add_action('comment_form', 'comment_saver_form'); 14 add_filter('comment_post_redirect', 'comment_saver_cleanup', 10, 2); 15 add_action('wp', 'comment_saver_js'); 16 17 18 /** 19 * Get path for comment saver cookie. 17 /** 18 * Get path for comment saver cookie. 20 19 */ 21 20 function comment_saver_cookie_path() { 22 $parts = parse_url(get_option('home'));23 $path = array_key_exists('path', $parts) ? $parts['path'] : '/';21 $parts = wp_parse_url( get_option( 'home' ) ); 22 $path = array_key_exists( 'path', $parts ) ? $parts['path'] : '/'; 24 23 return $path; 25 24 } 26 25 27 28 /** 29 * Setup require javascript. 26 /** 27 * Setup require javascript. 30 28 */ 31 29 function comment_saver_js() { 32 if ( is_single() || is_comments_popup()) {33 wp_enqueue_script('jquery.cookie', plugins_url('comment-saver/jquery.cookie.min.js'), array('jquery'), false, true);30 if ( ! is_singular() ) { 31 return; 34 32 } 33 34 wp_enqueue_script( 'comment-saver', plugin_dir_url( __FILE__ ) . 'comment-saver.js', array(), '1.4', true ); 35 wp_localize_script( 36 'comment-saver', 37 'comment_saver_cookie', 38 array( 39 'name' => 'comment_saver_post' . get_the_ID(), 40 'path' => comment_saver_cookie_path(), 41 ) 42 ); 35 43 } 36 37 38 /**39 * Add jQuery actions to save and restore comment.40 */41 function comment_saver_form($id) {42 $cookieName = 'comment_saver_post' . $id;43 $path = comment_saver_cookie_path();44 45 echo '46 <script type="text/javascript">47 jQuery(function() {48 jQuery("#commentform").submit(function() {49 jQuery.cookie("' . $cookieName . '", jQuery("#comment").val(), {expires: (1/24), path: "' . $path . '"});50 });51 if (jQuery("#comment").val() == "") {52 var cookieValue = jQuery.cookie("' . $cookieName . '");53 if (cookieValue != null) {54 jQuery("#comment").val(cookieValue));55 }56 }57 });58 </script>';59 }60 61 44 62 45 /** 63 46 * Cleanup comment saver cookie. 47 * 48 * @param string $location The 'redirect_to' URI sent via $_POST. 49 * @param WP_Comment $comment Comment object. 50 * 51 * @return string 64 52 */ 65 function comment_saver_cleanup( $location, $comment) {53 function comment_saver_cleanup( $location, $comment ) { 66 54 $path = comment_saver_cookie_path(); 67 setcookie( 'comment_saver_post' . $comment->comment_post_ID, null, -1, $path);55 setcookie( 'comment_saver_post' . $comment->comment_post_ID, '', -1, $path ); 68 56 return $location; 69 57 } 70 71 ?>
Note: See TracChangeset
for help on using the changeset viewer.