PluginProbe
Timetics – Appointment Booking Calendar & Scheduling / 1.0.49
Timetics – Appointment Booking Calendar & Scheduling v1.0.49
1.0.61 1.0.60 1.0.59 1.0.58 1.0.57 1.0.56 trunk 1.0.0 1.0.1 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 1.0.16 1.0.17 1.0.18 1.0.19 1.0.2 1.0.20 1.0.21 1.0.22 1.0.23 1.0.24 All 62 releases
← All changes | base/csv-reader.php +12 -35 trunk1.0.49 View file →
@@ -38,53 +38,30 @@
38 38 private static function read_file() {
39 39 $file = self::$file;
40 40 $csv_data = [];
41 41
42 - // Initialize WP_Filesystem
43 - global $wp_filesystem;
44 - if ( empty( $wp_filesystem ) ) {
45 - require_once ABSPATH . 'wp-admin/includes/file.php';
46 - WP_Filesystem();
47 - }
42 + $handle = fopen( $file, 'r' );
43 + $headers = fgetcsv( $handle );
48 44
49 - // Read file contents using WP_Filesystem
50 - $contents = $wp_filesystem->get_contents( $file );
51 - if ( false === $contents ) {
52 - return $csv_data;
53 - }
54 -
55 - // Split content into lines
56 - $lines = explode( "\n", $contents );
57 - if ( empty( $lines ) ) {
58 - return $csv_data;
59 - }
60 -
61 - // Parse header row
62 - $headers = str_getcsv( array_shift( $lines ) );
63 45 if ( ! $headers ) {
64 46 return $csv_data;
65 47 }
66 48
67 - $header_count = count( $headers );
49 + if ( $handle !== false ) {
50 + $header_count = count( $headers );
68 51
69 - foreach ( $lines as $line ) {
70 - // Skip empty lines
71 - if ( empty( trim( $line ) ) ) {
72 - continue;
73 - }
52 + while ( ( $data = fgetcsv( $handle ) ) !== false ) {
53 + $row = [];
74 54
75 - $data = str_getcsv( $line );
76 - if ( false === $data ) {
77 - continue;
78 - }
55 + for ( $i = 0; $i < $header_count; $i++ ) {
56 + $row[$headers[$i]] = $data[$i];
57 + }
79 58
80 - $row = [];
81 - for ( $i = 0; $i < $header_count; $i++ ) {
82 - $row[$headers[$i]] = isset( $data[$i] ) ? $data[$i] : '';
59 + $csv_data[] = $row;
83 60 }
61 + }
84 62
85 - $csv_data[] = $row;
86 - }
63 + fclose( $handle );
87 64
88 65 return $csv_data;
89 66 }
90 67 }