It doesn't seem that output buffering takes into account echo's from within hooked functions.
function buffer_start() { ob_start(); }
function buffer_end() { ob_end_flush(); }
add_action('init', 'buffer_start');
add_action('admin_footer', 'buffer_end');
add_action("draft_to_publish", "my_hooked_function", 10, 1); // the hook
function my_hooked_function($post) {
echo("<script>console.log('some stuff I want to output to the developer console, via the html page');</script>");
}
Somehow, this doesn't work. It will ignore the echo, and not update the source on the page. Even though the Wordpress execution cycle is: init
, draft_to_publish
, admin_footer
.
If I input echo's into the buffer_start and buffer_end functions, it works as normal though.
What am I doing wrong? Is there any scope or context or something that I need to reference from within my_hooked_function
to make sure the echo there goes to the page's output buffer?
I used this code as a starting point: http://www.dagondesign.com/articles/wordpress-hook-for-entire-page-using-output-buffering/