'free', 'have' => $have, ), self::base() . 'lists/db' ); $response = wp_remote_get( $url, array( 'timeout' => 15, 'user-agent' => 'SafetyBis-Security/' . SAFETYBIS_SECURITY_VERSION, 'headers' => array( 'Accept' => 'application/json' ), ) ); if ( is_wp_error( $response ) ) { return self::save_status( 'error', $response->get_error_message() ); } $code = (int) wp_remote_retrieve_response_code( $response ); if ( 304 === $code ) { return self::save_status( 'current', '' ); } if ( 200 !== $code ) { /* translators: %d: HTTP status code. */ return self::save_status( 'error', sprintf( __( 'The server answered with HTTP %d.', 'safetybis-security' ), $code ) ); } $version = DetectionList::store( (string) wp_remote_retrieve_body( $response ) ); if ( $version ) { return self::save_status( 'updated', '' ); } if ( null === DetectionList::verify( (string) wp_remote_retrieve_body( $response ) ) ) { return self::save_status( 'error', __( 'The downloaded list failed the signature check and was not used.', 'safetybis-security' ) ); } return self::save_status( 'current', '' ); } /** * Last status. * * @return array */ public static function status() { $status = get_option( self::STATUS_OPTION ); return is_array( $status ) ? $status : array(); } /** * API base URL (filter for tests). * * @return string */ private static function base() { return trailingslashit( (string) apply_filters( 'safetybis_security_api_base', self::BASE ) ); } /** * Store and return the status. * * @param string $result Result. * @param string $message Message. * @return array */ private static function save_status( $result, $message ) { $status = array( 'time' => time(), 'result' => $result, 'message' => $message, 'version' => DetectionList::current()['version'], ); update_option( self::STATUS_OPTION, $status, false ); return $status; } }