He is having a problem with his second wife and he fears for his daughter
The basic principle concerning divorce is that it is makrooh (disliked), as is indicated by the verse in which Allaah says (interpretation of the meaning):
“Those who take an oath not to have sexual relation with their wives must wait for four months, then if they return (change their idea in this period), verily, Allaah is Oft-Forgiving, Most Merciful.
227. And if they decide upon divorce, then Allaah is All-Hearer, All-Knower”
[al-Baqarah 2:226]
In relation to changing their minds He said “Oft-Forgiving, Most Merciful” and in relation to divorce He said “All-Hearer, All-Knower”. This indicates a kind of warning, which in turn indicates that divorce is disliked by Allaah (makrooh).
But there may be some cases in which divorce is inevitable, and even essential. In the case which you mention, divorce may be the appropriate solution, because it is unthinkable that a wife would treat her husband in such a bad way as you describe in your question. A woman could say or do something to offend her husband, but to be constantly ungrateful is very strange.
But before divorce, you have to try to reconcile first, and put up with the woman. If she has some bad characteristics, you will also find some good qualities, so you can put up with the bad characteristics because of the good ones.
See questions no. 20044 and 2076.
If you can get some relatives involved to solve the problem, then do so, as an act of mercy to this poor girl who will suffer – no matter what the situation – from the bitterness of separation and the break-up of the family.
If divorce is the final solution, and you have exhausted all possible solutions, then pray istikhaarah (asking for guidance) and consult others, and put your trust in Allaah.
With regard to the matters that she has referred to the court, this may be a request to the qaadi (judge) to compel the husband to divorce her by talaaq or it may be khula’, depending on the situation. If she is going to give the husband some money or return the mahr to him in return for getting a divorce, then this is khula’; if she is not going to pay anything then this is talaaq, if it takes place.
With regard to custody, the basic principle is that the mother has more right to custody, so long as there is no impediment to that. If there is any impediment, such as the mother marrying someone who is a stranger (non-mahram) to the child, or the mother’s character or attitude is bad, then custody passes to the mother’s mother according to the majority. If the mother’s mother is the same (i.e., of bad character etc) then custody passes to the father. Shaykh al-Islam Ibn Taymiyah was of the view that in the case of a dispute between the mother’s mother and the father, custody should be given to the father, because he is closer to the child. This view was also favoured by Shaykh Ibn ‘Uthaymeen in his commentary on the chapter on custody in Zaad al-Mustaqni’. We have already discussed this in detail in question no. 5234, 9463, 8189, and 21516. And Allaah knows best.