Header sudah dikirim pada plugin khusus (fungsi Ekspor)

Saya telah mengembangkan sebuah plugin dan memiliki fungsi ekspor yang mengekspor data dari wordpress ke csv.. masalahnya adalah pernyataan “Header” menyebabkan “Header sudah terkirim kesalahan”.

Saya telah memeriksa kode saya dan tidak ada html atau apa pun yang dikirim sebelumnya.

kesalahannya berasal dari script-loader.php (output dimulai di /home/test1/public_html/wp-includes/script-loader.php:1403)

Saya telah melihat inti php dan bagian tersebut menunjukkan yang berikut –

function _print_styles() {
global $compress_css;

$wp_styles = wp_styles();

$zip = $compress_css ? 1 : 0;
if ( $zip && defined('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="load%5B%5D=" . implode( '&load%5B%5D=', $concat );

    $href = $wp_styles->base_url . "/wp-admin/load-styles.php?c={$zip}&dir={$dir}&" . $concat . '&ver=" . $ver;
    echo "<link rel="stylesheet' href="" . esc_attr($href) . "" type="text/css" media="all" />\n";

    if ( !empty($wp_styles->print_code) ) {
        echo "<style type="text/css">\n";
        echo $wp_styles->print_code;
        echo "\n</style>\n";
    }
}

if ( !empty($wp_styles->print_html) )
    echo $wp_styles->print_html;

}

Baris tertentu 1403 –

if ( !empty($wp_styles->print_html) )
    echo $wp_styles->print_html;

inilah fungsi saya yang khusus melakukan ekspor.

function process_bulk_action()
{
    global $wpdb;
    $table_name = $wpdb->prefix . 'cj_raffle_tickets'; // do not 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->query("DELETE FROM $table_name WHERE ticketid IN($ids)");
        }
    }
    if ('export' === $this->current_action()) {
            //csv_export();
            //ob_start();

        $output="";                                           //Assigning the variable to store all future CSV file's data
        $result = $wpdb->get_results("SHOW COLUMNS FROM " . $table_name . "");   //Displays all COLUMN NAMES under 'Field' column in records     returned

        if (count($result) > 0) {
            foreach($result as $row) {
                $output = $output . $row->Field . ",";
            }
            $output = substr($output, 0, -1);               //Removing the last separator, because 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 where ticketid IN ($ids)");       //This here
        }

        foreach ($values as $rowr) {
            $fields = array_values((array) $rowr);                  //Getting rid of the keys and using numeric array to get values
            $output .= implode(",", $fields);      //Generating string with field separator
            $output .= "\n";    //Yeah...
        }
        // Download the file        
        $upload_dir = wp_upload_dir();
        $filedir = $upload_dir['path'];
        $filename="ticketssold_" . time() . '.csv';
        if ( ! is_writable( $filedir ) ) {
            wp_die( "<p>Uploads directory is not writable, can't save the file </p>", 'Directory not writable' );
        }
        $handle = fopen( $filedir . "https://wordpress.stackexchange.com/" . $filename, 'w' );

        fwrite( $handle, $output );
        fclose( $handle );
        header( 'Content-Description: File Transfer' );
        header( 'Content-Type: application/octet-stream' );
        header( 'Content-Disposition: attachment; filename=".$filename );
        header( "Content-Transfer-Encoding: binary' );
        header( 'Expires: 0' );
        header( 'Cache-Control: must-revalidate' );
        header( 'Pragma: public' );
        header( 'Content-Length: ' . filesize( $filedir . "https://wordpress.stackexchange.com/" . $filename ) );
        flush();
        readfile( $filedir . "https://wordpress.stackexchange.com/" . $filename );
        exit;
}

Adakah yang bisa membantu saya dengan ini.. Saya telah mencari forum demi forum mencoba segalanya mulai dari ob_clean hingga ob_start, ob_flush dll.

terima kasih Craig.

Leave a Reply

Your email address will not be published. Required fields are marked *