Ticket #4332: comment-validation2.diff
File comment-validation2.diff, 3.6 KB (added by , 16 years ago) |
---|
-
wp-comments-post.php
17 17 18 18 nocache_headers(); 19 19 20 function redirectBackToPost ($comment_post_ID, $errorCode) { 21 // Redirect to the post's comment section, but add the comment error message 22 wp_redirect (add_query_arg ("commentErrorCode", $errorCode, get_permalink ($comment_post_ID))); 23 die; 24 } 25 20 26 $comment_post_ID = (int) $_POST['comment_post_ID']; 21 27 22 28 $status = $wpdb->get_row( $wpdb->prepare("SELECT post_status, comment_status FROM $wpdb->posts WHERE ID = %d", $comment_post_ID) ); … … 26 32 exit; 27 33 } elseif ( !comments_open($comment_post_ID) ) { 28 34 do_action('comment_closed', $comment_post_ID); 29 wp_die( __('Sorry, comments are closed for this item.'));35 redirectBackToPost ($comment_post_ID, 4); 30 36 } elseif ( in_array($status->post_status, array('draft', 'pending') ) ) { 31 37 do_action('comment_on_draft', $comment_post_ID); 32 38 exit; … … 59 65 $comment_type = ''; 60 66 61 67 if ( get_option('require_name_email') && !$user->ID ) { 62 if ( 6 > strlen($comment_author_email)|| '' == $comment_author )63 wp_die( __('Error: please fill the required fields (name, email).'));68 if ( '' == $comment_author_email || '' == $comment_author ) 69 redirectBackToPost ($comment_post_ID, 3); 64 70 elseif ( !is_email($comment_author_email)) 65 wp_die( __('Error: please enter a valid email address.'));71 redirectBackToPost ($comment_post_ID, 2); 66 72 } 67 73 74 // Comment blank? 68 75 if ( '' == $comment_content ) 69 wp_die( __('Error: please type a comment.'));76 redirectBackToPost ($comment_post_ID, 1); 70 77 71 78 $comment_parent = isset($_POST['comment_parent']) ? absint($_POST['comment_parent']) : 0; 72 79 -
wp-includes/comment.php
1638 1638 return $open; 1639 1639 } 1640 1640 1641 /** 1642 * Echos error messages given when trying to post a comment. Hooked to comment_form 1643 * 1644 * @since 2.8 1645 */ 1646 function check_errors_on_comment_post () { 1647 /* Error codes are as follows: 1648 * 1 Comment was left blank 1649 * 2 Email address wasn't valid 1650 * 3 Name or email address weren't set 1651 * 4 Comments are closed 1652 */ 1653 1654 // Only bother with anything if there's an error code set 1655 if (isset ($_GET['commentErrorCode'])) { 1656 switch ($_GET['commentErrorCode']) { 1657 case 1: 1658 echo "<p id=\"commentError\">".__("Message can't be blank.")."</p>\n"; 1659 break; 1660 case 2: 1661 echo "<p id=\"commentError\">".__("Invalid email address.")."</p>\n"; 1662 break; 1663 case 3: 1664 echo "<p id=\"commentError\">".__("Name and email address are required fields.")."</p>\n"; 1665 break; 1666 case 4: 1667 echo "<p id=\"commentError\">".__("Sorry, comments are closed for this item.")."</p>\n"; 1668 break; 1669 default: 1670 // We should never get here, but just in case 1671 echo "<p id=\"commentError\">".__("Received unknown error value.")."</p>\n"; 1672 break; 1673 } 1674 } 1675 } 1676 1641 1677 ?> -
wp-includes/default-filters.php
123 123 124 124 add_filter('comment_excerpt', 'convert_chars'); 125 125 126 add_action ('comment_form', 'check_errors_on_comment_post', 11); 127 126 128 add_filter('list_cats', 'wptexturize'); 127 129 add_filter('single_post_title', 'wptexturize'); 128 130