Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 106 lines (85 sloc) 3.931 kB
b43564c *** empty log message ***
saxmatt authored
1 <?php
a6a1522 File file level phpdoc from jacobsantos. see #7037
ryan authored
2 /**
3 * Handles Comment Post to WordPress and prevents duplicate comment posting.
4 *
e6e0954 Minor phpdoc fixups.
westi authored
5 * @package WordPress
a6a1522 File file level phpdoc from jacobsantos. see #7037
ryan authored
6 */
7
c671554 Update wp-comments-post.php to WP coding conventions. props JeremyVi…
markjaquith authored
8 if ( '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;
0013fcd Requesting wp-comments-post.php with GET should return 405. Props Mi…
ryan authored
13 }
a6a1522 File file level phpdoc from jacobsantos. see #7037
ryan authored
14
15 /** Sets up the WordPress Environment. */
5b81135 Allow wp-config.php to exist one level up from WordPress root directo…
ryan authored
16 require( dirname(__FILE__) . '/wp-load.php' );
b43564c *** empty log message ***
saxmatt authored
17
140f059 Redirect to permalink instead of referrer. Fixes #1673
matt authored
18 nocache_headers();
19
c3f7df6 Fix notices and phpdoc, props hakre, fixes #10758
azaozz authored
20 $comment_post_ID = isset($_POST['comment_post_ID']) ? (int) $_POST['comment_post_ID'] : 0;
b43564c *** empty log message ***
saxmatt authored
21
31c4756 Register 'inherit' as a post status. Check the parent post status whe…
ryan authored
22 $post = get_post($comment_post_ID);
a6f9511 Refuse comments for post IDs that do not exist.
rboren authored
23
31c4756 Register 'inherit' as a post status. Check the parent post status whe…
ryan authored
24 if ( empty($post->comment_status) ) {
65bbec7 Comments refactoring and cleanup
saxmatt authored
25 do_action('comment_id_not_found', $comment_post_ID);
26 exit;
06249d5 Deny commenting on any post with a non-public status. see #9674
ryan authored
27 }
28
31c4756 Register 'inherit' as a post status. Check the parent post status whe…
ryan authored
29 // get_post_status() will get the parent status for attachments.
30 $status = get_post_status($post);
31
32 $status_obj = get_post_status_object($status);
06249d5 Deny commenting on any post with a non-public status. see #9674
ryan authored
33
34 if ( !comments_open($comment_post_ID) ) {
65bbec7 Comments refactoring and cleanup
saxmatt authored
35 do_action('comment_closed', $comment_post_ID);
550ede8 wp_die() for comment errors. Props filosofo. fixes #1786
ryan authored
36 wp_die( __('Sorry, comments are closed for this item.') );
31c4756 Register 'inherit' as a post status. Check the parent post status whe…
ryan authored
37 } elseif ( 'trash' == $status ) {
33a8043 Trash comments when trashing a post. see #11073
ryan authored
38 do_action('comment_on_trash', $comment_post_ID);
39 exit;
970943e Allow comments on private posts to proceed past the comment_on_draft …
nacin authored
40 } elseif ( !$status_obj->public && !$status_obj->private ) {
06249d5 Deny commenting on any post with a non-public status. see #9674
ryan authored
41 do_action('comment_on_draft', $comment_post_ID);
42 exit;
c0bbf8c Block comments for future posts and password protected posts (when pa…
ryan authored
43 } elseif ( post_password_required($comment_post_ID) ) {
44 do_action('comment_on_password_protected', $comment_post_ID);
45 exit;
dc2fb99 Add 'pre_comment_on_post' action to allow early denial by spam plugin…
westi authored
46 } else {
47 do_action('pre_comment_on_post', $comment_post_ID);
a6f9511 Refuse comments for post IDs that do not exist.
rboren authored
48 }
0990789 Fix for cookie paths being set correctly when using a different home …
saxmatt authored
49
fe4c133 Notice fixes from Viper007Bond. see #7509
ryan authored
50 $comment_author = ( isset($_POST['author']) ) ? trim(strip_tags($_POST['author'])) : null;
51 $comment_author_email = ( isset($_POST['email']) ) ? trim($_POST['email']) : null;
52 $comment_author_url = ( isset($_POST['url']) ) ? trim($_POST['url']) : null;
53 $comment_content = ( isset($_POST['comment']) ) ? trim($_POST['comment']) : null;
65bbec7 Comments refactoring and cleanup
saxmatt authored
54
c4649b9 Comment registration goodness. Hat tip to Jason at noprequisite.com f…
saxmatt authored
55 // If the user is logged in
5322fc2 current user cleanup
ryan authored
56 $user = wp_get_current_user();
95df222 nonce-protect comments by users with unfiltered_html cap to prevent x…
markjaquith authored
57 if ( $user->ID ) {
93bc952 Handle blank display_name for commenters. props mrmist. fixes #7494
markjaquith authored
58 if ( empty( $user->display_name ) )
59 $user->display_name=$user->user_login;
5322fc2 current user cleanup
ryan authored
60 $comment_author = $wpdb->escape($user->display_name);
61 $comment_author_email = $wpdb->escape($user->user_email);
62 $comment_author_url = $wpdb->escape($user->user_url);
95df222 nonce-protect comments by users with unfiltered_html cap to prevent x…
markjaquith authored
63 if ( current_user_can('unfiltered_html') ) {
64 if ( wp_create_nonce('unfiltered-html-comment_' . $comment_post_ID) != $_POST['_wp_unfiltered_html_comment'] ) {
65 kses_remove_filters(); // start with a clean slate
66 kses_init_filters(); // set up the filters
67 }
68 }
69 } else {
31c4756 Register 'inherit' as a post status. Check the parent post status whe…
ryan authored
70 if ( get_option('comment_registration') || 'private' == $status )
550ede8 wp_die() for comment errors. Props filosofo. fixes #1786
ryan authored
71 wp_die( __('Sorry, you must be logged in to post a comment.') );
95df222 nonce-protect comments by users with unfiltered_html cap to prevent x…
markjaquith authored
72 }
65bbec7 Comments refactoring and cleanup
saxmatt authored
73
c4649b9 Comment registration goodness. Hat tip to Jason at noprequisite.com f…
saxmatt authored
74 $comment_type = '';
65bbec7 Comments refactoring and cleanup
saxmatt authored
75
849a0d2 Use get_option instead of get_settings. Just 'cause.
ryan authored
76 if ( get_option('require_name_email') && !$user->ID ) {
0cffb54 I count good now
matt authored
77 if ( 6 > strlen($comment_author_email) || '' == $comment_author )
550ede8 wp_die() for comment errors. Props filosofo. fixes #1786
ryan authored
78 wp_die( __('Error: please fill the required fields (name, email).') );
6ecc63b Validate comment author email. http://mosquito.wordpress.org/view.ph…
ryan authored
79 elseif ( !is_email($comment_author_email))
550ede8 wp_die() for comment errors. Props filosofo. fixes #1786
ryan authored
80 wp_die( __('Error: please enter a valid email address.') );
6ecc63b Validate comment author email. http://mosquito.wordpress.org/view.ph…
ryan authored
81 }
0990789 Fix for cookie paths being set correctly when using a different home …
saxmatt authored
82
7661787 http://mosquito.wordpress.org/view.php?id=558
saxmatt authored
83 if ( '' == $comment_content )
550ede8 wp_die() for comment errors. Props filosofo. fixes #1786
ryan authored
84 wp_die( __('Error: please type a comment.') );
8f10709 Check for comment status.
saxmatt authored
85
95fa29a Reply to comments from admin, first run, see #7435
azaozz authored
86 $comment_parent = isset($_POST['comment_parent']) ? absint($_POST['comment_parent']) : 0;
87
96c363a Accept either user_id or user_ID. Remove user_id global. see #11271 #…
ryan authored
88 $commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_content', 'comment_type', 'comment_parent', 'user_ID');
b43564c *** empty log message ***
saxmatt authored
89
3d21925 Ryan slays the dragon. (Some of these return WP_Error objects.)
matt authored
90 $comment_id = wp_new_comment( $commentdata );
88a6405 Email fixes, formatting changes.
saxmatt authored
91
672530a Strip all html from comment author name, email, and url.
ryan authored
92 $comment = get_comment($comment_id);
c671554 Update wp-comments-post.php to WP coding conventions. props JeremyVi…
markjaquith authored
93 if ( !$user->ID ) {
cf2499b Allow a plugin to vary the comment cookie lifetime (or even remove th…
westi authored
94 $comment_cookie_lifetime = apply_filters('comment_cookie_lifetime', 30000000);
95 setcookie('comment_author_' . COOKIEHASH, $comment->comment_author, time() + $comment_cookie_lifetime, COOKIEPATH, COOKIE_DOMAIN);
96 setcookie('comment_author_email_' . COOKIEHASH, $comment->comment_author_email, time() + $comment_cookie_lifetime, COOKIEPATH, COOKIE_DOMAIN);
3ebf837 Deprecate sanitize_url() and clean_url() in favor of esc_url_raw() an…
markjaquith authored
97 setcookie('comment_author_url_' . COOKIEHASH, esc_url($comment->comment_author_url), time() + $comment_cookie_lifetime, COOKIEPATH, COOKIE_DOMAIN);
c671554 Update wp-comments-post.php to WP coding conventions. props JeremyVi…
markjaquith authored
98 }
facb7af Fixed whitespace error, cleaned some formatting. Improved grammer on …
saxmatt authored
99
8c67165 Redirect back to correct comment page after replying. Props Viper007B…
ryan authored
100 $location = empty($_POST['redirect_to']) ? get_comment_link($comment_id) : $_POST['redirect_to'] . '#comment-' . $comment_id;
ac455f6 comment_post_redirect and comment_edit_redirect from Mark J. fixes #2590
ryan authored
101 $location = apply_filters('comment_post_redirect', $location, $comment);
c1f391a Better redirect cleaning.
saxmatt authored
102
ac455f6 comment_post_redirect and comment_edit_redirect from Mark J. fixes #2590
ryan authored
103 wp_redirect($location);
a717edc Always exit after wp_redirect. props filosofo, fixes #15518.
nacin authored
104 exit;
e6e0954 Minor phpdoc fixups.
westi authored
105 ?>
Something went wrong with that request. Please try again.