Skip to content

Instantly share code, notes, and snippets.

@skeltoac
Created February 4, 2011 16:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save skeltoac/811310 to your computer and use it in GitHub Desktop.
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
<?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