'Startup', 'query' => $query ), '', '&' ) ); if ( is_wp_error( $response ) ) return new WP_Error( 500, 'AngelList API fail.' ); $response_body = wp_remote_retrieve_body( $response ); if ( empty( $response_body ) ) return new WP_Error( 404, 'No matching companies found.' ); $results = json_decode( $response_body, true ); unset( $response_body ); if ( empty( $results ) ) return new WP_Error( 404, 'No matching companies found.' ); $companies = array(); $num_companies = 0; foreach ( $results as $result ) { if ( $num_companies === $limit ) break; if ( ! array_key_exists( 'id', $result ) || ! is_int( $result['id'] ) || ! array_key_exists( 'name', $result ) || ! is_string( $result['name'] ) || ! trim( $result['name'] ) ) continue; $companies[] = array( 'id' => absint( $result['id'] ), 'name' => trim( $result['name'] ) ); $num_companies++; } if ( empty( $companies ) ) return new WP_Error( 404, 'No matching companies found.' ); return $companies; } } ?>