2 require( dirname(__FILE__) . '/wp-config.php' );
6 $comment_post_ID = (int) $_POST['comment_post_ID'];
8 $status = $wpdb->get_row("SELECT post_status, comment_status FROM $wpdb->posts WHERE ID = '$comment_post_ID'");
10 if ( empty($status->comment_status) ) {
11 do_action('comment_id_not_found', $comment_post_ID);
13 } elseif ( 'closed' == $status->comment_status ) {
14 do_action('comment_closed', $comment_post_ID);
15 die( __('Sorry, comments are closed for this item.') );
16 } elseif ( 'draft' == $status->post_status ) {
17 do_action('comment_on_draft', $comment_post_ID);
21 $comment_author = trim($_POST['author']);
22 $comment_author_email = trim($_POST['email']);
23 $comment_author_url = trim($_POST['url']);
24 $comment_content = trim($_POST['comment']);
26 // If the user is logged in
27 get_currentuserinfo();
29 $comment_author = $wpdb->escape($user_identity);
30 $comment_author_email = $wpdb->escape($user_email);
31 $comment_author_url = $wpdb->escape($user_url);
33 if ( get_option('comment_registration') )
34 die( __('Sorry, you must be logged in to post a comment.') );
39 if ( get_settings('require_name_email') && !$user_ID ) {
40 if ( 6 > strlen($comment_author_email) || '' == $comment_author )
41 die( __('Error: please fill the required fields (name, email).') );
42 elseif ( !is_email($comment_author_email))
43 die( __('Error: please enter a valid email address.') );
46 if ( '' == $comment_content )
47 die( __('Error: please type a comment.') );
49 $commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_content', 'comment_type', 'user_ID');
51 $comment_id = wp_new_comment( $commentdata );
54 $comment = get_comment($comment_id);
55 setcookie('comment_author_' . COOKIEHASH, $comment->comment_author, time() + 30000000, COOKIEPATH, COOKIE_DOMAIN);
56 setcookie('comment_author_email_' . COOKIEHASH, $comment->comment_author_email, time() + 30000000, COOKIEPATH, COOKIE_DOMAIN);
57 setcookie('comment_author_url_' . COOKIEHASH, clean_url($comment->comment_author_url), time() + 30000000, COOKIEPATH, COOKIE_DOMAIN);
60 $location = ( empty( $_POST['redirect_to'] ) ) ? get_permalink( $comment_post_ID ) : $_POST['redirect_to'];
62 wp_redirect( $location );