route( '/admin/import', array( array( 'methods' => WP_REST_Server::READABLE, 'callback' => static fn() => Importers::describe(), 'permission' => array( $this, 'can_settings' ), ), ) ); $this->route( '/admin/import/(?P[a-z0-9-]+)', array( array( 'methods' => WP_REST_Server::CREATABLE, 'callback' => array( $this, 'import' ), 'permission' => array( $this, 'can_settings' ), ), ) ); } /** * Import. * * @param WP_REST_Request $request Request. * @return array * @throws InvalidArgumentException When unknown. */ public function import( WP_REST_Request $request ): array { $importer = Importers::find( (string) $request['importer'] ); if ( null === $importer ) { throw new InvalidArgumentException( 'Unknown importer.' ); } return $importer->run( ! empty( self::body( $request )['dry_run'] ) ); } }