Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?php
function proxy_deviantart_oembed( $data ) {
$url = $data->get_param( 'url' );
if ( ! is_valid_url( $url ) ) {
return new WP_Error(
'error',
'Error: not a DeviantArt URL',
[ 'input' => $data ],
);
}
$da_response = wp_remote_get(
'https://backend.deviantart.com/oembed?url=' . $data->get_param( 'url' ),
[ 'headers' => [ 'User-Agent' => 'WordPress OEmbed Consumer' ] ]
);
if ( empty( $da_response ) || 200 !== $da_response['response']['code'] ) {
return new WP_Error(
'error',
'Error in response from DeviantArt',
[
'input' => $data,
'response' => $da_response,
]
);
}
return new WP_REST_Response( json_decode( $da_response['body'] ) );
}
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.