Bonjour,

J'ai créé un plugin qui récupère des informations et les stockes en base dans une table.
J'ai donc dans le back-office wordpress créé un menu admin portant le nom de mon plugin et affichant la liste des informations avec au dessus un bouton "extraire"
ce bouton devant me retourner toutes les informations au format CSV

Mon bouton créé bien un fichier csv mais dans le fichier j'ai tous mon code HTML généré automatiquement par wordpress...

Avez vous une solution ?

Merci de votre aide.

Voici le code de mon plugin :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
 
register_activation_hook( __FILE__, 'callback_plugin_jeux_concours' );
add_action('admin_menu', 'jeuxConcours');
add_action('init', 'export');
function callback_plugin_jeux_concours(){
	global $wpdb;
	$table_name = "plugin_jeuxConcours_users";
	if($wpdb->get_var("SHOW TABLES LIKE '$table_name'") != $table_name) {
	    $sql = "CREATE TABLE plugin_jeuxConcours_users(id int(255) AUTO_INCREMENT, nom varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci, prenom varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci,email varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci,dateNaissance varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci,sexe varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci,telephone varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci,adresse varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci,cp varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci,ville varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci,etablissement varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci,formation varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci,idConcours int(255),okNewsletter int(2),okPartenaire int(2), PRIMARY KEY ( id ));";
	    require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
	    dbDelta( $sql );
	}
}
function jeuxConcours(){
	add_menu_page('Jeux-concours','Jeux-concours','activate_plugins','jeuxConcours', 'renduJeux', null, 84);
}
function renduJeux(){
 
	if(isset($_POST['panel_submit'])){
		if(!wp_verify_nonce($_POST['panel_noncename'], 'jeuxConcours')){
			die('Token non valide');
		}
		?>
			<div id="message" class="updated fade">
				<p>Sauvegarde effectuée avec succès</p>
			</div>
		<?php
 
	}
	/*RECUP DES INFOS DE LA BASE */
	global $wpdb;
	$sql= "SELECT * FROM plugin_jeuxConcours_users ORDER BY id DESC;";
	$users = $wpdb->get_results($sql);
 
	?>
	<div class="wrap theme-options-page">
	<div id="icon-options-general" class="icon32"><br></div>
		<h2>Participants</h2>
		<form action="" method="post" name="leForm">
			<div class="theme-options-group">
				<table cellspacing="0" class="widefat options-table">
					<thead>
						<tr>
							<th>Nom</th>
							<th>Prenom</th>
							<th>email</th>
							<th>newsletter</th>
							<th>Partenaires</th>
							<th>telephone</th>
							<th>sexe</th>
							<th>Naissance</th>
							<th>Adresse</th>
							<th>Ville</th>
							<th>CP</th>
							<th>Etablissement</th>
							<th>Formation</th>
							<th>Concours concerné</th>
						</tr>
					</thead>
					<tbody>
					<?php
						foreach ($users as $user) {
							echo '<tr>';
							echo '<td>'.$user->nom.'</td>';
							echo '<td>'.$user->prenom.'</td>';
							echo '<td>'.$user->email.'</td>';
							echo '<td>'.$user->okNewsletter.'</td>';
							echo '<td>'.$user->okPartenaire.'</td>';
							echo '<td>'.$user->telephone.'</td>';
							echo '<td>'.$user->sexe.'</td>';
							echo '<td>'.$user->dateNaissance.'</td>';
							echo '<td>'.$user->adresse.'</td>';
							echo '<td>'.$user->ville.'</td>';
							echo '<td>'.$user->cp.'</td>';
							echo '<td>'.$user->etablissement.'</td>';
							echo '<td>'.$user->formation.'</td>';
							echo '<td>'.get_post($user->idConcours)->post_title.'</td>';
							echo'</tr>';
						}
					?>
					</tbody>
				</table>
			</div>
			<input type="hidden" name="panel_noncename" value="<?php echo(wp_create_nonce('jeuxConcours')); ?>" />
			<p class="submit">
			<?php
				$lien = (plugin_dir_path( __FILE__ ) . 'export.php');
				echo $lien;
			?>
				<a href="<?php echo $lien; ?>">ici !!!!</a>
				<input type="submit" name="panel_submit" class="button-primary autowidth" value="Extraire les données" />
			</p>
		</form>
 
	</div>
 
	<?php
}
function export(){
	if(isset($_POST['panel_submit'])){
 
 
		global $wpdb;
 
		$requete = "SELECT nom, prenom  FROM plugin_jeuxConcours_users";  
		$data = $wpdb->get_results($sql);
		$datas = array();  
		foreach($data as $d) {
		  $datas[] = array(
		  	'Nom'	=>	$d->nom,
		  	'Prenom'=>	$d->prenom  
		  );
		}
		$i = 0;
		$retour="";
		foreach ($datas as $v) {
		  	if($i==0){
		  		$retour.= '"'.implode('";"',array_keys($v)).'"'."\n";
		  	}
		  	$retour.= '"'.implode('";"',$v).'"'."\n";
		  	$i++;
		  }  
		$datestamp = date("Y-m-d");  
		$filename = $datestamp."_users.csv";    
 
		header("Content-Disposition: attachment; filename=$filename");  
		header("Content-Type: text/csv;"); 
		echo ($retour);
 
	}
}