I am creating a plugin in wordpress that should download an excel with several data from the DB but instead of doing so, paste the table into the Wordpress dashboard.
<?php
/**
* Plugin Name: Excel
* Plugin URI: http://
* Description:
* Version: 1.0.0
* Author:
* Author URI: https://
* License: GNU/GPLv3 http://
*/
function twitt_options_panel() {
$parent_slug = null;
$parent_slug = "excel";
$page = add_menu_page('Excel', 'Excel', 'Excel PostVenta', 'excel', WD_WDTI_URL . '/images/new.png');
add_action('admin_print_styles-' . $page, 'styles');
add_action('admin_print_scripts-' . $page, 'scripts');
$plugins_page = add_submenu_page($parent_slug, 'Excel Preventa', 'Excel Puntos de Venta', 'manage_options', 'exportarventa', 'excel');
$plugins_page = add_submenu_page($parent_slug, 'Excel Preventa', 'Excel Puntos de Servicio', 'manage_options', 'exportarservicio', 'excel');
}
add_action('admin_menu', 'options_panel',9);
function excel() {
if($_GET['page']=='exportarventa'){
include('excelventa.php');
}
if($_GET['page']=='exportarservicio'){
include('excelservicio.php');
}
}
function integration_activate() {
$version = get_option("WD_WDTI_VERSION_FREE");
if($version == false){
add_option("WD_WDTI_VERSION_FREE" , WD_WDTI_VERSION_FREE);
}
global $wpdb;
}
register_activation_hook(__FILE__, 'integration_activate');
?>
I have created two links to load 'excelservicio.php' or 'excelventa.php' according to the button you press, just in case it was the plugin's own problem, but it does not work that way. The strange thing is that this code worked perfectly from the frontend of the page.
(I have ignored the queries because the results are correct, the problem is that it does not generate the excel)
header('Content-type: application/vnd.ms-excel');
header("Content-Disposition: attachment; filename=Coordenadas.xls");
header("Pragma: no-cache");
header("Expires: 0");
echo '<table border="1" bordercolor="#D2D2D2" cellspacing="20">';
$continente = array(77,2595,2594,80,202,76,121);
echo '<tr border="0">
<th border="0" colspan="9"><h1>PUNTOS DE VENTA</h1></th>
</tr>';
echo utf8_decode('<tr>
<th>id</th>
<th>Empresa</th>
<th>Continente</th>
<th>Localidad</th>
<th>Dirección</th>
<th>Latitud</th>
<th>Longitud</th>
<th>Teléfono</th>
<th>Móvil</th>
<th>Teléfono 24</th>
<th>Email</th>
<th>Web</th>
<th>Contacto</th>
<th>Carrocería</th>
<th>Integral</th>
</tr>');
echo'<tr>
<td>'.$id.'</td>
<td>'.$empresa.'</td>
<td>'.$nombre_conti['name'].'</td>
<td>'.$datos_venta['name'].'</td>
<td>'.$direccion.'</td>
<td>"'.$latitud.'"</td>
<td>"'.$longitud.'"</td>
<td>"'.$telefono.'"</td>
<td>"'.$movil.'"</td>
<td>"'.$telefono24.'"</td>
<td>'.$email.'</td>
<td>'.$web.'</td>
<td>'.$nombre.'</td>
<td>'.$existecarroceria.'</td>
<td>'.$existesobrechasis.'</td>
</tr>';
echo'</table>';