Glee star Mark Salling has pleaded guilty to two counts of possession of child pornography involving a prepubescent minor.

The actor, 35, struck a plea deal on Wednesday. He’ll be sentenced to four to seven years in prison, according to court documents obtained by gossip website The Blast.

The documents also indicate that he must register as a sex offender, have no communication with anyone under the age of 18 (unless in the presence of a parent or guardian) and will be under supervised release for 20 years. He’ll also fall under the usual restrictions of registered sex offenders, being required to stay 100 feet (about 30m) away from schoolyards, parks, public swimming pools, playgrounds and video arcade facilities at all times.

Federal investigators found more than 50,000 “sexually charged” images and videos depicting child pornography on computers and hard drives belonging to Salling, reports The Sun. He was facing a maximum of 20 years behind bars before striking the plea deal.

He’s also been ordered to pay $50,000 (about AU $63,500) to each victim seeking restitution.

Investigators were reportedly tipped off to the mass of child pornography by one of Salling’s ex-girlfriends, to whom he showed the material to on at least two occasions.

He was arrested on December 29, 2015, but was later released on $20,000 bail.

“It doesn’t matter who you are or what you do, if you hurt children you will be held accountable,” said Lieutenant Andrea Grossman of the LAPD internet Crimes Against Children Task Force.

“These images are more than photographs, they are child abuse.”

Salling was previously sued by ex-girlfriend Roxanne Gorzela for sexual battery, which the pair settling for a reported $2.7 million (AU $3.43 million).

Image: Getty Images / Jason LaVeris