LLMS_Abstract_Exportable_Admin_Table::generate_export_file( array $args = array(), string $filename = null, string $type = 'csv' )
Generate an export file for the current table.
Description Description
Parameters Parameters
- $args
-
(array) (Optional) arguments to pass get_results().
Default value: array()
- $filename
-
(string) (Optional) filename of the existing file, if omitted creates a new file, if passed, will continue adding to existing file.
Default value: null
- $type
-
(string) (Optional) export file type for forward compatibility. Currently only accepts 'csv'.
Default value: 'csv'
Return Return
(WP_Error|array)
Source Source
File: includes/abstracts/llms.abstract.exportable.admin.table.php
public function generate_export_file( $args = array(), $filename = null, $type = 'csv' ) { if ( 'csv' !== $type ) { return false; } // always force page 1 regardless of what is requested. Pagination is handled below. $args['page'] = 1; // Boost records / page to speed up generation. $args['per_page'] = apply_filters( 'llms_table_generate_export_file_per_page_boost', 250 ); $filename = $filename ? $filename : $this->get_export_file_name() . '.' . $type; $file_path = LLMS_TMP_DIR . $filename; $option_name = 'llms_gen_export_' . basename( $filename, '.' . $type ); $args = get_option( $option_name, $args ); $handle = @fopen( $file_path, 'a+' ); if ( ! $handle ) { return new WP_Error( 'file_error', __( 'Unable to generate export file, could not open file for writing.', 'lifterlms' ) ); } $delim = apply_filters( 'llms_table_generate_export_file_delimiter', ',', $this, $args ); foreach ( $this->get_export( $args ) as $row ) { fputcsv( $handle, $row, $delim ); } if ( ! $this->is_last_page() ) { $args['page'] = $this->get_current_page() + 1; update_option( $option_name, $args ); $progress = round( ( $this->get_current_page() / $this->get_max_pages() ) * 100, 2 ); } else { delete_option( $option_name ); $progress = 100; } return array( 'filename' => $filename, 'progress' => $progress, 'url' => $this->get_export_file_url( $file_path ), ); }
Expand full source code Collapse full source code View on GitHub
Changelog Changelog
Version | Description |
---|---|
3.28.0 | Introduced. |
User Contributed Notes User Contributed Notes
Permalink: