Ticket #21849: wp-comments-post.php

File wp-comments-post.php, 3.5 KB (added by ryansatterfield, 9 months ago)

Removed old escape function from lines 59 to 61

Line 
1<?php
2/**
3 * Handles Comment Post to WordPress and prevents duplicate comment posting.
4 *
5 * @package WordPress
6 */
7
8if ( 'POST' != $_SERVER['REQUEST_METHOD'] ) {
9        header('Allow: POST');
10        header('HTTP/1.1 405 Method Not Allowed');
11        header('Content-Type: text/plain');
12        exit;
13}
14
15/** Sets up the WordPress Environment. */
16require( dirname(__FILE__) . '/wp-load.php' );
17
18nocache_headers();
19
20$comment_post_ID = isset($_POST['comment_post_ID']) ? (int) $_POST['comment_post_ID'] : 0;
21$post = get_post($comment_post_ID);
22
23if ( empty($post->comment_status) ) {
24        do_action('comment_id_not_found', $comment_post_ID);
25        exit;
26}
27
28// get_post_status() will get the parent status for attachments.
29$status = get_post_status($post);
30
31$status_obj = get_post_status_object($status);
32
33if ( !comments_open($comment_post_ID) ) {
34        do_action('comment_closed', $comment_post_ID);
35        wp_die( __('Sorry, comments are closed for this item.') );
36} elseif ( 'trash' == $status ) {
37        do_action('comment_on_trash', $comment_post_ID);
38        exit;
39} elseif ( !$status_obj->public && !$status_obj->private ) {
40        do_action('comment_on_draft', $comment_post_ID);
41        exit;
42} elseif ( post_password_required($comment_post_ID) ) {
43        do_action('comment_on_password_protected', $comment_post_ID);
44        exit;
45} else {
46        do_action('pre_comment_on_post', $comment_post_ID);
47}
48
49$comment_author       = ( isset($_POST['author']) )  ? trim($_POST['author']) : null; 
50$comment_author_email = ( isset($_POST['email']) )   ? trim($_POST['email']) : null; 
51$comment_author_url   = ( isset($_POST['url']) )     ? trim($_POST['url']) : null; 
52$comment_content      = ( isset($_POST['comment']) ) ? trim($_POST['comment']) : null;
53
54// If the user is logged in
55$user = wp_get_current_user();
56if ( $user->exists() ) {
57        if ( empty( $user->display_name ) )
58                $user->display_name=$user->user_login;
59        $comment_author       = $wpdb->esc_attr($user->display_name); //edited from escape RMS
60        $comment_author_email = $wpdb->esc_attr($user->user_email); // edited from escape RMS
61        $comment_author_url   = $wpdb->esc_attr($user->user_url); //edited from escape RMS
62        if ( current_user_can('unfiltered_html') ) {
63                if ( wp_create_nonce('unfiltered-html-comment_' . $comment_post_ID) != $_POST['_wp_unfiltered_html_comment'] ) {
64                        kses_remove_filters(); // start with a clean slate
65                        kses_init_filters(); // set up the filters
66                }
67        }
68} else {
69        if ( get_option('comment_registration') || 'private' == $status )
70                wp_die( __('Sorry, you must be logged in to post a comment.') );
71}
72
73$comment_type = '';
74
75if ( get_option('require_name_email') && !$user->exists() ) {
76        if ( 6 > strlen($comment_author_email) || '' == $comment_author )
77                wp_die( __('<strong>ERROR</strong>: please fill the required fields (name, email).') );
78        elseif ( !is_email($comment_author_email))
79                wp_die( __('<strong>ERROR</strong>: please enter a valid email address.') );
80}
81
82if ( '' == $comment_content )
83        wp_die( __('<strong>ERROR</strong>: please type a comment.') );
84
85$comment_parent = isset($_POST['comment_parent']) ? absint($_POST['comment_parent']) : 0;
86
87$commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_content', 'comment_type', 'comment_parent', 'user_ID');
88
89$comment_id = wp_new_comment( $commentdata );
90
91$comment = get_comment($comment_id);
92do_action('set_comment_cookies', $comment, $user);
93
94$location = empty($_POST['redirect_to']) ? get_comment_link($comment_id) : $_POST['redirect_to'] . '#comment-' . $comment_id;
95$location = apply_filters('comment_post_redirect', $location, $comment);
96
97wp_safe_redirect( $location );
98exit;