Last active
April 4, 2023 02:40
-
-
Save oddevan/f83a9bae88cf82976663f782075dd1e2 to your computer and use it in GitHub Desktop.
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 | |
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