10, 'redirection' => 0, 'headers' => array( 'Content-Type' => 'application/json' ), 'body' => '{}', 'user-agent' => ThirdDraft_Connection::user_agent(), ) ); if ( is_wp_error( $answer ) ) { return __( 'This site didn’t answer at the address ThirdDraft sends articles to. Ask your host to check that the site can be reached over HTTPS.', 'thirddraft' ); } $status = (int) wp_remote_retrieve_response_code( $answer ); $body = json_decode( (string) wp_remote_retrieve_body( $answer ), true ); $code = is_array( $body ) && isset( $body['code'] ) ? (string) $body['code'] : ''; if ( 0 === strpos( $code, 'thirddraft_' ) ) { return ''; } if ( 404 === $status ) { /* translators: %s: the address articles are sent to. */ return sprintf( __( 'Nothing answers at %s. Save Settings → Permalinks once, or ask your host why the address is missing.', 'thirddraft' ), $url ); } if ( $status >= 300 && $status < 400 ) { /* translators: %s: the address articles are sent to. */ return sprintf( __( '%s redirects elsewhere, and ThirdDraft doesn’t follow redirects. Make it answer at this address.', 'thirddraft' ), $url ); } /* translators: %s: the address articles are sent to. */ return sprintf( __( 'Something on this site is blocking ThirdDraft. Allow requests to %s in your security plugin or firewall.', 'thirddraft' ), $url ); } /** * Reaches ThirdDraft. * * @return string '' when it can. */ private static function outbound() { $answer = wp_remote_get( ThirdDraft_Connection::app_url( '/up' ), array( 'timeout' => 10, 'redirection' => 0, 'user-agent' => ThirdDraft_Connection::user_agent(), ) ); if ( ! is_wp_error( $answer ) && (int) wp_remote_retrieve_response_code( $answer ) > 0 ) { return ''; } /* translators: %s: ThirdDraft's host. */ return sprintf( __( 'This site can’t reach ThirdDraft. Ask your host to allow outgoing connections to %s.', 'thirddraft' ), ThirdDraft_Connection::app_host() ); } }