My son is 8 now. When he was around 4 he got a medication with the side effect to have hard to work to poo and it was very uncomfortable for him to do so. This led to a total avoiding strategy in his behaviour.
At the worsed point he was neglecting every need to go to the bathroom. He answered "no" whenever he was asked, if he needs the toilett. He got angry, when we did not ask, but instead said "go to the toilet!".
Today I assume the thing was bound to shame. He was very ashamed, to not be able make it right. So he totally ignored it.
The first step for me was to mention it in a regular meeting with the childrens doctor (without my son in the room). We both agreed to make it as easy as possible for him to do it right. So I had a talk with my son. I gave him the opportunity to go back to diapers (he was nearly 5 then) and, to my surprise, he agreed. I really tried to give him the impression, that the diaper is no punishment, that we tell nobody about it if he does not like, and that it is like a medication, you take it some time and then the issue will become better and the diapers will not be used anymore.
The diapers were shaped like pants, so he was using them in the same way, he was able to go to toilet and undress and dress again at his own. It helped us all to calm down. Less washing, less shame for him (and us) around other people, better control. When he went to toilet we praised him. Later we praised him when he went and the diaper was dry. He was proud of himself too. So we knew, it was his aim and motivation too, to handle the situations in a "grown up" manner.
I praised him every time he told me he needs to pee. In every situation (if it did not fit with my plans, if we were somewhere no toilet was around, whatever stress it caused me) I made clear I am happy he told me! I made clear, it was not his fault, if there is no toilet around. We saw a lots of trees and bushes at this time from near.
We completely avoided to shame him in front of other people. We made some secret sign, to remind him to go to toilet/to ask, if he wants to go. Over the summer, when it got hot, it was easy for him, to have more and more days without the diapers. He turned 6 and started school. I gave him the option to take the diapers again for the first days. And he agreed (he used them for around 3 weeks, nearly never brought home a wet one, but it made him feel save). Also I had a talk with the teacher. She was really nice. To avoid shame, she gave him a papercut-circle, green from one side, red from the other. If he need to go to the toilet, he could turn it, so the teacher knows, without he need to tell the whole class. Also the teacher sent all children to the bathroom before end of day, because my son took the school's bus home (to avoid he needs to pee at the trip).
Now he is 8. Sometimes, maybe once a month or less, he comes after one hour bus tour home, wispering in my ear, that he needs a new pants. He has two pants to change in the bathroom (hidden from guests eyes) and does it all on his own. I have a close eye on rhe frequency he poos. Because if this get stuck, he falls in old patterns right easy. He has an understanding of the connections (so I can remind him), but still needs time to relax and poo (My duty to give it to him). Also my duty is to have a look for food, which helps in making the poo soft, and less hard work for my son.
So my summary advice would be:
- do not punish
- make it as easy as possible for the girl and all around to reduce frustration, stress and anger
- praise every even the smallest step forward, let the girl be proud at herself
- avoid situations the girl could be ashamed/blamed
- take time, you want a solution for the long run, nothing working only for a short time
- have a talk with a person of medicine to be absolutely sure there is no medical reason