Former "Glee" star Mark Salling pleaded guilty to possession of child pornography involving a prepubescent minor as part of a plea bargain.

Us Weekly reported that the actor was facing two counts of child pornography after police found over 50,000 images of child erotica on his computer and another 4,000 on a flash drive. According to the deal, he agreed to make restitution to the victims, paying "approximately $50,000" to each who has requested it.

>> Read more trending news

Salling could have gone to prison for up to 20 years, but prosecutors agreed to having him serve four to seven years in prison with 20 years of supervised release. Upon release, he will be required to register as a sexual offender and cannot have any communication with anyone under 18 without a parent or legal guardian present. As a result, he won’t be allowed to live within view of, and must stay 100 feet away from, school yards, parks, public swimming pools, playgrounds and video arcade venues.

The actor was initially arrested in December 2015 after police were tipped off that he had a trove of child pornography in his home. After the horrifying discovery, Salling was cut from the film "Gods and Secrets."

In a 2016 memoir, Salling's ex-girlfriend and former "Glee" co-star Naya Rivera wrote that she wasn't "totally shocked" by the charges against him.