custody or legal custody:
1. A parent of the child.
2. A person who stands in loco parentis to the child.
3. A grandparent of the child who is not in loco parentis to the child:
a. whose relationship with the child began either with the
consent of a parent of the child or under a court order;
b.who assumes or is willing to assume responsibility for the child; and
c. when one of the following conditions is met:
(1) the child has been determined to be a dependent child under 42 Pa.C.S. Ch. 63 (relating to juvenile matters);
(2) the child is substantially at risk due to parental abuse, neglect, drug or alcohol abuse or incapacity; or
(3) the child has, for a period of at least 12 consecutive months, resided with the grandparent, excluding brief temporary absences of the child from the home, and is removed from the home by the parents, in which case the action must be
filed within six months after the removal of the child from the home.