Csv_Helper
Shared CSV read/write logic used by both the admin Import/Export page
and the WP-CLI wp top10 counts export|import commands.
Namespace: WebberZone\Top_Ten\Util
Since: 4.3.0
Source: includes/util/class-csv-helper.php line 24
Methods
write_export_csv() static
Write count rows to an open file handle in the Top 10 CSV format.
Writes UTF-8 BOM (for Excel compatibility), a header row, then one data row per result. The positional column layout is:
Overall: Post ID, Visits, Blog ID[, URL] Daily: Post ID, Visits, Date, Blog ID[, URL]
Since: 4.3.0
Line: 47
static public function write_export_csv( $fh, array $rows, bool $daily, bool $include_urls = ..., bool $network_wide = ... ): void;
| Type | Name | Description |
|---|---|---|
resource | $fh | Open file handle (writable). |
array | $rows | Result rows from the database. Each row |
bool | $daily | Whether rows are from the daily table. |
bool | $include_urls | Whether to append a “URL” column. |
bool | $network_wide | Whether this is a network-wide export |
Returns: void
parse_import_file() static
Parse an import CSV file and return structured rows.
Strips any UTF-8 BOM from the beginning of the file, reads the header to auto-detect whether the file targets the overall or daily table (by the presence of a “Date” column), then returns every data row in a canonical associative format.
The caller is responsible for URL resolution, date normalisation, blog filtering, and database writes.
Since: 4.3.0
Line: 109
static public function parse_import_file( string $file_path ): array;
| Type | Name | Description |
|---|---|---|
string | $file_path | Path to the CSV file. |
Returns: array — An associative array with the keys:
fetch_export_data() static
Fetch raw count rows from the database for CSV export.
Called by both the admin Import/Export page and the WP-CLI
wp top10 counts export command.
Since: 4.3.0
Line: 195
static public function fetch_export_data( bool $daily, bool $network_wide = ..., int $blog_id = ..., int $limit = ... ): array;
| Type | Name | Description |
|---|---|---|
bool | $daily | Whether to query the daily table. |
bool | $network_wide | Whether to collect rows from all sites (multisite only). |
int | $blog_id | Specific blog ID (0 = current site). Only used when |
int | $limit | Max rows to return (0 = all). |
Returns: array — Raw result rows (ARRAY_A).