johndigital / funkstagram

A simple Instagram image importer for Wordpress
GNU General Public License v2.0
1 stars 0 forks source link

Make username to ID conversion more robust #2

Closed drewbaker closed 8 years ago

drewbaker commented 8 years ago

Today we re-wrote the username to ID conversion to be case insensitive and work if the search result order came back not what we expected.

https://github.com/jrobson153/funkstagram/blob/master/funkstagram-class.php#L40-L52

                        // Decode JSON response
                        $response = json_decode( wp_remote_retrieve_body( $serach_user ), true );

                        // Go through serach results and find matching username
                        $found_id = false;
                        foreach($response['data'] as $key => $found_user) {
                            if(strtolower($found_user['username']) == strtolower($user)) {
                                $found_id = $response['data'][$key]['id'];
                                break;
                            }
                        }

                        // If username matches, switch username to be id instead
                        if ( $found_id ) {
                            $user_ids[$i] = $found_id;

                        // Otherwise remove from array and log
                        } else {
                            unset( $user_ids[$i] );
                            $this->error_log[] = 'User ' . $user . ' does not exist';
                        }