Skip to content

Instantly share code, notes, and snippets.

@katmoody
Forked from icryptic/gist:5defdf335d84bed11fa3
Last active August 29, 2015 14:14
Show Gist options
  • Save katmoody/fae020f8ba2007084db1 to your computer and use it in GitHub Desktop.
Save katmoody/fae020f8ba2007084db1 to your computer and use it in GitHub Desktop.
/* Creates random keys for confirm checkbox */
function generate_confirm_key($length = 50) {
$characters = '-0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_';
$randomString = '';
for ($i = 0; $i < $length; $i++) {
$randomString .= $characters[rand(0, strlen($characters) - 1)];
}
return $randomString;
}
/* Add comment confirm checkbox */
function insert_comment_checkbox() {
echo '<div style="width:100%;height:1px;margin-bottom:20px"></div>';
echo '<input type="checkbox" name="confirm-' . generate_confirm_key() . '" id="confirm-' . generate_confirm_key() . '" value="true" required><label for="confirm-' . generate_confirm_key() . '"><div style="margin-top:-4px;margin-left:4px;color:#CC0000">Confirm</div></label></form>';
}
/* Add comment confirm action */
add_action( 'comment_form', 'insert_comment_checkbox' );
/* Add login confirm checkbox */
function insert_login_checkbox() {
echo '<p class="forgetmenot"><label for="confirm-' . generate_confirm_key() . '"><input type="checkbox" name="confirm-' . generate_confirm_key() . '" id="confirm-' . generate_confirm_key() . '" value="true" required><label for="confirm-' . generate_confirm_key() . '"> <span style="color:#CC0000">Confirm</span></label></p><br /><br />';
}
/* Add login confirm action */
add_action( 'login_form', 'insert_login_checkbox' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment