Updated

A court commissioner has put the legal clamps on Britney Spears in a child custody dispute with her ex-husband Kevin Federline, noting she has not been in "substantial compliance" with a previous court order.

In an order released Thursday, Superior Court Commissioner Scott M. Gordon granted some visitation rights to the 25-year-old pop singer, but required that a monitor must watch her while she's with her sons, 2-year-old Sean Preston and 1-year-old Jayden James.

The visits will be cut short if the monitor decides any behavior or action by Spears endangers the children. Following a closed-door hearing Wednesday that Federline attended, a court spokesman indicated Spears would be allowed visits every other day.

Click here to read the court documents on TMZ.com

Phone messages left for attorneys for Spears and Federline were not immediately returned Thursday.

Earlier this week, Federline received temporary custody of the children, but Gordon said in his order that both parties will continue to share joint custody.

Spears turned the boys over to Federline after she failed to produce a California driver's license and allegedly missed a drug and alcohol test as ordered by the court, her attorney Sorrell Trope said.

Trope told The Associated Press on Thursday that there were attempts to reach Spears at her home about the testing, but that she never got the messages.

Although a temporary driver's license was issued to Spears late Tuesday in Santa Monica, Gordon said in his order that she "was not in substantial compliance with material provisions" of his previous ruling.

Gordon also said if Spears misses or refuses a drug and alcohol test, it will be "deemed by the court as a failed test."

"There has been no actual failed test in this case," Trope said. "She did not take a test when one was requested."

He also said Spears must complete at least three individual counseling sessions by the next hearing on Oct. 26.

He previously ordered Spears to undergo random drug and alcohol testing twice a week after the court found she engages in "habitual, frequent and continuous use of controlled substances and alcohol."

Gordon also previously ordered Spears to meet weekly with a "parenting coach" who was to report back to the court about her skills. Both Spears and Federline must complete the court's "Parenting Without Conflict" class.

Spears and Federline also were refrained from drinking or using drugs either in the presence of their children or within 12 hours before taking charge of them.

Federline's attorney, Mark Vincent Kaplan, said Wednesday his client has been in full compliance with the commissioner's order.

A phone message left for Federline's attorney Thursday was not immediately returned.

Spears and Federline were married in October 2004. She filed for divorce last November and it became official in July. They previously shared custody of the boys. Federline, 29, also has a son and daughter with former girlfriend Shar Jackson.

Spears has spiraled seemingly out of control since splitting with Federline. First she hit the Hollywood party circuit, where she was photographed several times without underwear. Then she volleyed in and out of rehab, shaved her head, beat a car with an umbrella and eventually spent a month at the posh Promises rehab clinic in Malibu.

An MTV Video Music Awards performance intended as a comeback was panned, with Spears appearing lethargic. The following week, her management firm dropped her and her divorce lawyer resigned.

Her problems continued when she was charged with misdemeanor counts of hit-and-run and driving without a valid license for allegedly crashing into a parked car in August.

On the upside, her new song, "Gimme More," topped Billboard's Hot Digital Songs with 179,000 downloads, and jumped from No. 68 to No. 3 on Billboard's Hot 100.

The song is the first single from her new album, set for release Nov. 13.