Skip to content

Commit

Permalink
Support "disallowed_keys" instead of "blacklist" for WP 5.5 compat (#174
Browse files Browse the repository at this point in the history
)

The "comment blacklist" has been renamed to "disallowed comment keys"
along with the corresponding option key. We now support the new option,
if available. Also the frontend wording is adapted to match the new
labels.
  • Loading branch information
stklcode authored Aug 1, 2020
1 parent 3ed44d8 commit ff40f5b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 14 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ All notable changes to this project will be documented in this file. This projec
## unreleased
* Fix date offset in dashboard widget in WP 5.3+ environments with mixed timezones (#167)
* Allow to deactivate the nonce check during JavaScript tracking (#168)
* Add support for "disallowed_keys" option instead of "blacklist_keys" in WordPress 5.5 (#174)

## 1.7.2
* Prevent JavaScript tracking from raising 400 for logged-in users, if tracking is disabled (#159)
Expand Down
29 changes: 18 additions & 11 deletions inc/class-statify-frontend.php
Original file line number Diff line number Diff line change
Expand Up @@ -258,17 +258,17 @@ private static function _is_internal() {
}

/**
* Compare the referrer url to the blacklist data.
* Compare the referrer URL to the disallowed keys list.
* De/activate this feature via settings in the Dashboard widget.
*
* @since 1.5.0
* @version 1.6.3
*
* @return boolean TRUE of referrer matches blacklist entry and should thus be excluded.
* @return boolean TRUE of referrer matches disallowed keys entry and should thus be excluded.
*/
private static function check_referrer() {

// Return false if the blacklist filter is inactive.
// Return false if the disallowed-keys filter (formerly blacklist) is inactive.
if ( ! self::$_options['blacklist'] ) {
return false;
}
Expand All @@ -291,9 +291,9 @@ private static function check_referrer() {
return false;
}

// Finally compare referrer against the blacklist.
$blacklist = self::get_blacklist_keys();
foreach ( $blacklist as $item ) {
// Finally compare referrer against the disallowed keys.
$disallowed_keys = self::get_disallowed_keys();
foreach ( $disallowed_keys as $item ) {
if ( strpos( $referrer, $item ) !== false ) {
return true;
}
Expand All @@ -303,21 +303,28 @@ private static function check_referrer() {
}

/**
* Get a array from the blacklist option of 'Settings' - 'Discussion' - 'Comment Blacklist'.
* Get a array from the disallowed_keys option of 'Settings' - 'Discussion' - 'Disallowed Comment Keys'.
*
* @since 2016-12-21
* @since 1.7.3 Renamed to "get_disallowed_keys" to match WP 5.5. wording.
*
* @return array
*/
private static function get_blacklist_keys() {
private static function get_disallowed_keys() {
$disallowed_keys = get_option( 'disallowed_keys' );

$blacklist = trim( get_option( 'blacklist_keys' ) );
if ( false === $disallowed_keys ) {
// WordPress < 5.5 uses the old key.
$disallowed_keys = get_option( 'blacklist_keys' );
}

$disallowed_keys = trim( $disallowed_keys );

if ( empty( $blacklist ) ) {
if ( empty( $disallowed_keys ) ) {
return array();
}

return (array) explode( "\n", $blacklist );
return (array) explode( "\n", $disallowed_keys );
}

/**
Expand Down
6 changes: 3 additions & 3 deletions inc/class-statify-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public static function register_settings() {
);
add_settings_field(
'statify-skip-referrer',
__( 'Blacklisted referrers', 'statify' ),
__( 'Disallowed referrers', 'statify' ),
array( __CLASS__, 'options_skip_blacklist' ),
'statify',
'statify-skip',
Expand Down Expand Up @@ -240,15 +240,15 @@ public static function header_skip() {
}

/**
* Option to skip tracking for blacklisted referrers.
* Option to skip tracking for disallowed referrers.
*
* @return void
*/
public static function options_skip_blacklist() {
?>
<input id="statify-skip-referrer" type="checkbox" name="statify[blacklist]" value="1"<?php checked( Statify::$_options['blacklist'] ); ?>>
(<?php esc_html_e( 'Default', 'statify' ); ?>: <?php esc_html_e( 'No', 'statify' ); ?>)
<p class="description"><?php esc_html_e( 'Enabling this option excludes any views with referrers listed in the comment blacklist.', 'statify' ); ?></p>
<p class="description"><?php esc_html_e( 'Enabling this option excludes any views with referrers listed in the list of disallowed comment keys.', 'statify' ); ?></p>
<?php
}

Expand Down

0 comments on commit ff40f5b

Please sign in to comment.