Plugin Directory

Changeset 2930258


Ignore:
Timestamp:
06/24/2023 12:52:14 AM (3 years ago)
Author:
willnorris
Message:

Update to version 1.5 from GitHub

Location:
comment-saver
Files:
6 added
4 deleted
2 edited
1 copied

Legend:

Unmodified
Added
Removed
  • comment-saver/tags/1.5/comment-saver.php

    r156845 r2930258  
    11<?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 */
    1113
     14add_filter( 'comment_post_redirect', 'comment_saver_cleanup', 10, 2 );
     15add_action( 'wp_enqueue_scripts', 'comment_saver_js' );
    1216
    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.
    2019 */
    2120function 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'] : '/';
    2423    return $path;
    2524}
    2625
    27 
    28 /**
    29  * Setup require javascript.
     26/**
     27 * Setup require javascript.
    3028 */
    3129function 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;
    3432    }
     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    );
    3543}
    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 
    6144
    6245/**
    6346 * 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
    6452 */
    65 function comment_saver_cleanup($location, $comment) {
     53function comment_saver_cleanup( $location, $comment ) {
    6654    $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 );
    6856    return $location;
    6957}
    70 
    71 ?>
  • comment-saver/trunk/comment-saver.php

    r156845 r2930258  
    11<?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 */
    1113
     14add_filter( 'comment_post_redirect', 'comment_saver_cleanup', 10, 2 );
     15add_action( 'wp_enqueue_scripts', 'comment_saver_js' );
    1216
    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.
    2019 */
    2120function 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'] : '/';
    2423    return $path;
    2524}
    2625
    27 
    28 /**
    29  * Setup require javascript.
     26/**
     27 * Setup require javascript.
    3028 */
    3129function 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;
    3432    }
     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    );
    3543}
    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 
    6144
    6245/**
    6346 * 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
    6452 */
    65 function comment_saver_cleanup($location, $comment) {
     53function comment_saver_cleanup( $location, $comment ) {
    6654    $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 );
    6856    return $location;
    6957}
    70 
    71 ?>
Note: See TracChangeset for help on using the changeset viewer.