Created
July 2, 2012 20:13
-
-
Save holizz/3035404 to your computer and use it in GitHub Desktop.
Attempt to fix oEmbed in WordPress - doesn't work because certain oEmbed providers won't give you HTTPS-suitable content
This file contains 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
# Fix oEmbed for HTTPS | |
add_filter('oembed_providers', function ($providers) { | |
$new_providers = array(); | |
foreach ($providers as $key => $value) { | |
$matchmask = $key; | |
$providerurl = $value[0]; | |
$regex = $value[1]; | |
# Convert simple-style to full regex (assuming all regexes use # as delimiter) | |
if (!$regex) { | |
# wp-includes/class-oembed.php line 79 | |
$matchmask = '#' . str_replace( '___wildcard___', '(.+)', preg_quote( str_replace( '*', '___wildcard___', $matchmask ), '#' ) ) . '#i'; | |
} | |
# Make regex match HTTPS too (note that some URIs already match for /https?/) | |
if (substr($matchmask, 0, 9) !== '#https?://') { | |
$matchmask = preg_replace('_^#http://_', '#https?://', $matchmask); | |
} | |
# Make oEmbed URL HTTPS | |
$providerurl = preg_replace('_^http://_', 'https://', $providerurl); | |
# Add it | |
$new_providers[$matchmask] = array($providerurl, true); | |
} | |
return $new_providers; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment