mirror of
https://github.com/10h30/wp-strava.git
synced 2026-07-11 18:56:18 +09:00
Rework ID filtering for maximum compatibility
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user