Created
September 8, 2015 08:45
-
-
Save pfefferle/62f7154c0ef2f94342fa to your computer and use it in GitHub Desktop.
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
/** | |
* Get the oEmbed endpoint URL for a given permalink. | |
* | |
* Pass an empty string as the first argument | |
* to get the endpoint base URL. | |
* | |
* @param string $permalink The permalink used for the `url` query arg. | |
* @param string|bool $format The requested response format. | |
* Provide false to get the default format. | |
* | |
* @return string | |
*/ | |
function get_oembed_endpoint_url( $permalink = '', $format = false ) { | |
$url = add_query_arg( array( 'oembed' => 'true' ), home_url( '/' ) ); | |
if ( function_exists( 'rest_url' ) ) { | |
$url = rest_url( 'wp/v2/oembed' ); | |
} | |
/** This filter is defined in classes/class-plugin.php */ | |
$default_format = apply_filters( 'rest_oembed_default_format', 'json' ); | |
if ( $format === $default_format ) { | |
$format = false; | |
} | |
if ( '' === $permalink ) { | |
$url = add_query_arg( array( | |
'url' => $permalink, | |
'format' => $format, | |
), $url ); | |
} | |
/** | |
* Filter the oEmbed endpoint URL. | |
* | |
* @param string $url The URL to the oEmbed endpoint. | |
* @param string $permalink The permalink used for the `url` query arg. | |
* @param string $format The requested response format. | |
* | |
* @return string | |
*/ | |
$url = apply_filters( 'rest_oembed_endpoint_url', $url, $permalink, $format ); | |
return $url; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment