I may have almost figured out #2 after finding the right functions in wp-includes/pluggable.php
I just wish these functions were documented somewhere.
I ended up changing a few lines and adding a new variable, $gravatar_show. Here are the relevant lines of code:
// Gravatar settings
$gravatar_size = 64;
$gravatar_show = get_option('show_avatars'); // showing or hiding avatars can be set in the admin panel under Settings - Discussion
$gravatar_default = get_option('avatar_default'); // The default avatar style can be chosen under Settings - Discussion
// $gravatar_default = 'https://www.gravatar.com/avatar/ad516503a11cd5ca435acc9bb6523536'; // or put a URI to your custom default image here
$gravatar_rating = get_option('avatar_rating');
// Customize this string if you want to modify the preview output
// %1 - author's name (as hyperlink if available)
// %2 - comment text
// %3 - gravatar image url
$previewFormat = '
<ol class="commentlist" style="clear: both; margin-top: 3em;">
<li id="comment-preview" class="alt" style="overflow: hidden;">
<div class="comment-author vcard">';
if ($gravatar_show) {
$previewFormat .= '
<img src="%3" alt="" class="avatar avatar-' . $gravatar_size . '" width="' . $gravatar_size . '" height="' . $gravatar_size . '"/>';
}
$previewFormat .= '
<span class="fn n">%1</span>
</div>
<div class="comment-meta">Posted (date) at (time) <span class="meta-sep">| Permalink</div>
%2
';
The preview format is sort-of customized to my Sandbox theme.
// You shouldn't need to edit anything else.
ob_start ("ob_gzhandler"); //compress with gzip if possible
header('Content-type: text/javascript');
<?php
if ($gravatar_show) :
?>
var user_gravatar = '<?php echo addslashes($user_gravatar); ?>';
var gravatar = '<?php echo addslashes($gravatar_default); ?>?';
if (eml != '') {
gravatar = 'https://www.gravatar.com/avatar/' + hex_md5(eml) + '?d=<?php echo urlencode($gravatar_default); ?>&';
}
else if (user_gravatar != '') {
gravatar = user_gravatar + '?d=<?php echo urlencode($gravatar_default); ?>&';
}
gravatar += 's=<?php echo $gravatar_size; ?>';
<?php
if (!empty($gravatar_rating)) {
?>
gravatar += '&r=<?php echo urlencode($gravatar_rating) ?>';
<?php
}
endif;
$previewFormat = str_replace("\r", "", $previewFormat);
$previewFormat = str_replace("\n", "", $previewFormat);
$previewFormat = str_replace("'", "\'", $previewFormat);
$previewFormat = str_replace("%1", "' + name + '", $previewFormat);
$previewFormat = str_replace("%2", "' + cmnt + '", $previewFormat);
if ($gravatar_show) {
$previewFormat = str_replace("%3", "' + gravatar + '", $previewFormat);
}
$previewFormat = "'" . $previewFormat . "';\n";
?>
Sorry for the mess… I’ll post a link as soon as I upload it to my server.
https://noisychaos.com/external/wp-work/live-comment-preview.zip