Last active
February 12, 2020 04:35
-
-
Save leepowers/9862956 to your computer and use it in GitHub Desktop.
Fix `clean_url` entities
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Fix esc_url/clean_url. Instead of escaping `&` to numeric character entities, this filter encodes them as `&` | |
* Some browsers (such as Android Chrome 33.0.1750.170) don't parse `&` correctly inside `<script src="..."></script>` tags. | |
* Such browsers leave out or otherwise mangle query string parameters. | |
* For instance, for a URL like `//maps.googleapis.com/maps/api/js?key=xxxx&sensor=false` the `sensor` parameter is not being sent to the server correctly. | |
*/ | |
function lpowers_fix_url_entities($url, $original_url, $_context) { | |
$bad_entity = "&"; | |
$good_entity = "&"; | |
$url = str_replace($bad_entity, $good_entity, $url); | |
return $url; | |
} | |
add_filter("clean_url", "lpowers_fix_url_entities", 99, 3); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment