我想在wordpress插件中添加功能以下载自定义文件。 这是我的代码。
add_action('admin_menu','function_name');
这是下载代码。
header("Content-Disposition: attachment; filename=map.html");
header("Content-Length: ".strlen($content));
echo $content;
exit;
但是,我收到了错误。
[22-Feb-2015 00:00:00 UTC] PHP Warning: Cannot modify header information - headers already sent by (output started at /path/to/wp/wp-admin/includes/template.php:1877) in /path/to/wp/wp-content/plugins/plugin-name/lib/model.php on line 99
我正在提出这样的请求
http://www.website.com/wp-admin/admin.php?page=file-download&fileid=10
答案 0 :(得分:0)
我建议使用这个钩子
http://codex.wordpress.org/Plugin_API/Action_Reference/load-%28page%29
使用add_menu_page函数的返回值。
load- $页面就像管理页面的init钩子一样。