diff --git a/readme.txt b/readme.txt index 2683bee..70ce305 100755 --- a/readme.txt +++ b/readme.txt @@ -4,7 +4,7 @@ Contributors: cmanon, jrfoell, lancewillett, dlintott, sebastianerb Tags: strava, activity, bicycle, cycling, biking, running, run, swimming, swim, paddle, kayak, gps, shortcode, widget, plugin, block, blocks Requires at least: 4.6 Tested up to: 5.8 -Stable tag: 2.10.0 +Stable tag: 2.10.1 Requires PHP: 5.3 License: GPLv2 or later @@ -134,6 +134,10 @@ On the WP-Strava settings page you cannot currently remove and add another athle == Changelog == += 2.10.1 = +Reworked settings save with multiple athletes, related to https://wordpress.org/support/topic/wp-strava-error-401-unauthorized/ + + = 2.10.0 = Add ability to paste Activity/Route/Segment URL into the block editor and have it insert the appropriate block https://wordpress.org/support/topic/sorry-this-content-could-not-be-embedded-5/ Add `reduce_polyline()` for maps with large polylines but no summary provided (prevents empty map) https://wordpress.org/support/topic/map-embed-from-segment-shows-default-map/ diff --git a/src/WPStrava/Settings.php b/src/WPStrava/Settings.php index 442a784..aaa50b2 100644 --- a/src/WPStrava/Settings.php +++ b/src/WPStrava/Settings.php @@ -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 * @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 + * @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; } diff --git a/wp-strava.php b/wp-strava.php index 0aaf314..c732c04 100755 --- a/wp-strava.php +++ b/wp-strava.php @@ -3,7 +3,7 @@ * Plugin Name: WP Strava * Plugin URI: https://wordpress.org/plugins/wp-strava/ * Description: Show your strava.com activity on your WordPress site. Some Icons are Copyright © Yusuke Kamiyamane. All rights reserved. Licensed under a Creative Commons Attribution 3.0 license. - * Version: 2.10.0 + * Version: 2.10.1 * Author: Carlos Santa Cruz, Justin Foell, Lance Willett, Daniel Lintott, Sebastian Erb * License: GPL2 * Text Domain: wp-strava @@ -27,7 +27,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -define( 'WPSTRAVA_PLUGIN_VERSION', '2.10.0' ); +define( 'WPSTRAVA_PLUGIN_VERSION', '2.10.1' ); define( 'WPSTRAVA_PLUGIN_FILE', __FILE__ ); define( 'WPSTRAVA_PLUGIN_DIR', trailingslashit( dirname( __FILE__ ) ) ); define( 'WPSTRAVA_PLUGIN_URL', plugins_url( '/', __FILE__ ) );