SHOW:
|
|
- or go back to the newest paste.
| 1 | //Create the Catalogue Code File | |
| 2 | function sp_create_catalogues() {
| |
| 3 | ||
| 4 | $terms = get_terms( 'product_cat', | |
| 5 | array( | |
| 6 | 'parent' => 0, | |
| 7 | 'hide_empty' => 1 | |
| 8 | ) | |
| 9 | ); | |
| 10 | $count = count($terms); | |
| 11 | if ($count == 0) return; | |
| 12 | ||
| 13 | $file_options = get_option('sp_file');
| |
| 14 | $shortname = isset( $file_options['catalogues'] ) && !is_null( $file_options['catalogues'] ) ? $file_options['catalogues'] : 'Catalogues.csv'; | |
| 15 | $filename = SP_FILE_PATH .$shortname; | |
| 16 | ||
| 17 | - | header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
|
| 17 | + | |
| 18 | - | header('Content-Description: File Transfer');
|
| 18 | + | |
| 19 | - | header('Content-type: application/octet-stream');
|
| 19 | + | |
| 20 | - | header('"filename=' .$filename .'"');
|
| 20 | + | |
| 21 | - | header("Expires: 0");
|
| 21 | + | $fh = @fopen( $filename, 'w' ); |
| 22 | - | header("Pragma: public");
|
| 22 | + | |
| 23 | fputcsv($fh, $data); | |
| 24 | ||
| 25 | foreach ( $terms as $term ) {
| |
| 26 | // Put the data into the stream | |
| 27 | $data = array(); | |
| 28 | - | $fh = @fopen( 'php://output', 'w' ); |
| 28 | + | |
| 29 | - | |
| 29 | + | |
| 30 | fputcsv($fh, $data); | |
| 31 | ||
| 32 | $children = get_terms( 'product_cat', | |
| 33 | array( | |
| 34 | 'parent' => $term->term_id, | |
| 35 | 'hide_empty' => 1 | |
| 36 | ) | |
| 37 | ); | |
| 38 | ||
| 39 | $count = count($children); | |
| 40 | if ($count > 0) {
| |
| 41 | foreach ( $children as $child ) {
| |
| 42 | $data = array(); | |
| 43 | $data[] = $child->slug; | |
| 44 | $data[] = '> ' .html_entity_decode($child->name); | |
| 45 | fputcsv($fh, $data); | |
| 46 | } | |
| 47 | } | |
| 48 | } | |
| 49 | // Close the file | |
| 50 | fclose($fh); | |
| 51 | - | $data[] = '- ' .html_entity_decode($child->name); |
| 51 | + | $currpage = site_url() .'/wp-admin/tools.php?page=export'; |
| 52 | wp_redirect($currpage); | |
| 53 | // Make sure nothing else is sent, our file is done | |
| 54 | exit; | |
| 55 | } |