-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #114 from cmanon/feature/109-error-unauthorized
Feature/109 error unauthorized
- Loading branch information
Showing
3 changed files
with
57 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -333,8 +333,8 @@ public function sanitize_nickname( $nicknames ) { | |
} | ||
} | ||
|
||
// Process $nicknames so indexes start with zero. | ||
$nicknames = array_merge( $nicknames, array() ); | ||
// Rebase array keys after unset. | ||
$nicknames = array_values( $nicknames ); | ||
} | ||
|
||
foreach ( $nicknames as $index => $nickname ) { | ||
|
@@ -351,13 +351,54 @@ public function sanitize_nickname( $nicknames ) { | |
* | ||
* Renamed from sanitize_token(). | ||
* | ||
* @param string $id Client ID. | ||
* @return string | ||
* @param array $ids Client IDs. | ||
* @return array | ||
* @author Justin Foell <[email protected]> | ||
* @since 2.0 | ||
*/ | ||
public function sanitize_id( $id ) { | ||
return $id; | ||
public function sanitize_id( $ids ) { | ||
$this->get_ids(); | ||
|
||
if ( ! is_array( $ids ) ) { | ||
$ids = array( $ids ); | ||
} | ||
|
||
// Filter empty IDs. | ||
$ids = array_filter( $ids ); | ||
|
||
// Rebase array keys after unset. | ||
$ids = array_values( $ids ); | ||
|
||
$this->maybe_clean_info( $ids ); | ||
|
||
$this->ids = $ids; | ||
|
||
return $ids; | ||
} | ||
|
||
/** | ||
* Remove IDs from strava_info that are being deleted. | ||
* | ||
* @param array $ids IDs that we're keeping. | ||
* @author Justin Foell <[email protected]> | ||
* @since 2.10.1 | ||
*/ | ||
private function maybe_clean_info( $ids ) { | ||
$update = false; | ||
|
||
$infos = $this->info; | ||
|
||
foreach ( $infos as $id => $info ) { | ||
if ( ! in_array( $id, $ids ) ) { | ||
$update = true; | ||
unset( $infos[ $id ] ); | ||
} | ||
} | ||
|
||
if ( $update ) { | ||
update_option( 'strava_info', $infos ); | ||
} | ||
|
||
} | ||
|
||
/** | ||
|
@@ -584,10 +625,11 @@ public function get_ids() { | |
foreach ( $ids as $index => $id ) { | ||
if ( empty( $id ) ) { | ||
unset( $ids[ $index ] ); | ||
$ids = array_values( $ids ); // Rebase array keys after unset @see https://stackoverflow.com/a/5943165/2146022 | ||
} | ||
} | ||
$this->ids = $ids; | ||
|
||
// Rebase array keys after unset @see https://stackoverflow.com/a/5943165/2146022 | ||
$this->ids = array_values( $ids ); | ||
return $this->ids; | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters