functions修改记录

functions修改记录,以备主题升级或者主题更换

2014-08-08,使用ajax评论

functions.php增加一下代码

1
2
3
4
5
6
7
8
9
10
11
12
//comments-ajax by liang at 20140808
//使用ajax评论
if (!is_admin()) {
function proliang_load_comment_ajax_scripts() {
#wp_enqueue_script('jquery');
if (is_singular()) {
wp_enqueue_script('comments_ajax_js', (get_template_directory_uri()."/comments-ajax.js"), false, '1.3', true);
}
}
add_action('wp_enqueue_scripts', 'proliang_load_comment_ajax_scripts');
}
//comments-ajax end

其他修改参照增加ajax评论小记

2014-10-27,修改Google founts加载

Google被墙,导致字体不能加载,增加以下代码把字体源换成360

1
2
3
4
5
6
7
8
9
//google font by liang at 20141027
//修改google字体到 useso.com,360的CDN
function wpdx_replace_open_sans() {
wp_deregister_style('open-sans');
wp_register_style( 'open-sans', '//fonts.useso.com/css?family=Open+Sans:300italic,400italic,600italic,300,400,600' );
if(is_admin()) wp_enqueue_style( 'open-sans');
}
add_action( 'init', 'wpdx_replace_open_sans' );
//google font end

2014-11-20,修复Gravatar头像不能显示问题

gravatar部分域名被墙,导致自己头像和评论头像不能显示,增加以下代码可把头像源改为https

1
2
3
4
5
6
7
8
//gravatar by liang at 20141120
//gravatar被墙,头像不显示问题解决
function get_ssl_avatar($avatar) {
$avatar = preg_replace('/.*\/avatar\/(.*)\?s=([\d]+)&.*/','<img src="https://secure.gravatar.com/avatar/$1?s=$2" class="avatar avatar-$2" height="$2" width="$2">',$avatar);
return $avatar;
}
add_filter('get_avatar', 'get_ssl_avatar');
//gravatar end

2015-01-21

增加功能,评论回复邮件通知,包括两种情况
1.未被批准的评论回复,会在被批准时发送邮件
2.已被批准的人在回复别人评论时,会立即发送邮件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
//评论回复被审核之后发送邮件通知
function commit_reply_approved($comment) {
$parent_id = $comment->comment_parent ? $comment->comment_parent : '';
$spam_confirmed = $comment->comment_approved;
if (($parent_id != '') && ($spam_confirmed == '1')) {
$post_link = get_permalink($comment->comment_post_ID);
$wp_email = 'admin@proliang.com';
$to = trim(get_comment($parent_id)->comment_author_email);
$author_email=$comment->comment_author_email;//评论人邮箱
$admin_email = get_bloginfo ('admin_email');//管理员邮箱
if($to == $admin_email || $to == $author_email) {
return;
}
$subject = '您在 [' . get_option("blogname") . '] 发表的评论收到了回复';
$message = '
<div style="background-color:#eef2fa; border:1px solid #d8e3e8; color:#111; padding:0 15px; -moz-border-radius:5px; -webkit-border-radius:5px; -khtml-border-radius:5px;">
<p>' . trim(get_comment($parent_id)->comment_author) . ', 您好!</p>
<p>您在《<a href="'.$post_link.'">'. get_the_title($comment->comment_post_ID) . '</a>》发表的评论:<br />'
. trim(get_comment($parent_id)->comment_content) . '</p>
<p>' . trim($comment->comment_author) . ' 给您的回复:<br />'
. trim($comment->comment_content) . '<br /></p>
<p>您可以点击 <a href="' . htmlspecialchars(get_comment_link($parent_id,array("type" => "all"))) . '">查看回复的完整內容</a></p>
<p>欢迎再度光临 <a href="' . get_option('home') . '">' . get_option('blogname') . '</a></p>
<p>(此邮件由系统自动发送,请勿回复.)</p>
</div>';
$from = "From: \"" . get_option('blogname') . "\" <$wp_email>";
$headers = "$from\nContent-Type: text/html; charset=" . get_option('blog_charset') . "\n";
wp_mail( $to, $subject, $message, $headers );
}
}
add_action('comment_unapproved_to_approved', 'commit_reply_approved');
//评论被已批准过的人回复时,发送邮件通知
function commit_reply_notify($comment_id) {
$comment = get_comment($comment_id);
$parent_id = $comment->comment_parent ? $comment->comment_parent : '';
$spam_confirmed = $comment->comment_approved;
if (($parent_id != '') && ($spam_confirmed == '1')) {
$post_link = get_permalink($comment->comment_post_ID);
$wp_email = 'admin@proliang.com';
$to = trim(get_comment($parent_id)->comment_author_email);
$author_email=$comment->comment_author_email;//评论人邮箱
$admin_email = get_bloginfo ('admin_email');//管理员邮箱
if($to == $admin_email || $to == $author_email) {
return;
}
$subject = '您在 [' . get_option("blogname") . '] 发表的评论收到了回复';
$message = '
<div style="background-color:#eef2fa; border:1px solid #d8e3e8; color:#111; padding:0 15px; -moz-border-radius:5px; -webkit-border-radius:5px; -khtml-border-radius:5px;">
<p>' . trim(get_comment($parent_id)->comment_author) . ', 您好!</p>
<p>您在《<a href="'.$post_link.'">'. get_the_title($comment->comment_post_ID) . '</a>》发表的评论:<br />'
. trim(get_comment($parent_id)->comment_content) . '</p>
<p>' . trim($comment->comment_author) . ' 给您的回复:<br />'
. trim($comment->comment_content) . '<br /></p>
<p>您可以点击 <a href="' . htmlspecialchars(get_comment_link($parent_id,array("type" => "all"))) . '">查看回复的完整內容</a></p>
<p>欢迎再度光临 <a href="' . get_option('home') . '">' . get_option('blogname') . '</a></p>
<p>(此邮件由系统自动发送,请勿回复.)</p>
</div>';
$from = "From: \"" . get_option('blogname') . "\" <$wp_email>";
$headers = "$from\nContent-Type: text/html; charset=" . get_option('blog_charset') . "\n";
wp_mail( $to, $subject, $message, $headers );
}
}
add_action('comment_post', 'commit_reply_notify');

后记

GFW真是疯了~