wp_api = &$wp_api; $this->http = &$http; $this->url = $url; if ( $this->validate_url_string() === false ) { throw new InvalidArgumentException( 'Invalid URL :' . $this->url ); } $this->language_code = $language_code; } /** * Makes a http request to the url this points at and checks if the requests * returns the correct validation result. * * @return bool */ public function is_valid() { $url_glue = false === strpos( $this->url, '?' ) ? '?' : '&'; $url = trailingslashit( $this->url ) . ( $this->language_code ? '/' . $this->language_code . '/' : '' ) . $url_glue . '____icl_validate_domain=1'; $response = $this->http->request( $url, 'timeout=15' ); return ! is_wp_error( $response ) && ( $response['response']['code'] == '200' ) && ( ( $response['body'] === '' ) || $response['body'] === '' ); } /** * Checks that the input url is valid in so far that it contains schema * and host at least. * * @return bool */ private function validate_url_string() { $url_parts = parse_url( $this->url ); return isset( $url_parts['scheme'] ) && isset( $url_parts['host'] ); } }