Ticket #4332: comment-validation.diff
File comment-validation.diff, 4.5 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 // Work out the link we're redirecting back to 22 $postURL = get_permalink ($comment_post_ID); 23 if (strstr ($postURL, '?') !== false) $postURL .= "&"; else $postURL .= "?"; 24 $postURL .= "commentErrorCode=".$errorCode; 25 // Redirect to the post's comment section, but add the comment error message 26 header ("Location: ".$postURL); 27 die; 28 } 29 20 30 $comment_post_ID = (int) $_POST['comment_post_ID']; 21 31 22 32 $status = $wpdb->get_row( $wpdb->prepare("SELECT post_status, comment_status FROM $wpdb->posts WHERE ID = %d", $comment_post_ID) ); … … 26 36 exit; 27 37 } elseif ( !comments_open($comment_post_ID) ) { 28 38 do_action('comment_closed', $comment_post_ID); 29 wp_die( __('Sorry, comments are closed for this item.'));39 redirectBackToPost ($comment_post_ID, 4); 30 40 } elseif ( in_array($status->post_status, array('draft', 'pending') ) ) { 31 41 do_action('comment_on_draft', $comment_post_ID); 32 42 exit; … … 59 69 $comment_type = ''; 60 70 61 71 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).'));72 if ( '' == $comment_author_email || '' == $comment_author ) 73 redirectBackToPost ($comment_post_ID, 3); 64 74 elseif ( !is_email($comment_author_email)) 65 wp_die( __('Error: please enter a valid email address.'));75 redirectBackToPost ($comment_post_ID, 2); 66 76 } 67 77 78 // Comment blank? 68 79 if ( '' == $comment_content ) 69 wp_die( __('Error: please type a comment.'));80 redirectBackToPost ($comment_post_ID, 1); 70 81 71 82 $comment_parent = isset($_POST['comment_parent']) ? absint($_POST['comment_parent']) : 0; 72 83 -
wp-content/themes/default/comments.php
66 66 67 67 <p>Logged in as <a href="<?php echo get_option('siteurl'); ?>/wp-admin/profile.php"><?php echo $user_identity; ?></a>. <a href="<?php echo wp_logout_url(get_permalink()); ?>" title="Log out of this account">Log out »</a></p> 68 68 69 <?php else : ?>69 <?php else : 70 70 71 do_action ('comment_form_errors'); ?> 72 71 73 <p><input type="text" name="author" id="author" value="<?php echo $comment_author; ?>" size="22" tabindex="1" <?php if ($req) echo "aria-required='true'"; ?> /> 72 74 <label for="author"><small>Name <?php if ($req) echo "(required)"; ?></small></label></p> 73 75 -
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.7.1 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\">Something went wrong. No idea what.</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_errors', 'check_errors_on_comment_post'); 127 126 128 add_filter('list_cats', 'wptexturize'); 127 129 add_filter('single_post_title', 'wptexturize'); 128 130