Skip to content

Commit

Permalink
Fix empty data error (#529)
Browse files Browse the repository at this point in the history
* Fix empty data error

Usage of the core filter pre_comment_user_ip does trigger our empty data check for the ip address if the IP is removed intentionallly for GDPR compliance. Switching to own filter.

* Fix test

* Fix inline doc
  • Loading branch information
Zodiac1978 authored Sep 20, 2023
1 parent 6f761db commit 2bf2a59
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
5 changes: 3 additions & 2 deletions antispam_bee.php
Original file line number Diff line number Diff line change
Expand Up @@ -2450,14 +2450,15 @@ private static function _go_in_peace() {
*
* @since 2.6.1
* @since 2.11.4 Only use `REMOTE_ADDR` to get the IP, make it filterable with `pre_comment_user_ip`
* @since 2.11.5 Switch to own filter `antispam_bee_trusted_ip`
*
* @hook string pre_comment_user_ip The Client IP
*
* @return string $ip Client IP
*/
public static function get_client_ip() {
/**
* WordPress hook for allowing to modify the client IP used by Antispam Bee. Default value is the `REMOTE_ADDR`.
* Hook for allowing to modify the client IP used by Antispam Bee. Default value is the `REMOTE_ADDR`.
*
* @link https://developer.wordpress.org/reference/hooks/pre_comment_user_ip/
*
Expand All @@ -2466,7 +2467,7 @@ public static function get_client_ip() {
// phpcs:disable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound
// phpcs:disable WordPress.Security.ValidatedSanitizedInput.InputNotValidated
// phpcs:disable WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
return self::_sanitize_ip( (string) apply_filters( 'pre_comment_user_ip', wp_unslash( $_SERVER['REMOTE_ADDR'] ) ) );
return self::_sanitize_ip( (string) apply_filters( 'antispam_bee_trusted_ip', wp_unslash( $_SERVER['REMOTE_ADDR'] ) ) );
// phpcs:enable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound
// phpcs:enable WordPress.Security.ValidatedSanitizedInput.InputNotValidated
// phpcs:enable WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/AntispamBeeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public function test_gets_ip_address() {
$result = Testee::handle_incoming_request( $comment );
$this->assertSame( '192.0.2.1', $result['comment_author_IP'], 'Unexpected IP with default detection' );

Filters::expectApplied( 'pre_comment_user_ip' )
Filters::expectApplied( 'antispam_bee_trusted_ip' )
->once()
->with( '192.0.2.1' )
->andReturn( '192.0.2.2' );
Expand Down

0 comments on commit 2bf2a59

Please sign in to comment.