Skip to content

Instantly share code, notes, and snippets.

@vstm
Last active January 23, 2024 22:06
Show Gist options
  • Save vstm/12cb0b79462e254b7d5c to your computer and use it in GitHub Desktop.
Save vstm/12cb0b79462e254b7d5c to your computer and use it in GitHub Desktop.
Debug wp_oembed-problems
<?php
require_once("wp-load.php");
add_action('http_api_debug', 'test_http_api_debug', 10, 5);
add_filter('oembed_remote_get_args', 'test_oembed_remote_get_args', 10, 2);
add_filter('oembed_fetch_url', 'test_oembed_fetch_url', 10, 3);
$embed_code = wp_oembed_get('http://vimeo.com/75343493');
echo "<h2>result</h2>", PHP_EOL;
var_dump_html($embed_code);
print($embed_code);
function var_dump_html($var) {
ob_start();
var_dump($var);
$result = ob_get_contents();
ob_end_clean();
echo "<pre>", htmlspecialchars($result), "</pre>", PHP_EOL;
}
function test_oembed_remote_get_args($args, $url) {
echo "<h2>oembed_remote_get_args</h2> $url<br>", PHP_EOL;
return $args;
}
function test_oembed_fetch_url($provider, $url, $args) {
echo "<h2>oembed_fetch_url</h2> $provider, $url <br><pre>", PHP_EOL;
var_dump_html($args);
echo "</pre>end oembed_fetch_url<br>", PHP_EOL;
return $provider;
}
function test_http_api_debug($response, $context, $class, $args, $url) {
echo "<h2>http_api_debug</h2> context=$context, class=$class, url=$url <br>", PHP_EOL;
echo "args: "; var_dump_html($args);
if(is_wp_error($response)) {
echo "error: ", PHP_EOL;
$messages = $response->get_error_messages();
var_dump_html($messages);
} else {
echo "response:";
var_dump_html($response);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment