这不是一个直接的答案,但是:对于管理端的简单数据导出,我通常只使用AJAX API. 为导出设置AJAX处理程序:
/**
* export from admin
*/
function wpse_126508_export() {
header(\'Content-Type: text/xml; charset=utf-8\');
header(\'Content-Description: File Transfer\');
header(\'Content-Disposition: attachment; filename=wpse_126508_export.xml\');
$xml = new XMLWriter();
$xml->openURI(\'php://output\');
$xml->startDocument(\'1.0\', \'UTF-8\');
$xml->startElement(\'wpse_126508_export\');
// ... your details
$xml->endElement(); // wpse_126508_export
$xml->flush();
exit();
}
add_action(\'wp_ajax_wpse_126508_export\', \'wpse_126508_export\');
add_action(\'wp_ajax_nopriv_wpse_126508_export\', \'wpse_126508_export\');
然后在管理页面上输出指向它的链接:
$exportURL = add_query_arg(array(
\'action\' => \'wpse_126508_export\',
\'nc\' => time(), // cache buster
), admin_url(\'admin-ajax.php\'));
printf(\'<a href="%s">export</a>\', $exportURL);
当然,如果需要发布请求,也可以向AJAX端点提交表单。