From 06b0141f17f087de814a1d6017b49f3a74cc5614 Mon Sep 17 00:00:00 2001 From: Justin Foell <630830+jrfoell@users.noreply.github.com> Date: Fri, 26 Mar 2021 11:30:53 -0500 Subject: [PATCH] Rework ID filtering for maximum compatibility --- src/WPStrava/Settings.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/WPStrava/Settings.php b/src/WPStrava/Settings.php index 0035b5a..cd341c2 100644 --- a/src/WPStrava/Settings.php +++ b/src/WPStrava/Settings.php @@ -692,7 +692,9 @@ class WPStrava_Settings { public function save_info( $id, $secret, $info ) { $infos = get_option( 'strava_info' ); $infos = empty( $infos ) ? array() : $infos; - $infos = array_filter( $infos, array( $this, 'filter_by_id' ), ARRAY_FILTER_USE_KEY ); // Remove old IDs. + + array_walk( $infos, array( $this, 'filter_by_id' ) ); + $infos = array_filter( $infos ); $info->client_secret = $secret; $infos[ $id ] = $info; @@ -700,19 +702,19 @@ class WPStrava_Settings { } /** - * array_filter() callback to remove info for IDs we no longer have. + * array_walk() callback to clear IDs we no longer want. * * @param int $key Strava Client ID - * @return boolean True if Client ID is in $this->ids, false otherwise. * @author Justin Foell * @since 2.0.0 */ - public function filter_by_id( $key ) { + public function filter_by_id( &$value, $key ) { $ids = $this->get_ids(); if ( in_array( $key, $ids ) ) { // phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict -- Loose comparison OK. - return true; + return; } - return false; + + $value = null; } /**