I faced with problem. I have my self written plugin (my-plugin). It has admin page "users".
That page uses script /wp-content/plugins/my-plugin/my-plugin.php which inludes file /wp-content/plugins/my-plugin/users.php In admin area i use such url: /wp-admin/admin.php?page=my-plugin.php
I made there csv export link: /wp-admin/admin.php?page=my-plugin.php?export=1
code in users.php:
if (isset($_GET['export']))
{
user_export($_GET['export']);
}
function user_export($type)//export exel
{
global $wpdb;
$filename = "users_".date("Y-m-d_H-i",time());
$result = mysql_query("SHOW COLUMNS FROM `".$wpdb->prefix . "users`") or die(mysql_error());
$i = 0;
if (mysql_num_rows($result) > 0)
{
while ($row = mysql_fetch_assoc($result))
{
$csv_output .= $row['Field']."; ";
$i++;
}
}
$csv_output .= "\n";
$values = mysql_query("SELECT * FROM `".$wpdb->prefix . "users`") or die(mysql_error());
while ($rowr = mysql_fetch_row($values))
{
for ($j=0;$j<$i;$j++)
{
$csv_output .= $rowr[$j]."; ";
}
$csv_output .= "\n";
}
header("Content-type: application/vnd.ms-excel");
header("Content-disposition: csv" . date("Y-m-d") . ".csv");
header("Content-disposition: filename=".$filename.".csv");
print $csv_output;
exit;
}
I'm getting the file by clicking on the link, but that file contains all wordpress admin panel design.
I need get just get excel export file by clicking on link on admin page of my plugin.
May anybody help me?