Stokes marked the release date of the new documentary about his turbulent career with a timely piece of ambush marketing, hitting 103 as he and Foakes powered their side into a commanding first-innings lead of 264 at Emirates Old Trafford.
The wicketkeeper's only other hundred came on debut in Sri Lanka in 2018 and he carved out a vital 113 not out to share the heavy lifting with his skipper, allowing a declaration at 415 for nine.
With nine overs to face before the close Dean Elgar and Sarel Erwee reached 23 without loss, the start of a long battle to stay in contention.
For much of his first summer in charge, Stokes has been more concerned with making a statement at the crease than a score, driving his team's ultra-aggressive agenda but selling his wicket cheaply at times.
He struck a more mature balance here, clearing the ropes on three occasions and adding six fours, but he also showed durability and diligence as he scored at a refreshingly gentle strike-rate of 63.19.
Foakes was even more considered, reaching three figures in 206 deliveries, but between them the pair got their priorities perfectly right: cement England's position in the match and lay the foundations for levelling the series 1-1.
South Africa were still four runs in front when they came together at 147 for five, Anrich Nortje having ripped out the overnight duo of Jonny Bairstow and Zak Crawley in a fiery first spell. But they spent the next 53 overs side by side, putting on a brilliant stand of 173.
Stokes fell six balls after celebrating his 12th Test century with a familiar gesture in honour of his late father Ged, whose final days are touchingly captured in the new film, but Foakes held up his end to finish unbeaten.
With England resuming on 111 for three, still 40 short of parity, South Africa enjoyed the best of the early exchanges. That was down to Nortje, who once again raised the roof with his hostile pace.
Bairstow was first to succumb, one short of his half-century, when he nicked a reverse-swinging delivery to the keeper before Crawley followed in Nortje's next over.
The opener won generous praise for grinding out 17 in 77 balls on the first evening but was vulnerable from the outset here. He opened his account with an edge through the cordon and was lucky to see a leading edge land safe before he eventually feathering Nortje behind for 38.
South Africa's spirits were up but the sixth-wicket partnership between Stokes and Foakes changed that. Stokes safely negotiated the remainder of Nortje's opening burst and rewarded himself by slog-sweeping his first ball from Simon Harmer for six.
A dashed single on 16 left him wincing in pain, his troublesome left knee once again causing discomfort, but a visit from the physio put him right and it was not long before he was punching Lungi Ngidi down the ground for four.
Foakes offered solid support, overturning an lbw decision on 28 before clubbing a no-ball for four just before lunch to take England's runs for the session past 100.
Nortje was surprisingly held back at the restart in favour of spin at both ends, a decision which played to Foakes' strengths against slow bowling and allowed Stokes to assert himself again. He reached fifty by smashing Harmer for six on the charge and never looked back. Nortje returned for two further spells but could not recreate his previous menace.
Stokes was emboldened, stepping away to swat Ngidi over extra-cover before launching Keshav Maharaj over long-off for six more, while Foakes quietly chalked off his own half-century.
Aiden Markram made a game attempt to pull off a wonder catch when Stokes hammered one in his direction just before tea and the England skipper reached the break two short of his ton.
The wait did not deter him, but almost as soon as the celebrations died down he was caught attempting to throw the kitchen sink at Kagiso Rabada. Foakes crept carefully to his own hundred while Stuart Broad and Ollie Robinson swung the bat, reaching the landmark with a slash for four off Nortje.
A breakthrough with the ball would have capped off a superb day, but a hopeful lbw referral from James Anderson was as close as they came before stumps.