Yoast/wordpress-seo — pull request #1172 by jrfnl (2014-05-27 04:42:12+00:00)
Title: Refactor of the wpseo_replace_vars function

Complete refactor of the `wpseo_replace_vars()` function. This should hopefully fix most, if not all, the issues people were having with variables not being replaced. If not, it will at the very least make it a hell of a lot easier to debug any remaining issues ;-)

The refactor also implements what was intended by pull request #1121 and reversed in commit 0e0c8af511006e8d1536ca7f7ea07835ee6fb41e, i.e. removal of unreplaced variables, now while respecting the `$omit` variable. /cc @Petervw

Tested, but additional testing welcome & recommended.

Pull request #981 will need updating to be compliant with this pull request (or if that's merged first, this PR will need to be updated with the new setting, but it's an easy fix). /cc @dannyvankooten

**Related issues:**
- #1080, #1092, #1104, #1106, #1108, #1111, #1119, #1121, #1122, #1125, #1126, #1127, #1128, #1129, #1140, #1150, (may be) #1124 - variable replacements failing
- #1145 registering new variables + help texts
- #981 double separator comment

#### Changelog:

**Bugfixes**

* Refactored the variable replacement function for better, faster results and more stability. This should fix most if not all problems users where having with variables not being replaced in the title, meta description, snippet preview etc - props [Jrf](http://profiles.wordpress.org/jrf).
* Fixed: `wpseo_replacements` filter was being run before all replacements were known.
* Fixed: `%%pt_single%%` and `%%pt_plural%%` didn't work in preview mode.
* Fixed: `%%page_total%%` would sometimes be one short.
* Fixed: `%%term404%%` would sometimes be empty while the pagename causing the 404 was known.

**Enhancements**

* New `wpseo_register_extra_replacements` action hook which lets plugin/theme builders add new `%%...%%` replacement variables - including relevant help texts -. See [function documentation](https://github.com/Yoast/wordpress-seo/blob/master/inc/wpseo-functions.php) for an example of how to use this new functionality.
* If the final string - after replacement - would contain two separators with nothing between them, this extra separator will be removed.
* All remaining not replaced replacement vars are now stripped from the strings (without breaking the snippet preview).

**_Also_**: variable help tables now have auto-alternating row colours