I want to add functionality to the wordpress plugin to download custom file.
here is my code.
add_action('admin_menu','function_name');
and here is the download code.
header("Content-Disposition: attachment; filename=map.html");
header("Content-Length: ".strlen($content));
echo $content;
exit;
But, I’m getting error.
[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
I’m making the request like this
http://www.website.com/wp-admin/admin.php?page=file-download&fileid=10
I suggest using this hook
http://codex.wordpress.org/Plugin_API/Action_Reference/load-%28page%29
with the return value of the add_menu_page function.
The load-$page is like the init hook for admin pages.