Skip to content

Instantly share code, notes, and snippets.

@oddevan
Last active April 4, 2023 02:40
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oddevan/f83a9bae88cf82976663f782075dd1e2 to your computer and use it in GitHub Desktop.
Save oddevan/f83a9bae88cf82976663f782075dd1e2 to your computer and use it in GitHub Desktop.
<?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