Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support "disallowed_keys" instead of "blacklist" for WP 5.5 compat #174

Merged
merged 2 commits into from
Aug 1, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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