Charlie Sheen has been granted an emergency order to obtain sole custody of his 14-year-old twins if their mother relapses.
The 58-year-old actor filed a motion last week with new stipulations involving his ex-wife Brooke Mueller's sobriety.
According to documents obtained by PEOPLE, Charlie has asked the court to sign and enter two documents, which stipulate the pair have agreed that Charlie will get sole custody of their sons Bob and Max if she relapses.
The pair share physical custody of the boys, although the paperwork states that "the minor children's primary residence will be with [Sheen]".
They will "continue to enjoy joint legal custody" unless Brooke tests positive for drugs and alcohol or otherwise relapses.
If she does, Charlie will obtain sole custody "until further court order or written agreement of the Parties".
The documents state: "Brooke shall enjoy reasonable and flexible periods of custody and visitation as agreed and arranged between the Parties, [with] the goal of frequent and continuous contact between the minors and both parents."
Brooke must also undergo drug and alcohol testing weekly as well as "as often as required by her probation officer" or "within 24 hours of a written request (email or text) from [Sheen] or his attorney,".
This will continue until their sons Bob and Max turn 18 or graduate high school.