Yes it is valid all the times under the consideration of acceleration due to gravity .it is not valid on space where there is no influence of gravity
Photon energy is directly proportional to the frequency of electromagnetic radiation.
(That would also mean that it's inversely proportional to the wavelength.)
So the photon energy increases as you scan the chart of visible colors
moving from the red end of the rainbow to the blue end.