A federal appeals court ruling Tuesday leaves in place almost all of a Texas law banning so-called sanctuary cities.

The law, Senate Bill 4, punishes local officials who limit immigration enforcement by local police or prevent officers from questioning the immigration status of anyone they detain or arrest. It also requires county jails to honor requests by U.S. Immigration and Customs Enforcement to hold detainees suspected of being eligible for deportation.

Tuesday’s ruling by a three-judge panel of the 5th Circuit Court of Appeals in New Orleans overturns an injunction by a San Antonio federal judge that had found portions of the law unconstitutional.

The appeals court upheld almost all of the law except for civil penalties for local officials who “endorse a policy under which the entity or department prohibits or materially limits the enforcement of immigration laws.” They found that use of the word “endorse” could violate the First Amendment and result in penalties against local officials who speak out on immigration policies.

“With one exception, SB4’s provisions do not, on their face, violate the Constitution,” the justices wrote.

RELATED: Trump views designs for border wall while bashing California

The unanimous ruling was by justices Edith Jones and Jerry Smith, both Ronald Reagan appointees, and Edward Prado, a San Antonio native appointed to the appellate bench by George W. Bush and who was nominated this year to be ambassador to Argentina.

Texas Republicans like Attorney General Ken Paxton, who had defended the law in court, and Gov. Greg Abbott, who’d pushed for the law and signed it last year in a ceremony live streamed on Facebook, celebrated the decision.

“I’m pleased the 5th Circuit recognized that Senate Bill 4 is lawful, constitutional and protects the safety of law enforcement officers and all Texans,” Paxton said in a statement. “Enforcing immigration law prevents the release of individuals from custody who have been charged with serious crimes. Dangerous criminals shouldn’t be allowed back into our communities to possibly commit more crimes.”

RELATED: Immigrants in Florida, facing a Texas SB-4 'anti-sanctuary' environment, activists say

San Antonio was one of the first cities to challenge SB 4, in part because of a police department policy preventing officers from asking about immigration status.

When U.S. District Judge Orlando Garcia enjoined key portions of the law last year, he left in place provisions that allowed the Texas Attorney General to fine or remove local officials who prevent police from asking about immigration status.

Opponents of the law had said it turns police into immigration agents, eroding trust in the community and harming their ability to enforce state laws and local ordinances.

At the time, Mayor Sylvester Turner praised the ruling that temporarily blocked pieces of the "sanctuary cities" law that would have allowed local law enforcement to question a person's immigration status. His stance was echoed by Houston Police Chief Art Acevedo, who said that he did not want his police officers to become quasi-ICE agents.

On Tuesday, state Sen. José Menéndez, D-San Antonio: said “The ruling doesn’t change that SB4 is an unnecessary, politically motivated law that was opposed by virtually everyone in law enforcement.” “It does nothing to make anyone safer and it will drive a wedge between law enforcement and certain people.”

POLICE CHIEFS: SB 4 a 'lose-lose' for Texas

The judges left some leeway for local officials “regarding bona fide resource allocation — e.g., policies regarding overtime or patrolling locations.”

“The court cannot force you to go bankrupt,” said Luis Vera, an attorney for the League of United Latin American Citizens representing the border communities of El Cenizo and Maverick County. “The locals still have a right to allocate their resources where they need them first.”

In his ruling last year Garcia had also found that ICE detainers, requests by immigration officials to keep criminal suspects in county jails for up to 48 hours after they would have otherwise been released, violated the Fourth Amendment.

SB 4 makes it a misdemeanor to ignore ICE detainers, and Garcia ruled that because immigration cases are civil matters and local police enforce criminal laws, the statute violated protections from unreasonable search and seizure.

The 5th Circuit disagreed, finding that ICE administrative warrants, which unlike criminal warrants are not issued by a judge, are sufficient to detain in a county jail someone who ICE might deport, even if they’ve been granted bail or their charges have been dropped.

Vera said lawyers involved in the case will have to decide if they want to appeal the ruling to a larger panel of the appellate court, ask the Supreme Court to review Tuesday’s ruling, or return to Garcia’s court for a trial on the merits.

Cesar Espinosa, executive director of FIEL, an immigrant rights group in Houston, stated: “This doesn't entirely change the implementation of the program since the key provisions of SB4 have been in effect this entire time. We know the 5th Circuit is a very conservative court but we had hoped they would see how damaging a law like SB4 would be to our communities. Not all is lost though, we hope that we may be able to take this case up all the way to the Supreme Court and hope the justices can make the right decision on this very damaging law."

The state could also face more lawsuits if SB 4 results in civil rights violations after it’s implemented, he said.

Peggy Fikac and Allie Morris of the San Antonio Express-News contributed to this report.