输出缓冲似乎没有考虑挂钩函数中的echo。
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>");
}
不知怎么的,这是行不通的。它将忽略回显,而不会更新页面上的源。即使Wordpress的执行周期是:init
, draft_to_publish
, admin_footer
.如果我将echo输入到buffer\\u start和buffer\\u end函数中,它会正常工作。
我做错了什么?我是否需要从内部引用任何范围、上下文或其他内容my_hooked_function
要确保回音到达页面的输出缓冲区?
我使用此代码作为起点:http://www.dagondesign.com/articles/wordpress-hook-for-entire-page-using-output-buffering/