Skip to content

Instantly share code, notes, and snippets.

@oddevan
Last active November 3, 2020 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oddevan/03c675a843c03b3f66cf1eff012889be to your computer and use it in GitHub Desktop.
Save oddevan/03c675a843c03b3f66cf1eff012889be to your computer and use it in GitHub Desktop.
<?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