route( '/health', array( 'methods' => \WP_REST_Server::READABLE, 'callback' => array( $this, 'get_health' ), ) ); $this->route( '/health/scan', array( 'methods' => \WP_REST_Server::CREATABLE, 'callback' => array( $this, 'scan' ), ) ); } /** * Handles GET /health. * * @return \WP_REST_Response */ public function get_health() { return $this->respond( $this->present( Scanner::result() ) ); } /** * Handles POST /health/scan. * * @return \WP_REST_Response */ public function scan() { return $this->respond( $this->present( Scanner::start() ) ); } /** * Adds display names and the statuses each check covers. * * @param array $result Scan result. * @return array */ private function present( array $result ) { $result['statuses'] = Scanner::CHECKS; if ( isset( $result['checks']['gateway_missing']['gateways'] ) ) { $names = array(); foreach ( $result['checks']['gateway_missing']['gateways'] as $id => $count ) { $names[] = array( 'id' => (string) $id, 'name' => Gateways::name( (string) $id ), 'count' => (int) $count, ); } $result['checks']['gateway_missing']['gateways'] = $names; } return $result; } }