39 |
40 |
40 if ( ! comments_open( $comment_post_ID ) ) { |
41 if ( ! comments_open( $comment_post_ID ) ) { |
41 /** |
42 /** |
42 * Fires when a comment is attempted on a post that has comments closed. |
43 * Fires when a comment is attempted on a post that has comments closed. |
43 * |
44 * |
44 * @since unknown |
45 * @since 1.5.0 |
|
46 * |
45 * @param int $comment_post_ID Post ID. |
47 * @param int $comment_post_ID Post ID. |
46 */ |
48 */ |
47 do_action( 'comment_closed', $comment_post_ID ); |
49 do_action( 'comment_closed', $comment_post_ID ); |
48 wp_die( __('Sorry, comments are closed for this item.') ); |
50 wp_die( __( 'Sorry, comments are closed for this item.' ), 403 ); |
49 } elseif ( 'trash' == $status ) { |
51 } elseif ( 'trash' == $status ) { |
50 /** |
52 /** |
51 * Fires when a comment is attempted on a trashed post. |
53 * Fires when a comment is attempted on a trashed post. |
52 * |
54 * |
53 * @since 2.9.0 |
55 * @since 2.9.0 |
|
56 * |
54 * @param int $comment_post_ID Post ID. |
57 * @param int $comment_post_ID Post ID. |
55 */ |
58 */ |
56 do_action( 'comment_on_trash', $comment_post_ID ); |
59 do_action( 'comment_on_trash', $comment_post_ID ); |
57 exit; |
60 exit; |
58 } elseif ( ! $status_obj->public && ! $status_obj->private ) { |
61 } elseif ( ! $status_obj->public && ! $status_obj->private ) { |
59 /** |
62 /** |
60 * Fires when a comment is attempted on a post in draft mode. |
63 * Fires when a comment is attempted on a post in draft mode. |
61 * |
64 * |
62 * @since unknown |
65 * @since 1.5.1 |
|
66 * |
63 * @param int $comment_post_ID Post ID. |
67 * @param int $comment_post_ID Post ID. |
64 */ |
68 */ |
65 do_action( 'comment_on_draft', $comment_post_ID ); |
69 do_action( 'comment_on_draft', $comment_post_ID ); |
66 exit; |
70 exit; |
67 } elseif ( post_password_required( $comment_post_ID ) ) { |
71 } elseif ( post_password_required( $comment_post_ID ) ) { |
68 /** |
72 /** |
69 * Fires when a comment is attempted on a password-protected post. |
73 * Fires when a comment is attempted on a password-protected post. |
70 * |
74 * |
71 * @since unknown |
75 * @since 2.9.0 |
|
76 * |
72 * @param int $comment_post_ID Post ID. |
77 * @param int $comment_post_ID Post ID. |
73 */ |
78 */ |
74 do_action( 'comment_on_password_protected', $comment_post_ID ); |
79 do_action( 'comment_on_password_protected', $comment_post_ID ); |
75 exit; |
80 exit; |
76 } else { |
81 } else { |
77 /** |
82 /** |
78 * Fires before a comment is posted. |
83 * Fires before a comment is posted. |
79 * |
84 * |
80 * @since unknown |
85 * @since 2.8.0 |
|
86 * |
81 * @param int $comment_post_ID Post ID. |
87 * @param int $comment_post_ID Post ID. |
82 */ |
88 */ |
83 do_action( 'pre_comment_on_post', $comment_post_ID ); |
89 do_action( 'pre_comment_on_post', $comment_post_ID ); |
84 } |
90 } |
85 |
91 |
103 kses_remove_filters(); // start with a clean slate |
109 kses_remove_filters(); // start with a clean slate |
104 kses_init_filters(); // set up the filters |
110 kses_init_filters(); // set up the filters |
105 } |
111 } |
106 } |
112 } |
107 } else { |
113 } else { |
108 if ( get_option('comment_registration') || 'private' == $status ) |
114 if ( get_option( 'comment_registration' ) || 'private' == $status ) { |
109 wp_die( __('Sorry, you must be logged in to post a comment.') ); |
115 wp_die( __( 'Sorry, you must be logged in to post a comment.' ), 403 ); |
|
116 } |
110 } |
117 } |
111 |
118 |
112 $comment_type = ''; |
119 $comment_type = ''; |
113 |
120 |
114 if ( get_option('require_name_email') && !$user->exists() ) { |
121 if ( get_option('require_name_email') && !$user->exists() ) { |
115 if ( 6 > strlen($comment_author_email) || '' == $comment_author ) |
122 if ( 6 > strlen( $comment_author_email ) || '' == $comment_author ) { |
116 wp_die( __('<strong>ERROR</strong>: please fill the required fields (name, email).') ); |
123 wp_die( __( '<strong>ERROR</strong>: please fill the required fields (name, email).' ), 200 ); |
117 elseif ( !is_email($comment_author_email)) |
124 } elseif ( ! is_email( $comment_author_email ) ) { |
118 wp_die( __('<strong>ERROR</strong>: please enter a valid email address.') ); |
125 wp_die( __( '<strong>ERROR</strong>: please enter a valid email address.' ), 200 ); |
|
126 } |
119 } |
127 } |
120 |
128 |
121 if ( '' == $comment_content ) |
129 if ( '' == $comment_content ) { |
122 wp_die( __('<strong>ERROR</strong>: please type a comment.') ); |
130 wp_die( __( '<strong>ERROR</strong>: please type a comment.' ), 200 ); |
|
131 } |
123 |
132 |
124 $comment_parent = isset($_POST['comment_parent']) ? absint($_POST['comment_parent']) : 0; |
133 $comment_parent = isset($_POST['comment_parent']) ? absint($_POST['comment_parent']) : 0; |
125 |
134 |
126 $commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_content', 'comment_type', 'comment_parent', 'user_ID'); |
135 $commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_content', 'comment_type', 'comment_parent', 'user_ID'); |
127 |
136 |
128 $comment_id = wp_new_comment( $commentdata ); |
137 $comment_id = wp_new_comment( $commentdata ); |
129 $comment = get_comment($comment_id); |
138 if ( ! $comment_id ) { |
|
139 wp_die( __( "<strong>ERROR</strong>: The comment could not be saved. Please try again later." ) ); |
|
140 } |
|
141 |
|
142 $comment = get_comment( $comment_id ); |
130 |
143 |
131 /** |
144 /** |
132 * Perform other actions when comment cookies are set. |
145 * Perform other actions when comment cookies are set. |
133 * |
146 * |
134 * @since 3.4.0 |
147 * @since 3.4.0 |
139 do_action( 'set_comment_cookies', $comment, $user ); |
152 do_action( 'set_comment_cookies', $comment, $user ); |
140 |
153 |
141 $location = empty($_POST['redirect_to']) ? get_comment_link($comment_id) : $_POST['redirect_to'] . '#comment-' . $comment_id; |
154 $location = empty($_POST['redirect_to']) ? get_comment_link($comment_id) : $_POST['redirect_to'] . '#comment-' . $comment_id; |
142 |
155 |
143 /** |
156 /** |
144 * The location URI to send commenter after posting. |
157 * Filter the location URI to send the commenter after posting. |
145 * |
158 * |
146 * @since unknown |
159 * @since 2.0.5 |
147 * |
160 * |
148 * @param string $location The 'redirect_to' URI sent via $_POST. |
161 * @param string $location The 'redirect_to' URI sent via $_POST. |
149 * @param object $comment Comment object. |
162 * @param object $comment Comment object. |
150 */ |
163 */ |
151 $location = apply_filters( 'comment_post_redirect', $location, $comment ); |
164 $location = apply_filters( 'comment_post_redirect', $location, $comment ); |