Last active
November 3, 2020 14:13
-
-
Save oddevan/03c675a843c03b3f66cf1eff012889be to your computer and use it in GitHub Desktop.
This file contains 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 | |
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