Rework ID filtering for maximum compatibility

This commit is contained in:
Justin Foell
2021-03-26 11:30:53 -05:00
parent 280a9dfe26
commit 06b0141f17
+8 -6
View File
@@ -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 <justin@foell.org>
* @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;
}
/**