Skip to content

Instantly share code, notes, and snippets.

@wsaribeiro
Forked from joemcgill/show_img_vars.php
Created March 4, 2016 17:35
Show Gist options
  • Save wsaribeiro/164e2735bc30aeb27b75 to your computer and use it in GitHub Desktop.
Save wsaribeiro/164e2735bc30aeb27b75 to your computer and use it in GitHub Desktop.
A poor man's var_dump for the image_send_to_editor() filter in Wordpress. Throw this in your functions.php file and add an image to your post to see what get's passed. Filter it however you want to return the image however you want.
<?php
function show_img_vars($html, $id, $caption, $title, $align, $url, $size, $alt) {
// round up all the variables that get passed so we can test them
$vars = "html = $html\n";
$vars .= "id = $id\n";
$vars .= "caption = $caption\n";
$vars .= "title = $title\n"; // this will end up blank no matter what
$vars .= "align = $align\n";
$vars .= "url = $url\n";
$vars .= "size = $size\n";
$vars .= "alt = $alt\n";
// return the normal html output you would expect
$return = $html . "\n";
// add our ad-hoc var dump to the editor
$return .= "<!-- args \n";
$return .= $vars;
$return .= "/args -->";
return $return;
}
add_filter( 'image_send_to_editor', 'show_img_vars', 10, 9 );
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment