Skip to content

Instantly share code, notes, and snippets.

@oddevan oddevan/eph-daembed.php
Last active Jul 17, 2019

Embed
What would you like to do?
<?php
namespace EPH\DAEmbed;
function register_providers() {
$callback = __NAMESPACE__ . '\handle_deviantart';
wp_embed_register_handler( 'deviantart-main', '#https://www.deviantart.com/*+#', $callback, 10 );
// Include other handlers as needed
}
function handle_deviantart( $matches, $attr, $url, $rawattr ) {
$http_options = [
'headers' => [
'User-Agent' => 'WordPress OEmbed Consumer',
],
];
$da_response = \wp_remote_get( 'https://backend.deviantart.com/oembed?url=' . rawurlencode( $url ), $http_options );
if ( empty( $da_response ) || 200 !== $da_response['response']['code'] ) {
return "<p><!-- Could not embed --><a href=\"{$url}\">View Deviation</a></p>";
}
// Generate client-side HTML here
return $html;
}
add_action( 'init', __NAMESPACE__ . '\register_providers' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.