Use of strings for pinMode argument

The only safe way that I can think of is to create an array of them and then index it:
(untested)

byte ESPdatapins[] = {D2, D3, D4, D5, D6, D7};
...
  for (byte thisPin = 0; thisPin < sizeof(ESPdatapins[]); thisPin++) {
    pinMode(ESPdatapins[thisPin], OUTPUT);
  }

The names D2...D7 are not strings, they are preprocessor macro identifiers. They disappear in the process of compilation.