Rewrite Rules: Add support for random content redirects.
Introduce a random query var and /random/ rewrite rules[1], built on the existing rewrite, WP, and query APIs, that redirect to a randomly selected published post. Random requests[2] work for the whole site, taxonomy terms, authors and post type archives, with the base configurable on the Permalinks screen. A new randomable post type argument controls which content is eligible, and the selection runs through the main query so it remains filterable and costs a single database query.
The Random Base[3] is translatable and stored in the rewrite rules. This means that rewrite rules are regenerated when translations are updated or the Site Language is changed. Also, if a post or page is published that would result in the same slug as the Random Base, that content gets priority and nothing will be random[4].
This reintroduces the feature committed in r63767 and reverted in r63906.
1) Literally /random/, not just rules that are random. Though that could be fun too!
2) Not "random" as in unpredictable, but random as in someone wanted it to be random.
3) It's intentionally "random" but it could also intentionally be "aleatoria" or "karkovice".
4) The other random permalinks will still work, so not nothing. But is anything really random?
Developed in: https://github.com/WordPress/wordpress-develop/pull/14018
Follow-up to r63767, r63906.
Props jorbin, peterwilsoncc, westonruter, mukesh27, annezazu, mlaetitia, mcsf, johnbillion, TobiasBg, solankisoftware, sajib1223, ellatrix, matt.
See #64498.