Skip to content

Commit

Permalink
remove comment black listing based on words #81
Browse files Browse the repository at this point in the history
  • Loading branch information
markkap committed Oct 25, 2018
1 parent 1d670c8 commit a80af7b
Show file tree
Hide file tree
Showing 5 changed files with 1 addition and 86 deletions.
3 changes: 1 addition & 2 deletions src/wp-admin/includes/schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,6 @@ function populate_options() {
'template' => $template,
'stylesheet' => $stylesheet,
'comment_whitelist' => 1,
'blacklist_keys' => '',
'comment_registration' => 0,
'html_type' => 'text/html',

Expand Down Expand Up @@ -498,7 +497,7 @@ function populate_options() {
}

// Set autoload to no for these options
$fat_options = array( 'moderation_keys', 'recently_edited', 'blacklist_keys', 'uninstall_plugins' );
$fat_options = array( 'moderation_keys', 'recently_edited', 'uninstall_plugins' );

$keys = "'" . implode( "', '", array_keys( $options ) ) . "'";
$existing_options = $wpdb->get_col( "SELECT option_name FROM $wpdb->options WHERE option_name in ( $keys )" );
Expand Down
9 changes: 0 additions & 9 deletions src/wp-admin/options-discussion.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,15 +156,6 @@
</p>
</fieldset></td>
</tr>
<tr>
<th scope="row"><?php _e('Comment Blacklist'); ?></th>
<td><fieldset><legend class="screen-reader-text"><span><?php _e('Comment Blacklist'); ?></span></legend>
<p><label for="blacklist_keys"><?php _e('When a comment contains any of these words in its content, name, URL, email, or IP address, it will be put in the trash. One word or IP address per line. It will match inside words, so &#8220;press&#8221; will match &#8220;calmPress&#8221;.'); ?></label></p>
<p>
<textarea name="blacklist_keys" rows="10" cols="50" id="blacklist_keys" class="large-text code"><?php echo esc_textarea( get_option( 'blacklist_keys' ) ); ?></textarea>
</p>
</fieldset></td>
</tr>
<?php do_settings_fields('discussion', 'default'); ?>
</table>

Expand Down
1 change: 0 additions & 1 deletion src/wp-admin/options.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@
'comment_whitelist',
'comment_max_links',
'moderation_keys',
'blacklist_keys',
'show_avatars',
'avatar_rating',
'avatar_default',
Expand Down
73 changes: 0 additions & 73 deletions src/wp-includes/comment.php
Original file line number Diff line number Diff line change
Expand Up @@ -764,17 +764,6 @@ function wp_allow_comment( $commentdata, $avoid_die = false ) {
} else {
$approved = 0;
}

if ( wp_blacklist_check(
$commentdata['comment_author'],
$commentdata['comment_author_email'],
$commentdata['comment_author_url'],
$commentdata['comment_content'],
$commentdata['comment_author_IP'],
$commentdata['comment_agent']
) ) {
$approved = EMPTY_TRASH_DAYS ? 'trash' : 'spam';
}
}

/**
Expand Down Expand Up @@ -1170,68 +1159,6 @@ function wp_check_comment_data_max_lengths( $comment_data ) {
return true;
}

/**
* Does comment contain blacklisted characters or words.
*
* @since 1.5.0
*
* @param string $author The author of the comment
* @param string $email The email of the comment
* @param string $url The url used in the comment
* @param string $comment The comment content
* @param string $user_ip The comment author's IP address
* @param string $user_agent The author's browser user agent
* @return bool True if comment contains blacklisted content, false if comment does not
*/
function wp_blacklist_check($author, $email, $url, $comment, $user_ip, $user_agent) {
/**
* Fires before the comment is tested for blacklisted characters or words.
*
* @since 1.5.0
*
* @param string $author Comment author.
* @param string $email Comment author's email.
* @param string $url Comment author's URL.
* @param string $comment Comment content.
* @param string $user_ip Comment author's IP address.
* @param string $user_agent Comment author's browser user agent.
*/
do_action( 'wp_blacklist_check', $author, $email, $url, $comment, $user_ip, $user_agent );

$mod_keys = trim( get_option('blacklist_keys') );
if ( '' == $mod_keys )
return false; // If moderation keys are empty

// Ensure HTML tags are not being used to bypass the blacklist.
$comment_without_html = wp_strip_all_tags( $comment );

$words = explode("\n", $mod_keys );

foreach ( (array) $words as $word ) {
$word = trim($word);

// Skip empty lines
if ( empty($word) ) { continue; }

// Do some escaping magic so that '#' chars in the
// spam words don't break things:
$word = preg_quote($word, '#');

$pattern = "#$word#i";
if (
preg_match($pattern, $author)
|| preg_match($pattern, $email)
|| preg_match($pattern, $url)
|| preg_match($pattern, $comment)
|| preg_match($pattern, $comment_without_html)
|| preg_match($pattern, $user_ip)
|| preg_match($pattern, $user_agent)
)
return true;
}
return false;
}

/**
* Retrieve total comments for blog or single post.
*
Expand Down
1 change: 0 additions & 1 deletion src/wp-includes/formatting.php
Original file line number Diff line number Diff line change
Expand Up @@ -4151,7 +4151,6 @@ function sanitize_option( $option, $value ) {
break;

case 'moderation_keys':
case 'blacklist_keys':
$value = $wpdb->strip_invalid_text_for_column( $wpdb->options, 'option_value', $value );
if ( is_wp_error( $value ) ) {
$error = $value->get_error_message();
Expand Down

0 comments on commit a80af7b

Please sign in to comment.