Created
February 4, 2011 16:27
-
-
Save skeltoac/811310 to your computer and use it in GitHub Desktop.
A WordPress plug-in to fill comment form from cookies client-side, eliminating a whole class of uncacheable variants
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: Client-Side Comment Fill | |
Author: Andy Skelton | |
Description: Fills comment form from cookies client-side, eliminating a whole class of uncacheable variants | |
*/ | |
function cscf_get_current_commenter( $commenter ) { | |
foreach ( $commenter as &$string ) | |
$string = ''; | |
return $commenter; | |
} | |
add_filter( 'wp_get_current_commenter', 'cscf_get_current_commenter', 10, 1 ); | |
function cscf_comment_form_after() { | |
if ( is_user_logged_in() ) | |
return; | |
$format = 'document.cookie.match(/comment_author%s_'.COOKIEHASH.'=([^;]+)/)'; | |
?> | |
<script> | |
var v; | |
if ( v = <?php printf($format, '') ?> ) document.getElementById('author').value=unescape(v[1]); | |
if ( v = <?php printf($format, '_email') ?> ) document.getElementById('email').value=unescape(v[1]); | |
if ( v = <?php printf($format, '_url') ?> ) document.getElementById('url').value=unescape(v[1]); | |
</script> | |
<?php | |
} | |
add_action( 'comment_form_after', 'cscf_comment_form_after', 10 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment