如何实现wordpress评论回复邮件通知功能
展开全部 有以下3种方法来实现“免插件仅代码实现WordPress评论回复邮件提醒”,都是把代码加到主题里的functions.php中的最后一个 ?> 即可。
第一种:所有回复都发邮件通知使用前,请确定你的主机是否支持 mail() 函数。
/* comment_mail_notify v1.0 by willin kan. (所有回复都发邮件) */function comment_mail_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 != 'spam')) { $wp_email = 'no-reply@' . preg_replace('#^www.#', '', strtolower($_SERVER['SERVER_NAME'])); //e-mail 发出点, no-reply 可改为可用的 e-mail. $to = trim(get_comment($parent_id)->comment_author_email); $subject = '您在 [' . get_option("blogname") . '] 的留言有了回复'; $message = ' ' . trim(get_comment($parent_id)->comment_author) . ', 您好! 您曾在《' . get_the_title($comment->comment_post_ID) . '》的留言:' . trim(get_comment($parent_id)->comment_content) . ' ' . trim($comment->comment_author) . ' 给您的回复:' . trim($comment->comment_content) . ' 您可以点击 查看回复完整内容 欢迎再度光临 ' . get_option('blogname') . ' (此邮件由系统自动发送,请勿回复.) '; $from = "From: "" . get_option('blogname') . "" "; $headers = "$fromnContent-Type: text/html; charset=" . get_option('blog_charset') . "n"; wp_mail( $to, $subject, $message, $headers ); //echo 'mail to ', $to, ' ' , $subject, $message; // for testing }}add_action('comment_post', 'comment_mail_notify');// -- END - 第二种:让访客自己选择是否邮件通知在评论框下方显示一个勾选框,让评论人自己决定是否接收邮件通知。
不过要注意的是,具体的#comment_mail_notify 需要你自己定义css以符合你的主题样式。
function comment_mail_notify($comment_id) { $admin_notify = '1'; // admin 要不要收回复通知 ( '1'=要 ; '0'=不要 ) $admin_email = get_bloginfo ('admin_email'); // $admin_email 可改为你指定的 e-mail. $comment = get_comment($comment_id); $comment_author_email = trim($comment->comment_author_email); $parent_id = $comment->comment_parent ? $comment->comment_parent : ''; global $wpdb; if ($wpdb->query("Describe {$wpdb->comments} comment_mail_notify") == '') $wpdb->query("ALTER TABLE {$wpdb->comments} ADD COLUMN comment_mail_notify TINYINT NOT NULL DEFAULT 0;"); if (($comment_author_email != $admin_email && isset($_POST['comment_mail_notify'])) || ($comment_author_email == $admin_email && $admin_notify == '1')) $wpdb->query("UPDATE {$wpdb->comments} SET comment_mail_notify='1' WHERE comment_ID='$comment_id'"); $notify = $parent_id ? get_comment($parent_id)->comment_mail_notify : '0'; $spam_confirmed = $comment->comment_approved; if ($parent_id != '' && $spam_confirmed != 'spam' && $notify == '1') { $wp_email = 'no-reply@' . preg_replace('#^www.#', '', strtolower($_SERVER['SERVER_NAME'])); // e-mail 发出点, no-reply 可改为可用的 e-mail. $to = trim(get_comment($parent_id)->comment_author_email); $subject = '您在 [' . get_option("blogname") . '] 的留言有了回复'; $message = ' ' . trim(get_comment($parent_id)->comment_author) . ', 您好! 您曾在《' . get_the_title($comment->comment_post_ID) . '》的留言:' . trim(get_comment($parent_id)->comment_content) . ' ' . trim($comment->comment_author) . ' 给您的回复:' . trim($comment->comment_content) . ' 您可以点击查看回复的完整内容 还要再度光临 ' . get_option('blogname') . ' (此邮件由系统自动发送,请勿回复.) '; $from = "From: "" . get_option('blogname') . "" "; $headers = "$fromnContent-Type: text/html; charset=" . get_option('blog_charset') . "n"; wp_mail( $to, $subject, $message, $headers ); //echo 'mail to ', $to, ' ' , $subject, $message; // for testing }}add_action('comment_post', 'comment_mail_...
wordpress 中comments
在 wp-includes/comment-template.php2055 行function comment_form里面。
/*** Filter the default comment form fields.** @since 3.0.0** @param array $fields The default comment fields.*/$fields = apply_filters( 'comment_form_default_fields', $fields );$defaults = array('fields' => $fields,'comment_field' => '' . _x( 'Comment', 'noun' ) . ' ',/** This filter is documented in wp-includes/link-template.php */'must_log_in' => '' . sprintf( __( 'You must be logged in to post a comment.' ), wp_login_url( apply_filters( 'the_permalink', get_permalink( $post_id ) ) ) ) . '',/** This filter is documented in wp-includes/link-template.php */'logged_in_as' => '' . sprintf( __( 'Logged in as %2$s. Log out?' ), get_edit_user_link(), $user_identity, wp_logout_url( apply_filters( 'the_permalink', get_permalink( $post_id ) ) ) ) . '','comment_notes_before' => '' . __( 'Your email address will not be published.' ) . ( $req ? $required_text : '' ) . '','comment_notes_after' => '' . sprintf( __( 'You may use these HTML tags and attributes: %s' ), ' ' . allowed_tags() . '' ) . '','id_form' => 'commentform','id_submit' => 'submit','title_reply' => __( 'Leave a Reply' ),'title_reply_to' => __( 'Leave a Reply to %s' ),'cancel_reply_link' => __( 'Cancel reply' ),'label_submit' => __( 'Post Comment' ),'format' => 'xhtml',);根据你自己要求改就OK
如何简单地给WordPress页面或文章设置访问密码
Wordpress 如何显示作者文章数量和评论数量,这是通过数据库查询获得文章作者文章数量和评论数量,其代码如下:ID;$comment_count = $wpdb->get_var( $wpdb->prepare( “SELECT COUNT(*) FROM $wpdb->comments WHERE comment_approved='1′ AND user_id = '$author_id' AND comment_type not in ('trackback','pingback')” ) ); //查询作者评论数量$post_count = $wpdb->get_var( $wpdb->prepare( “SELECT COUNT(*) FROM $wpdb->posts WHERE post_status IN ('publish','static') AND post_author = '$author_id' AND post_type = 'iask'” ) ); //查询作者文章数量?>下面是显示文章作者文章数和评论数:文章数量:点评数量:将以上代码放到wordpress主题 single.php文件 loop内即可希望能够帮到你。
wordpress关闭评论之后,”评论已关闭“这几个字怎么删除
实现代码,放到当前主题的functions.php中即可(这里还增加了对IP的判断,更保险):// 获取评论用户的ip,参考wp-includes/comment.phpfunction ludou_getIP() { $ip = $_SERVER['REMOTE_ADDR']; $ip = preg_replace( '/[^0-9a-fA-F:., ]/', '', $ip ); return $ip;}function ludou_only_one_comment( $commentdata ) { global $wpdb; $currentUser = wp_get_current_user(); // 不限制管理员发表评论 if(empty($currentUser->roles) || !in_array('administrator', $currentUser->roles)) { $bool = $wpdb->get_var("SELECT comment_ID FROM $wpdb->comments WHERE comment_post_ID = ".$commentdata['comment_post_ID']." AND (comment_author = '".$commentdata['comment_author']."' OR comment_author_email = '".$commentdata['comment_author_email']."' OR comment_author_IP = '".ludou_getIP()."') LIMIT 0, 1;"); if($bool) wp_die('本站每篇文章只允许评论一次。
点此返回'); } return $commentdata;}add_action( 'preprocess_comment' , 'ludou_only_one_comment', 2...
wordpress 获取评论数,在线等,急!!
展开全部 可以利用wordpress中的widgets来搞定,来吧实战开始: 首先,备份\wp-includes\default-widgets.php 然后,找到\wp-includes\default-widgets.php文件中,大约在679行 sprintf(_x('%1$s on %2$s', 'widgets'), get_comment_author_link(), 'comment_ID) ) . '">' . get_the_title($comment->comment_post_ID) . '') . '';将其修改为: //sprintf(_x('%1$s on %2$s', 'widgets'), get_comment_author_link(), 'comment_ID) ) . '">' . get_the_title($comment->comment_post_ID) . '') . '';sprintf(_x('%1$s 在“%2$s”留言:', 'widgets'), get_comment_author_link(), 'comment_ID) ) . '">' . get_the_title($comment->comment_post_ID) . '') . '' . strip_tags( $comment->comment_content) . '';这样就OK了。
前台显示效果如图: ...
转载请注明出处51数据库 » wordpress comment_fo