White House staff secretary Rob Porter on the White House complex in January 2017. (Michael Reynolds/European Pressphoto Agency)

White House spokesman Raj Shah on Thursday declined to specify when senior officials first became aware of allegations that staff secretary Rob Porter had physically and emotionally abused his two ex-wives but acknowledged the White House had could have better handled the episode.

Shah said that President Trump only learned of the allegations from media reports on Tuesday night and that White House chief of staff John F. Kelly did not become“fully aware” of the alleged abuse until Wednesday. Pressed during a White House briefing on what he meant by “fully aware,” Shah offered limited elaboration, saying Kelly did not see photographs showing the black eye of one of Porter’s ex-wives until Wednesday.

As he was peppered with questions, Shah did not rule out the possibility Kelly and other senior White House officials knew about the allegations — which Porter has denied — long before they surfaced in the media. The Washington Post has reported White House aides had been aware generally of accusations against Porter since late last year and that Kelly urged Porter to stay even after the photographs surfaced.

Shah said Porter, whose job included presenting Trump with classified documents, was serving in the White House with a temporary security clearance while law enforcement officials continued to conduct a comprehensive background check. Both of Porter’s ex-wives have said they detailed their allegations to FBI agents in January as part of the security clearance review.

Because the review was still ongoing, Shah said there had been no determination one way or another whether Porter qualified for a permanent security clearance.

“There was not a thumbs up or thumbs down,” Shah said. “The process hadn’t been completed.”

Shah said that Trump did not know of the status of Porter’s security clearance. Upon learning of the allegations, the president was “saddened for all the individuals involved,” Shah said.

Shah said statements supportive of Porter crafted by White House officials on Tuesday night when approached by a reporter from DailyMail.com “reflected the Rob Porter we’ve come to know.”

After defending Porter on Tuesday night, Kelly issued a statement Wednesday saying he was “shocked” by Porter’s alleged abuses while still expressing personal support for his close aide.

Shah would not say what, beyond the images of one accuser's black eye in news reports about the case, had changed between Kelly's first statement and the second.

“It’s fair to say we could all have done better over the past few days dealing with this situation,” Shah said.

Shah said Porter was “terminated” but later clarified he was not fired. Porter submitted his resignation Wednesday, and it was accepted, Shah said. Porter returned to the White House on Thursday morning to retrieve belongings, Shah said.

Shah said President Trump retains confidence in Kelly following the episode, in which Kelly first defended Porter's integrity against what Porter called a smear campaign.

Shah stressed Porter denies the allegations.

“You've got to take allegations seriously. You've got to take the denials seriously,” Shah said.

He did not directly address whether the White House regrets Porter was hired under the circumstances.

Porter’s title of staff secretary belies the role’s importance in any White House — but especially in Trump’s.

Porter functioned as Kelly’s top enforcer in their shared mission to instill discipline and order in what had become an extraordinarily chaotic West Wing. He was the gatekeeper to the Oval Office, determining which articles and policy proposals reached the president’s hands and screening the briefing materials that his visitors shared with him.

Porter’s first wife, Colbie Holderness, said in an interview with The Post that he was continually abusive during their marriage. She alleged he punched her in the face during a trip to Florence in 2005 and provided photos showing her with a black eye.

Porter’s second wife, Jennie Willoughby, received a temporary emergency protective order in ­Arlington in June 2010 after saying he refused to leave her residence, in violation of their separation agreement. She said he broke her window, causing his knuckles to bleed. The document, a copy of which was obtained by The Post, concludes that “reasonable grounds exist to believe that [Porter] has committed family abuse and there is probable danger of a further such offense.”

Josh Dawsey contributed to this report.