2003-04-01 14:12:34 +00:00
|
|
|
<?php
|
2008-05-25 15:50:15 +00:00
|
|
|
/**
|
|
|
|
* Handles Comment Post to WordPress and prevents duplicate comment posting.
|
|
|
|
*
|
2008-06-20 20:56:40 +00:00
|
|
|
* @package WordPress
|
2008-05-25 15:50:15 +00:00
|
|
|
*/
|
|
|
|
|
2007-07-04 16:12:37 +00:00
|
|
|
if ( 'POST' != $_SERVER['REQUEST_METHOD'] ) {
|
|
|
|
header('Allow: POST');
|
|
|
|
header('HTTP/1.1 405 Method Not Allowed');
|
|
|
|
header('Content-Type: text/plain');
|
|
|
|
exit;
|
2007-03-28 17:34:42 +00:00
|
|
|
}
|
2008-05-25 15:50:15 +00:00
|
|
|
|
|
|
|
/** Sets up the WordPress Environment. */
|
2008-05-21 05:59:27 +00:00
|
|
|
require( dirname(__FILE__) . '/wp-load.php' );
|
2003-04-01 14:12:34 +00:00
|
|
|
|
2005-11-05 22:08:56 +00:00
|
|
|
nocache_headers();
|
|
|
|
|
2009-11-26 11:29:54 +00:00
|
|
|
$comment_post_ID = isset($_POST['comment_post_ID']) ? (int) $_POST['comment_post_ID'] : 0;
|
2003-04-01 14:12:34 +00:00
|
|
|
|
2010-04-14 14:07:48 +00:00
|
|
|
$post = get_post($comment_post_ID);
|
2004-11-15 06:20:28 +00:00
|
|
|
|
2010-04-14 14:07:48 +00:00
|
|
|
if ( empty($post->comment_status) ) {
|
2004-12-16 02:57:05 +00:00
|
|
|
do_action('comment_id_not_found', $comment_post_ID);
|
|
|
|
exit;
|
2010-02-18 20:08:35 +00:00
|
|
|
}
|
|
|
|
|
2010-04-14 14:07:48 +00:00
|
|
|
// get_post_status() will get the parent status for attachments.
|
|
|
|
$status = get_post_status($post);
|
|
|
|
|
|
|
|
$status_obj = get_post_status_object($status);
|
2010-02-18 20:08:35 +00:00
|
|
|
|
|
|
|
if ( !comments_open($comment_post_ID) ) {
|
2004-12-16 02:57:05 +00:00
|
|
|
do_action('comment_closed', $comment_post_ID);
|
2006-07-05 20:34:19 +00:00
|
|
|
wp_die( __('Sorry, comments are closed for this item.') );
|
2010-04-14 14:07:48 +00:00
|
|
|
} elseif ( 'trash' == $status ) {
|
2009-11-05 21:03:09 +00:00
|
|
|
do_action('comment_on_trash', $comment_post_ID);
|
|
|
|
exit;
|
2010-05-06 15:38:40 +00:00
|
|
|
} elseif ( !$status_obj->public && !$status_obj->private ) {
|
2010-02-18 20:08:35 +00:00
|
|
|
do_action('comment_on_draft', $comment_post_ID);
|
|
|
|
exit;
|
2010-01-07 19:37:16 +00:00
|
|
|
} elseif ( post_password_required($comment_post_ID) ) {
|
|
|
|
do_action('comment_on_password_protected', $comment_post_ID);
|
|
|
|
exit;
|
2009-05-10 07:11:12 +00:00
|
|
|
} else {
|
|
|
|
do_action('pre_comment_on_post', $comment_post_ID);
|
2004-11-15 06:20:28 +00:00
|
|
|
}
|
2004-05-07 23:21:31 +00:00
|
|
|
|
2008-11-04 20:16:54 +00:00
|
|
|
$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;
|
2004-12-16 02:57:05 +00:00
|
|
|
|
2005-01-31 06:38:12 +00:00
|
|
|
// If the user is logged in
|
2006-02-22 19:08:55 +00:00
|
|
|
$user = wp_get_current_user();
|
2012-04-06 19:18:45 +00:00
|
|
|
if ( $user->exists() ) {
|
2008-11-19 06:58:44 +00:00
|
|
|
if ( empty( $user->display_name ) )
|
|
|
|
$user->display_name=$user->user_login;
|
2006-02-22 19:08:55 +00:00
|
|
|
$comment_author = $wpdb->escape($user->display_name);
|
|
|
|
$comment_author_email = $wpdb->escape($user->user_email);
|
|
|
|
$comment_author_url = $wpdb->escape($user->user_url);
|
2007-03-14 23:10:57 +00:00
|
|
|
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 {
|
2010-04-14 14:07:48 +00:00
|
|
|
if ( get_option('comment_registration') || 'private' == $status )
|
2006-07-05 20:34:19 +00:00
|
|
|
wp_die( __('Sorry, you must be logged in to post a comment.') );
|
2007-03-14 23:10:57 +00:00
|
|
|
}
|
2004-12-16 02:57:05 +00:00
|
|
|
|
2005-01-31 06:38:12 +00:00
|
|
|
$comment_type = '';
|
2004-12-16 02:57:05 +00:00
|
|
|
|
2012-04-06 19:18:45 +00:00
|
|
|
if ( get_option('require_name_email') && !$user->exists() ) {
|
2005-04-20 19:05:34 +00:00
|
|
|
if ( 6 > strlen($comment_author_email) || '' == $comment_author )
|
2011-09-30 17:18:35 +00:00
|
|
|
wp_die( __('<strong>ERROR</strong>: please fill the required fields (name, email).') );
|
2005-03-22 00:29:43 +00:00
|
|
|
elseif ( !is_email($comment_author_email))
|
2011-09-30 17:18:35 +00:00
|
|
|
wp_die( __('<strong>ERROR</strong>: please enter a valid email address.') );
|
2005-03-22 00:29:43 +00:00
|
|
|
}
|
2004-05-07 23:21:31 +00:00
|
|
|
|
2004-12-17 08:44:30 +00:00
|
|
|
if ( '' == $comment_content )
|
2011-09-30 17:18:35 +00:00
|
|
|
wp_die( __('<strong>ERROR</strong>: please type a comment.') );
|
2003-06-04 18:17:48 +00:00
|
|
|
|
2008-08-24 06:56:22 +00:00
|
|
|
$comment_parent = isset($_POST['comment_parent']) ? absint($_POST['comment_parent']) : 0;
|
|
|
|
|
2009-12-01 02:06:02 +00:00
|
|
|
$commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_content', 'comment_type', 'comment_parent', 'user_ID');
|
2003-04-01 14:12:34 +00:00
|
|
|
|
2007-03-23 02:05:29 +00:00
|
|
|
$comment_id = wp_new_comment( $commentdata );
|
2003-09-01 01:26:20 +00:00
|
|
|
|
2006-02-28 04:22:24 +00:00
|
|
|
$comment = get_comment($comment_id);
|
2011-12-21 10:57:42 +00:00
|
|
|
do_action('set_comment_cookies', $comment, $user);
|
2003-04-07 06:55:21 +00:00
|
|
|
|
2008-11-04 03:37:30 +00:00
|
|
|
$location = empty($_POST['redirect_to']) ? get_comment_link($comment_id) : $_POST['redirect_to'] . '#comment-' . $comment_id;
|
2006-09-28 19:16:15 +00:00
|
|
|
$location = apply_filters('comment_post_redirect', $location, $comment);
|
2004-10-05 16:22:31 +00:00
|
|
|
|
2012-04-10 17:21:17 +00:00
|
|
|
wp_safe_redirect( $location );
|
2010-12-09 18:02:54 +00:00
|
|
|
exit;
|