[I answered another question which was subsequently marked a duplicate on this one. So I am replicating my answer here]
There are two issues here. One is whether our bathrooms have the status of the beit hakisei of the traditional halacha, the second whether we can say a bracha close to a beit hakisei.
Whether our bathroom have the status of a beit hakisei is a machloket poskim. R Yirmiyohu Kaganoff for instance writes
The latter-day poskim dispute whether our bathrooms have the halachic
status of the beis hakisei of the days of Chazal. Some poskim are
lenient since our bathrooms are much cleaner than old-time outhouses
(Shu’t Zakan Aharon 1:1; Shu’t Minchas Yitzchok 1:60).
Others contend
that our bathrooms should still be treated as a beis hakisei (Shu’t
Yechaveh Daas 3:1). Both the Chazon Ish (Orach Chayim 17:4) and Rav
Moshe Feinstein (Shu’t Igros Moshe, Even HaEzer 1:114) rule that we
should treat our bathrooms as a safek (questionable) beis hakisei.
The universal practice is to not recite brachos in the bathroom, but some
people are lenient to wash their hands there. Rav Moshe rules that one
may not wash for bread in our bathrooms, but one may wash his hands
there before davening, although one should dry one’s hands outside the
bathroom.
From this R Kaganoff concludes that one should not recite a bracha [...] facing the bathroom when its door is ajar. However, if we assume that it is only questionable, then one may have grounds to be lenient.
R Moshe Feinstein does indeed provide such a leniency. He writes (Even Haezer 1:114) that since the walls of our bathrooms are also an integral part of the house, we can ascribe the same status to the door doorframe as to the walls and consider them to be part of the structure of the house and not part of the bathroom. Therefore he rules that [...] one may recite a bracha opposite and outside a bathroom even when the door is open (even if tzo'ah is present in the bathroom as it is considered as in a different domain). R Tzvi Pesach Frank reaches a similar conclusion (Har Tzvi OC 1:48). R Moshe Feinstein further discusses how synagogues should be built to avoid the issue.
(sourced from R Ari Zivotofsky extensive study on the halachot of modern plumbing)
In all cases you must be four amot from the source of foul odors and not see tzo'ah (see here and here).