comment_status ) ) { do_action( 'comment_id_not_found', $comment_post_ID ); wp_die( $invalid_text ); } $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( __( '抱歉,该文章无法评论', 'Bing' ) ); }elseif( 'trash' == $status ){ do_action( 'comment_on_trash', $comment_post_ID ); wp_die( $invalid_text ); }elseif( !$status_obj->public && !$status_obj->private ){ do_action( 'comment_on_draft', $comment_post_ID ); wp_die( $invalid_text ); }elseif( post_password_required( $comment_post_ID ) ) { do_action( 'comment_on_password_protected', $comment_post_ID ); wp_die( __( '抱歉,输入密码之后才能评论', 'Bing' ) ); }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; $user = wp_get_current_user(); if( $user->exists() ){ if( empty( $user->display_name ) ) $user->display_name = $user->user_login; $comment_author = wp_slash( $user->display_name ); $comment_author_email = wp_slash( $user->user_email ); $comment_author_url = wp_slash( $user->user_url ); if( current_user_can( 'unfiltered_html' ) && !( isset( $_POST['_wp_unfiltered_html_comment'] ) && wp_verify_nonce( $_POST['_wp_unfiltered_html_comment'], 'unfiltered-html-comment_' . $comment_post_ID ) ) ){ kses_remove_filters(); kses_init_filters(); } }elseif( get_option( 'comment_registration' ) || 'private' == $status ) wp_die( __( '抱歉,您必须登录才能评论' ) ); $comment_type = ''; if( get_option( 'require_name_email' ) && !$user->exists() ){ if( 6 > strlen( $comment_author_email ) || '' == $comment_author ) wp_die( __( '请填写正确的昵称和邮箱' ) ); elseif( ! is_email( $comment_author_email ) ) wp_die( __( '请使用一个有效的邮箱' ) ); } $user = wp_get_current_user(); if( $user->exists() ){ if( empty( $user->display_name ) ) $user->display_name = $user->user_login; $comment_author = esc_sql( $user->display_name ); $comment_author_email = esc_sql( $user->user_email ); $comment_author_url = esc_sql( $user->user_url ); $user_ID = esc_sql( $user->ID ); if( current_user_can( 'unfiltered_html' ) ){ if( wp_create_nonce( 'unfiltered-html-comment_' . $comment_post_ID ) != $_POST['_wp_unfiltered_html_comment'] ){ kses_remove_filters(); kses_init_filters(); } } }elseif( get_option( 'comment_registration' ) || $status == 'private' ) wp_die( __( '您必须登录才能发表评论', 'Bing' ) ); if( get_option( 'require_name_email' ) && !$user->exists() ){ if( strlen( $comment_author_email ) < 6 || !$comment_author ) wp_die( __( '请填写正确的昵称和邮箱', 'Bing' ) ); elseif( !is_email( $comment_author_email ) ) wp_die( __( '请使用一个有效的邮箱', 'Bing' ) ); } if( empty( $comment_content ) ) wp_die( __( '评论不能为空', 'Bing' ) ); $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'); if( !$comment_id = wp_new_comment( $commentdata ) ) wp_die( __( '无法保存评论,请稍后再试', 'Bing' ) ); $comment = get_comment( $comment_id ); do_action( 'set_comment_cookies', $comment, $user ); Bing_comments_list_loop( $comment ); Bing_comments_list_loop_end(); remove_filter( 'wp_die_ajax_handler', 'Bing_add_ajax_comment_error', 16 ); remove_action( 'comment_flood_trigger', 'Bing_ajax_comment_flood_trigger', 16 ); remove_action( 'comment_duplicate_trigger', 'Bing_ajax_comment_duplicate_trigger', 16 ); wp_die(); } add_action( 'wp_ajax_submit_comment', 'Bing_ajax_comment' ); add_action( 'wp_ajax_nopriv_submit_comment', 'Bing_ajax_comment' ); /** * AJAX 添加评论报错改造 */ function Bing_add_ajax_comment_error(){ return 'Bing_ajax_comment_error'; } /** * AJAX 评论报错改造 */ function Bing_ajax_comment_error( $message ){ header( 'HTTP/1.0 500 Internal Server Error' ); header( 'Content-Type: text/plain;charset=UTF-8' ); die( $message ); } /** * AJAX 评论报错频率过快改造 */ function Bing_ajax_comment_flood_trigger(){ wp_die( __( '您评论的速度太快了,休息一下吧', 'Bing' ) ); } /** * AJAX 评论报错内容重复改造 */ function Bing_ajax_comment_duplicate_trigger(){ wp_die( __( '您好像已经发表过这篇评论了', 'Bing' ) ); } /** * 把评论中的代码转换成实体字符 */ function Bing_comment_code_htmlspecialchars( $comment ){ $comment['comment_content'] = preg_replace_callback( '|
%s
%s
%s
%s
%s
%s