/**

* 这个文件是从根目录下拷贝过来的comment-posts.php文件,主要功能就是提交评论,同时增加了显示出结果的功能。

*/

if ( 'POST' != $_SERVER['REQUEST_METHOD'] ) {

header('Allow: POST');

header('HTTP/1.1 405 Method Not Allowed');

header('Content-Type: text/plain');

exit;

}

/** Sets up the WordPress Environment. */

require( dirname(__FILE__) . '/../../../../wp-load.php' ); //修改load.php地址

nocache_headers();

$comment_post_ID = isset($_POST['comment_post_ID']) ? (int) $_POST['comment_post_ID'] : 0;

$post = get_post($comment_post_ID);

if ( empty($post->comment_status) ) {

do_action('comment_id_not_found', $comment_post_ID);

exit;

}

// get_post_status() will get the parent status for attachments.

$status = get_post_status($post);

$status_obj = get_post_status_object($status);

if ( !comments_open($comment_post_ID) ) {

do_action('comment_closed', $comment_post_ID);

wp_die( __('Sorry, comments are closed for this item.') );

} elseif ( 'trash' == $status ) {

do_action('comment_on_trash', $comment_post_ID);

exit;

} elseif ( !$status_obj->public && !$status_obj->private ) {

do_action('comment_on_draft', $comment_post_ID);

exit;

} elseif ( post_password_required($comment_post_ID) ) {

do_action('comment_on_password_protected', $comment_post_ID);

exit;

} else {

do_action('pre_comment_on_post', $comment_post_ID);

}

$comment_author = ( isset($_POST['author']) ) ? trim(strip_tags($_POST['author'])) : null;

$comment_author_email = ( isset($_POST['email']) ) ? trim($_POST['email']) : null;

$comment_author_url = ( isset($_POST['url']) ) ? trim($_POST['url']) : null;

$comment_content = ( isset($_POST['comment']) ) ? trim($_POST['comment']) : null;

// If the user is logged in

$user = wp_get_current_user();

if ( $user->ID ) {

if ( empty( $user->display_name ) )

$user->display_name=$user->user_login;

$comment_author = $wpdb->escape($user->display_name);

$comment_author_email = $wpdb->escape($user->user_email);

$comment_author_url = $wpdb->escape($user->user_url);

if ( current_user_can('unfiltered_html') ) {

if ( wp_create_nonce('unfiltered-html-comment_' . $comment_post_ID) != $_POST['_wp_unfiltered_html_comment'] ) {

kses_remove_filters(); // start with a clean slate

kses_init_filters(); // set up the filters

}

}

} else {

if ( get_option('comment_registration') || 'private' == $status )

wp_die( __('Sorry, you must be logged in to post a comment.') );

}

$comment_type = '';

if ( get_option('require_name_email') && !$user->ID ) {

if ( 6 > strlen($comment_author_email) || '' == $comment_author )

wp_die( __('ERROR: please fill the required fields (name, email).') );

elseif ( !is_email($comment_author_email))

wp_die( __('ERROR: please enter a valid email address.') );

}

if ( '' == $comment_content )

wp_die( __('ERROR: please type a comment.') );

$comment_parent = isset($_POST['comment_parent']) ? absint($_POST['comment_parent']) : 0;

$commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_content', 'comment_type', 'comment_parent', 'user_ID');

$comment_id = wp_new_comment( $commentdata );

$comment = get_comment($comment_id);

if ( !$user->ID ) {

$comment_cookie_lifetime = apply_filters('comment_cookie_lifetime', 30000000);

setcookie('comment_author_' . COOKIEHASH, $comment->comment_author, time() + $comment_cookie_lifetime, COOKIEPATH, COOKIE_DOMAIN);

setcookie('comment_author_email_' . COOKIEHASH, $comment->comment_author_email, time() + $comment_cookie_lifetime, COOKIEPATH, COOKIE_DOMAIN);

setcookie('comment_author_url_' . COOKIEHASH, esc_url($comment->comment_author_url), time() + $comment_cookie_lifetime, COOKIEPATH, COOKIE_DOMAIN);

}

///

?>

<?php if ($comment->comment_approved == '0')printf('

%s

','您的见解正在审核中,很快就会出现在评论列表~~'); ?>

wordpressPHP实现ajax评论,wordpress无刷新评论:无需插件ajax实现wordpress comment无刷新机制...相关推荐

  1. ajax判断邮箱是否重复,帝国cms插件ajax判断用户名和邮箱是否存在

    在注册页面没修改的话就是e/template/member/register.php中添加js代码 //by winston ajax会员邮箱判断 var xmlHttp; function chkU ...

  2. ajax无刷新留言板远吗,基于jquery实现ajax无刷新评论

    基于jquery实现ajax无刷新评论 发布于 2017-03-31 11:26:07 | 75 次阅读 | 评论: 0 | 来源: 网友投递 jQuery javascript框架jQuery是一个 ...

  3. ajax无刷新评论的思路,ajax学习——ajax版无刷新评论(数据库)

    //Comment.htm 无刷新评论 type="text/javascript"> //加载评论 $(function() { $.post("GetComme ...

  4. ajax无刷新评论示例

    下面就为大家带来一篇 ajax无刷新评论示例.学习还是有点帮助的,给大家做个参考吧. 这是留言板的界面,当用户点击提交留言的时候,自动提交到我的留言下面 留言内容中为空,或者为灰色的"没有填 ...

  5. wordpress 评论ajax,WordPress教程 WordPress实现提交评论ajax翻页效果教程

    WordPress提交评论ajax翻页的效果会很大的提高用户体验度,虽然我们一般的个人WordPress博客评论也不会有很多,但是用户体验至上嘛,所以WordPress主题站小编为大家分享WordPr ...

  6. 如何构建自己的免费无服务器评论框

    by Shaun Persad 通过Shaun Persad 如何构建自己的免费无服务器评论框 (How you can build your own free, serverless comment ...

  7. WordPress有新评论时微信通知站长

    最近小任发现了一个特别严重的漏洞,甚至威胁到整个网站的安全,那就是smtp发信会导致暴露网站的真实ip,这样就算你有cdn也没用了,除非购买高仿ip和盾机,但是作为穷站长的小任怎么可能有钱买--所以昨 ...

  8. 五种WordPress防止垃圾评论方法-过滤垃圾评论提高WP运行效率

    点击上方蓝字"优派编程"选择"加为星标",第一时间关注原创干货 最近小编wp后台老是收到烦人的文章垃圾评论,并且评论是机器人发过来的.请看下图: 为了防止对方机 ...

  9. wp comments post.php,通过修改wp-comments-post.php 防wordpress垃圾(spam)评论 | 沉默过客

    相信大家都饱受垃圾评论困扰,于是什么随机验证码.小学加减法.滑动解锁等各种防垃圾评论的方法都尝试个遍,最终发现垃圾留言还是屡禁不止. 上面的方法只能对付一些自动填表单的垃圾评论,其实垃圾评论机器人根本 ...

最新文章

  1. Java使用Maven加载redis.clients连接Redis
  2. Swift:print()vs println()vs NSLog()
  3. python3命令行运行程序怎么关闭_python中怎样退出程序运行?
  4. 自定义圆形倒计时Android,Android自定义View倒计时圆
  5. 信息学奥赛一本通(1407:笨小猴)
  6. mysql软件使用,内含福利
  7. pl/sql 存储过程实例
  8. 黑苹果10.14.5安装WebDriver驱动nvidia独立显卡
  9. 《千字文》 梁•周兴嗣
  10. 解决IE浏览器jQuery执行ajax不响应问题
  11. Java第十二周作业
  12. PTA L1-088 静静的推荐
  13. 和同事技术争吵_注意数据争吵
  14. 如何参与到开源优测-积微速成计划任务
  15. while循环和doWhile循环
  16. php hrtime stopwatch,学习PHP中的高精度计时器HRTime扩展
  17. opencv中CV_IMAGE_ELEM的用法读取每个像素
  18. 深度优先搜索求解八数码问题
  19. 骑行318、 2016.7.28
  20. Spring事务和Aspects框架管理事务,看这篇就够了!(简单易懂!)

热门文章

  1. 期望最大化算法(Expectation-Maximum,简称EM)算法+EM算法+EM的应用
  2. p值+p-value+p value+显著性+significance
  3. Oxford Nanopore sequencing, hybrid error correction, and de novo assembly of a eukaryotic genome
  4. Linux下运行.cpp文件
  5. java swing 外观框架_【GUI】一、Swing外观框架BeautyEye使用
  6. flask_sqlalchemy 多对多 关系 对中间表的操作
  7. 对抗网络用于人脸转正--Beyond Face Rotation
  8. 报错解决:fatal error: json/json.h: No such file or directory
  9. SynchronizedMap和ConcurrentHashMap有什么区别
  10. Centos7上安装rabbitmq和使用