Skip to content

Commit

Permalink
fix: issues from alpha.10 preventing valid comments
Browse files Browse the repository at this point in the history
  • Loading branch information
florianbrinkmann committed Dec 17, 2023
1 parent 645dde6 commit 490cbd3
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/Handlers/Comment.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function () {
}

public static function process( $comment ) {
if ( ! ContentTypeHelper::reaction_is_one_of( $comment, [ ContentTypeHelper::COMMENT_TYPE ], 'comment' ) ) {
if ( ! ContentTypeHelper::reaction_is_one_of( $comment, [ 'comment', '' ], 'comment' ) ) {
return $comment;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Handlers/Linkback.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Linkback extends Reaction {
protected static $type = 'linkback';

public static function process( $linkback ) {
if ( ! ContentTypeHelper::reaction_is_one_of( $linkback, [ ContentTypeHelper::LINKBACK_TYPE ], 'linkback' ) ) {
if ( ! ContentTypeHelper::reaction_is_one_of( $linkback, [ 'pingback', 'trackback', 'pings' ], 'linkback' ) ) {
return $linkback;
}

Expand Down
3 changes: 2 additions & 1 deletion src/Helpers/ContentTypeHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ public static function get_type_name( $item_type ) {
* @return bool
*/
public static function reaction_is_one_of( $reaction, $reaction_types, $context = '' ) {
$reaction_type = $reaction['reaction_type'] ?? '';
// This `comment_type` is set from WordPress.
$reaction_type = $reaction['comment_type'] ?? '';

$is_one_of = in_array( $reaction_type, $reaction_types );

Expand Down
5 changes: 3 additions & 2 deletions src/Rules/DbSpam.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@ class DbSpam extends ControllableBase implements SpamReason {
public static function verify( $item ) {
$params = [];
$filter = [];
$url = DataHelper::get_values_where_key_contains( [ 'url' ], $item );
$url = wp_unslash( array_shift( DataHelper::get_values_where_key_contains( [ 'url' ], $item ) ) );

if ( ! empty( $url ) ) {
$filter[] = '`comment_author_url` = %s';
$params[] = wp_unslash( array_shift( $url ) );
$params[] = $url;
}

$ip = DataHelper::get_values_by_keys( [ 'comment_author_IP' ], $item );

if ( ! empty( $ip ) ) {
Expand Down
2 changes: 1 addition & 1 deletion src/Rules/EmptyData.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public static function verify( $item ) {
}

if ( $item[ 'reaction_type'] === ContentTypeHelper::COMMENT_TYPE ) {
if ( get_option( 'require_name_email' ) && ( empty( $comment['comment_author_email'] ) || empty( $comment['comment_author'] ) ) ) {
if ( get_option( 'require_name_email' ) && ( empty( $item['comment_author_email'] ) || empty( $item['comment_author'] ) ) ) {
return 999;
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/Rules/Honeypot.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ public static function precheck() {
}
$fields = [];
foreach ( $_POST as $key => $value ) {
if ( $key === HoneypotField::get_secret_name_for_post() ) {
$fields['plugin_field'] = $key;
}
if ( isset( $fields['plugin_field'] ) ) {
$fields['hidden_field'] = $key;
break;
}
if ( $key === HoneypotField::get_secret_name_for_post() ) {
$fields['plugin_field'] = $key;
}
}

if ( ! isset( $fields['plugin_field'] ) ) {
Expand Down

0 comments on commit 490cbd3

Please sign in to comment.