Guest User

Untitled

a guest
Nov 22nd, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. add_filter( '__construct', 'custom__construct' );
  2.  
  3. public function custom__construct( $file, $params = array() ) {
  4. $default_args = array(
  5. 'start_pos' => 0, // File pointer start.
  6. 'end_pos' => -1, // File pointer end.
  7. 'lines' => -1, // Max lines to read.
  8. 'mapping' => array(), // Column mapping. csv_heading => schema_heading.
  9. 'parse' => false, // Whether to sanitize and format data.
  10. 'update_existing' => false, // Whether to update existing items.
  11. 'delimiter' => '~', // CSV delimiter.
  12. 'prevent_timeouts' => true, // Check memory and time usage and abort if reaching limit.
  13. 'enclosure' => '"', // The character used to wrap text in the CSV.
  14. );
  15.  
  16. $this->params = wp_parse_args( $params, $default_args );
  17. $this->file = $file;
  18.  
  19. if ( isset( $this->params['mapping']['from'], $this->params['mapping']['to'] ) ) {
  20. $this->params['mapping'] = array_combine( $this->params['mapping']['from'], $this->params['mapping']['to'] );
  21. }
  22.  
  23. $this->read_file();
  24. }
Add Comment
Please, Sign In to add comment