/ ** * Instantiate CSVDownload class with appropriate arguments (listed in class).
*使用适当的参数实例化CSVDownload类(在类中列出)。
* Arguments are optional
*参数是可选的
*/
* /
if (class_exists('CSVDownload')) {
如果(class_exists('CSVDownload')){
$csv_button = New CSVDownload(array(
$ csv_button =新的CSVDownload(array(
'post_types' => array('page'),
'post_types'=> array('page'),
'post_type_ids' => array(420, 114, 749),
'post_type_ids'=> array(420,114,749),
'metabox_title' => 'Download CSV Data',
'metabox_title'=>'下载CSV数据',
'help_text' => 'CSV file containing useful data.',
'help_text'=>'包含有用数据的CSV文件。',
'parameter' => 'csv_export_button',
'参数'=>'csv_export_button',
'button_text' => 'Download'
'button_text'=>'下载'
));
));
}
}
/**
/ **
* Get results, convert to csv file, and trigger download.
*获取结果,转换为csv文件,并触发下载。
*/
* /
if(isset($_GET[$csv_button->parameter])) {
if(isset($ _ GET [$ csv_button-> parameter])){
add_action('admin_init', function(){
add_action('admin_init',function(){
// Get results array
//获取结果数组
$results = get_csv_file_results();
$ results = get_csv_file_results();
// Convert results array to csv file and trigger download.
//将结果数组转换为csv文件并触发下载。
CSVDownload::download_csv_results(array(
CSVDownload :: download_csv_results(array(
'results' => $results,
'results'=> $ results,
'file_name' => 'csv_data'
'文件名'=>'csv_data'
));
));
exit;
出口;
}, 1);
},1);
}
}
/**
/ **
* Get the results array for the csv button download.
*获取用于csv按钮下载的结果数组。
*
*
* @return array
* @返回数组
*/
* /
function get_csv_file_results(){
函数get_csv_file_results(){
// Create multi-dimensional array.
//创建多维数组。
$results_array = array(
$ results_array =数组(
array('Email','User Name','Favorite Color'), // Column headers
array('Email','User Name','Favorite Color'),//列标题
array('fake@email.com','coolguy1','blue'),
array('fake@email.com','coolguy1','blue'),
array('fake@email.com','coolguy2','orange'),
array('fake@email.com','coolguy2','orange'),
array('fake@email.com','coolguy3','pink'),
array('fake@email.com','coolguy3','pink'),
array('fake@email.com','coolguy4','red'),
array('fake@email.com','coolguy4','red'),
);
);
// Return results array
//返回结果数组
return $results_array;
返回$ results_array;
}
}