I’ve developed a plugin and have an export perform that exports knowledge from wordpress to csv.. the difficulty is that the “Header” assertion is inflicting the “Headers already despatched error”.
I’ve checked by my code and there isn’t any html or something being despatched earlier than hand.
the error is coming from script-loader.php (output began at /residence/test1/public_html/wp-includes/script-loader.php:1403)
I’ve regarded on the core php and the part exhibits the next –
perform _print_styles() {
world $compress_css;
$wp_styles = wp_styles();
$zip = $compress_css ? 1 : 0;
if ( $zip && outlined('ENFORCE_GZIP') && ENFORCE_GZIP )
$zip = 'gzip';
if ( $concat = trim( $wp_styles->concat, ', ' ) ) {
$dir = $wp_styles->text_direction;
$ver = $wp_styles->default_version;
$concat = str_split( $concat, 128 );
$concat = 'loadpercent5Bpercent5D=' . implode( '&loadpercent5Bpercent5D=', $concat );
$href = $wp_styles->base_url . "/wp-admin/load-styles.php?c={$zip}&dir={$dir}&" . $concat . '&ver=' . $ver;
echo "<hyperlink rel='stylesheet' href='" . esc_attr($href) . "' kind='textual content/css' media='all' />n";
if ( !empty($wp_styles->print_code) ) {
echo "<model kind='textual content/css'>n";
echo $wp_styles->print_code;
echo "n</model>n";
}
}
if ( !empty($wp_styles->print_html) )
echo $wp_styles->print_html;
}
Particular line 1403 –
if ( !empty($wp_styles->print_html) )
echo $wp_styles->print_html;
right here is my perform that particularly does the export.
perform process_bulk_action()
{
world $wpdb;
$table_name = $wpdb->prefix . 'cj_raffle_tickets'; // don't forget about tables prefix
if ('delete' === $this->current_action()) {
$ids = isset($_REQUEST['ticketid']) ? $_REQUEST['ticketid'] : array();
if (is_array($ids)) $ids = implode(',', $ids);
if (!empty($ids)) {
$wpdb->question("DELETE FROM $table_name WHERE ticketid IN($ids)");
}
}
if ('export' === $this->current_action()) {
//csv_export();
//ob_start();
$output = ''; //Assigning the variable to retailer all future CSV file's knowledge
$end result = $wpdb->get_results("SHOW COLUMNS FROM " . $table_name . ""); //Shows all COLUMN NAMES beneath 'Subject' column in data returned
if (depend($end result) > 0) {
foreach($end result as $row) {
$output = $output . $row->Subject . ",";
}
$output = substr($output, 0, -1); //Eradicating the final separator, as a result of thats how CSVs work
}
$output .= "n";
$ids = isset($_REQUEST['ticketid']) ? $_REQUEST['ticketid'] : array();
if (is_array($ids)) $ids = implode(',', $ids);
if (!empty($ids)) {
$values = $wpdb->get_results("SELECT * FROM $table_name the place ticketid IN ($ids)"); //This right here
}
foreach ($values as $rowr) {
$fields = array_values((array) $rowr); //Eliminating the keys and utilizing numeric array to get values
$output .= implode(",", $fields); //Producing string with discipline separator
$output .= "n"; //Yeah...
}
// Obtain the file
$upload_dir = wp_upload_dir();
$filedir = $upload_dir['path'];
$filename = 'ticketssold_' . time() . '.csv';
if ( ! is_writable( $filedir ) ) {
wp_die( "<p>Uploads listing isn't writable, cannot save the file </p>", 'Listing not writable' );
}
$deal with = fopen( $filedir . '/' . $filename, 'w' );
fwrite( $deal with, $output );
fclose( $deal with );
header( 'Content material-Description: File Switch' );
header( 'Content material-Sort: utility/octet-stream' );
header( 'Content material-Disposition: attachment; filename='.$filename );
header( 'Content material-Switch-Encoding: binary' );
header( 'Expires: 0' );
header( 'Cache-Management: must-revalidate' );
header( 'Pragma: public' );
header( 'Content material-Size: ' . filesize( $filedir . '/' . $filename ) );
flush();
readfile( $filedir . '/' . $filename );
exit;
}
Can anybody assist me with this.. I’ve searched discussion board after discussion board making an attempt all the pieces from ob_clean to ob_start, ob_flush and so on.
thanks
Craig.