2003-04-01 16:12:34 +02:00
|
|
|
<?php
|
2008-05-25 17:50:15 +02:00
|
|
|
/**
|
|
|
|
* Handles Comment Post to WordPress and prevents duplicate comment posting.
|
|
|
|
*
|
2008-06-20 22:56:40 +02:00
|
|
|
* @package WordPress
|
2008-05-25 17:50:15 +02:00
|
|
|
*/
|
|
|
|
|
2007-07-04 18:12:37 +02: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 19:34:42 +02:00
|
|
|
}
|
2008-05-25 17:50:15 +02:00
|
|
|
|
|
|
|
/** Sets up the WordPress Environment. */
|
2008-05-21 07:59:27 +02:00
|
|
|
require( dirname(__FILE__) . '/wp-load.php' );
|
2003-04-01 16:12:34 +02:00
|
|
|
|
2005-11-05 23:08:56 +01:00
|
|
|
nocache_headers();
|
|
|
|
|
2013-03-01 17:28:40 +01:00
|
|
|
$comment_post_ID = isset($_POST['comment_post_ID']) ? (int) $_POST['comment_post_ID'] : 0;
|
2003-04-01 16:12:34 +02:00
|
|
|
|
2010-04-14 16:07:48 +02:00
|
|
|
$post = get_post($comment_post_ID);
|
2004-11-15 07:20:28 +01:00
|
|
|
|
2013-09-05 18:05:09 +02:00
|
|
|
if ( empty( $post->comment_status ) ) {
|
|
|
|
/**
|
2013-09-06 03:38:09 +02:00
|
|
|
* Fires when a comment is attempted on a post that does not exist.
|
2013-09-05 18:05:09 +02:00
|
|
|
*
|
2014-02-09 21:12:12 +01:00
|
|
|
* @since 1.5.0
|
|
|
|
*
|
2013-09-05 18:12:09 +02:00
|
|
|
* @param int $comment_post_ID Post ID.
|
2013-09-05 18:05:09 +02:00
|
|
|
*/
|
|
|
|
do_action( 'comment_id_not_found', $comment_post_ID );
|
2004-12-16 03:57:05 +01:00
|
|
|
exit;
|
2010-02-18 21:08:35 +01:00
|
|
|
}
|
|
|
|
|
2010-04-14 16:07:48 +02: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 21:08:35 +01:00
|
|
|
|
2013-09-05 18:05:09 +02:00
|
|
|
if ( ! comments_open( $comment_post_ID ) ) {
|
|
|
|
/**
|
2013-09-06 03:38:09 +02:00
|
|
|
* Fires when a comment is attempted on a post that has comments closed.
|
2013-09-05 18:05:09 +02:00
|
|
|
*
|
2014-02-09 21:12:12 +01:00
|
|
|
* @since 1.5.0
|
|
|
|
*
|
2013-09-05 18:12:09 +02:00
|
|
|
* @param int $comment_post_ID Post ID.
|
2013-09-05 18:05:09 +02:00
|
|
|
*/
|
|
|
|
do_action( 'comment_closed', $comment_post_ID );
|
2014-11-26 21:17:24 +01:00
|
|
|
wp_die( __( 'Sorry, comments are closed for this item.' ), 403 );
|
2010-04-14 16:07:48 +02:00
|
|
|
} elseif ( 'trash' == $status ) {
|
2013-09-05 18:05:09 +02:00
|
|
|
/**
|
2013-09-06 03:38:09 +02:00
|
|
|
* Fires when a comment is attempted on a trashed post.
|
2013-09-05 18:05:09 +02:00
|
|
|
*
|
|
|
|
* @since 2.9.0
|
2014-02-09 21:12:12 +01:00
|
|
|
*
|
2013-09-05 18:12:09 +02:00
|
|
|
* @param int $comment_post_ID Post ID.
|
2013-09-05 18:05:09 +02:00
|
|
|
*/
|
|
|
|
do_action( 'comment_on_trash', $comment_post_ID );
|
2009-11-05 22:03:09 +01:00
|
|
|
exit;
|
2013-09-05 18:05:09 +02:00
|
|
|
} elseif ( ! $status_obj->public && ! $status_obj->private ) {
|
|
|
|
/**
|
2013-09-06 03:38:09 +02:00
|
|
|
* Fires when a comment is attempted on a post in draft mode.
|
2013-09-05 18:05:09 +02:00
|
|
|
*
|
2014-02-18 22:45:13 +01:00
|
|
|
* @since 1.5.1
|
2014-02-09 21:12:12 +01:00
|
|
|
*
|
2013-09-05 18:12:09 +02:00
|
|
|
* @param int $comment_post_ID Post ID.
|
2013-09-05 18:05:09 +02:00
|
|
|
*/
|
|
|
|
do_action( 'comment_on_draft', $comment_post_ID );
|
2010-02-18 21:08:35 +01:00
|
|
|
exit;
|
2013-09-05 18:05:09 +02:00
|
|
|
} elseif ( post_password_required( $comment_post_ID ) ) {
|
|
|
|
/**
|
2013-09-06 03:38:09 +02:00
|
|
|
* Fires when a comment is attempted on a password-protected post.
|
2013-09-05 18:05:09 +02:00
|
|
|
*
|
2014-02-09 21:12:12 +01:00
|
|
|
* @since 2.9.0
|
|
|
|
*
|
2013-09-05 18:12:09 +02:00
|
|
|
* @param int $comment_post_ID Post ID.
|
2013-09-05 18:05:09 +02:00
|
|
|
*/
|
|
|
|
do_action( 'comment_on_password_protected', $comment_post_ID );
|
2010-01-07 20:37:16 +01:00
|
|
|
exit;
|
2009-05-10 09:11:12 +02:00
|
|
|
} else {
|
2013-09-05 18:05:09 +02:00
|
|
|
/**
|
2013-09-06 03:38:09 +02:00
|
|
|
* Fires before a comment is posted.
|
2013-09-05 18:05:09 +02:00
|
|
|
*
|
2014-02-09 21:12:12 +01:00
|
|
|
* @since 2.8.0
|
|
|
|
*
|
2013-09-05 18:12:09 +02:00
|
|
|
* @param int $comment_post_ID Post ID.
|
2013-09-05 18:05:09 +02:00
|
|
|
*/
|
|
|
|
do_action( 'pre_comment_on_post', $comment_post_ID );
|
2004-11-15 07:20:28 +01:00
|
|
|
}
|
2004-05-08 01:21:31 +02:00
|
|
|
|
2013-03-01 17:28:40 +01: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 03:57:05 +01:00
|
|
|
|
2005-01-31 07:38:12 +01:00
|
|
|
// If the user is logged in
|
2006-02-22 20:08:55 +01:00
|
|
|
$user = wp_get_current_user();
|
2012-04-06 21:18:45 +02:00
|
|
|
if ( $user->exists() ) {
|
2008-11-19 07:58:44 +01:00
|
|
|
if ( empty( $user->display_name ) )
|
2013-03-01 17:28:40 +01:00
|
|
|
$user->display_name=$user->user_login;
|
2013-07-16 16:19:03 +02:00
|
|
|
$comment_author = wp_slash( $user->display_name );
|
|
|
|
$comment_author_email = wp_slash( $user->user_email );
|
|
|
|
$comment_author_url = wp_slash( $user->user_url );
|
2013-08-27 15:57:09 +02:00
|
|
|
if ( current_user_can( 'unfiltered_html' ) ) {
|
|
|
|
if ( ! isset( $_POST['_wp_unfiltered_html_comment'] )
|
|
|
|
|| ! wp_verify_nonce( $_POST['_wp_unfiltered_html_comment'], 'unfiltered-html-comment_' . $comment_post_ID )
|
|
|
|
) {
|
2007-03-15 00:10:57 +01:00
|
|
|
kses_remove_filters(); // start with a clean slate
|
|
|
|
kses_init_filters(); // set up the filters
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2014-11-26 21:17:24 +01:00
|
|
|
if ( get_option( 'comment_registration' ) || 'private' == $status ) {
|
|
|
|
wp_die( __( 'Sorry, you must be logged in to post a comment.' ), 403 );
|
|
|
|
}
|
2007-03-15 00:10:57 +01:00
|
|
|
}
|
2004-12-16 03:57:05 +01:00
|
|
|
|
2005-01-31 07:38:12 +01:00
|
|
|
$comment_type = '';
|
2004-12-16 03:57:05 +01:00
|
|
|
|
2012-04-06 21:18:45 +02:00
|
|
|
if ( get_option('require_name_email') && !$user->exists() ) {
|
2014-11-26 21:17:24 +01:00
|
|
|
if ( 6 > strlen( $comment_author_email ) || '' == $comment_author ) {
|
|
|
|
wp_die( __( '<strong>ERROR</strong>: please fill the required fields (name, email).' ), 200 );
|
2015-01-08 08:05:25 +01:00
|
|
|
} elseif ( ! is_email( $comment_author_email ) ) {
|
2014-11-26 21:17:24 +01:00
|
|
|
wp_die( __( '<strong>ERROR</strong>: please enter a valid email address.' ), 200 );
|
|
|
|
}
|
2005-03-22 01:29:43 +01:00
|
|
|
}
|
2004-05-08 01:21:31 +02:00
|
|
|
|
2014-11-26 21:17:24 +01:00
|
|
|
if ( '' == $comment_content ) {
|
|
|
|
wp_die( __( '<strong>ERROR</strong>: please type a comment.' ), 200 );
|
|
|
|
}
|
2003-06-04 20:17:48 +02:00
|
|
|
|
2013-03-01 17:28:40 +01:00
|
|
|
$comment_parent = isset($_POST['comment_parent']) ? absint($_POST['comment_parent']) : 0;
|
2008-08-24 08:56:22 +02:00
|
|
|
|
2009-12-01 03:06:02 +01: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 16:12:34 +02:00
|
|
|
|
2007-03-23 03:05:29 +01:00
|
|
|
$comment_id = wp_new_comment( $commentdata );
|
2014-06-05 06:38:14 +02:00
|
|
|
if ( ! $comment_id ) {
|
|
|
|
wp_die( __( "<strong>ERROR</strong>: The comment could not be saved. Please try again later." ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
$comment = get_comment( $comment_id );
|
2013-09-05 18:05:09 +02:00
|
|
|
|
|
|
|
/**
|
2013-09-06 03:38:09 +02:00
|
|
|
* Perform other actions when comment cookies are set.
|
2013-09-05 18:05:09 +02:00
|
|
|
*
|
|
|
|
* @since 3.4.0
|
|
|
|
*
|
2013-09-05 18:12:09 +02:00
|
|
|
* @param object $comment Comment object.
|
|
|
|
* @param WP_User $user User object. The user may not exist.
|
2013-09-05 18:05:09 +02:00
|
|
|
*/
|
|
|
|
do_action( 'set_comment_cookies', $comment, $user );
|
2003-04-07 08:55:21 +02:00
|
|
|
|
2013-03-01 17:28:40 +01:00
|
|
|
$location = empty($_POST['redirect_to']) ? get_comment_link($comment_id) : $_POST['redirect_to'] . '#comment-' . $comment_id;
|
2013-09-05 18:05:09 +02:00
|
|
|
|
|
|
|
/**
|
2014-02-09 21:12:12 +01:00
|
|
|
* Filter the location URI to send the commenter after posting.
|
2013-09-05 18:05:09 +02:00
|
|
|
*
|
2014-02-09 21:12:12 +01:00
|
|
|
* @since 2.0.5
|
2013-09-05 18:05:09 +02:00
|
|
|
*
|
2013-09-05 18:12:09 +02:00
|
|
|
* @param string $location The 'redirect_to' URI sent via $_POST.
|
|
|
|
* @param object $comment Comment object.
|
2013-09-05 18:05:09 +02:00
|
|
|
*/
|
|
|
|
$location = apply_filters( 'comment_post_redirect', $location, $comment );
|
2004-10-05 18:22:31 +02:00
|
|
|
|
2012-04-10 19:21:17 +02:00
|
|
|
wp_safe_redirect( $location );
|
2010-12-09 19:02:54 +01:00
|
|
|
exit;
|