CSV_Controller

This class is the controller for the CSV Import

Tags
author

Barn2 Plugins support@barn2.com

license

GPL-3.0

copyright

Barn2 Media Ltd

Table of Contents

$delimiter  : string
The current delimiter for the file being read.
$errors  : array<string|int, mixed>
Errors.
$file  : string
The path to the current file.
$map_preferences  : bool
Whether to use previous mapping selections.
$step  : string
The current import step.
$steps  : array<string|int, mixed>
Progress steps.
__construct()  : mixed
Constructor.
auto_map_user_preferences()  : array<string|int, mixed>
Map columns using the user's lastest import mappings.
get_importer()  : CSV_Importer
Get importer instance.
get_next_step_link()  : string
Get the URL for the next step's screen.
handle_upload()  : string|WP_Error
Handles the CSV upload and initial parsing of the file to prepare for displaying author import options.
import()  : mixed
Import step
is_file_valid_csv()  : bool
Check whether a file is a valid CSV file.
render()  : mixed
Render the current step and show correct view.
upload_form_handler()  : mixed
Handle the upload form and store options.
add_error()  : mixed
Add error message.
auto_map_columns()  : array<string|int, mixed>
Auto map column names.
done()  : mixed
Done step.
get_mapping_options()  : array<string|int, mixed>
Get mapping options.
get_special_columns()  : array<string|int, mixed>
Get special columns.
get_valid_csv_filetypes()  : array<string|int, mixed>
Get all the valid filetypes for a CSV file.
mapping_form()  : mixed
Mapping step.
normalize_columns_names()  : array<string|int, mixed>
Columns to normalize.
output_errors()  : mixed
Add error message.
output_footer()  : mixed
Output footer view.
output_header()  : mixed
Output header view.
output_steps()  : mixed
Output steps view.
sanitize_special_column_name_regex()  : string
Sanitize special column name regex.
upload_form()  : mixed
Output information about the uploading process.
get_acf_custom_fields()  : array<string|int, mixed>
Get ACF custom fields.
get_custom_fields()  : array<string|int, mixed>
Get custom fields.
get_ept_custom_fields()  : array<string|int, mixed>
Get Easy Post Types custom fields.

Properties

$delimiter

The current delimiter for the file being read.

protected string $delimiter = ','
Tags

$errors

Errors.

protected array<string|int, mixed> $errors = []
Tags

$file

The path to the current file.

protected string $file = ''
Tags

$map_preferences

Whether to use previous mapping selections.

protected bool $map_preferences = false
Tags

$steps

Progress steps.

protected array<string|int, mixed> $steps = []
Tags

Methods

__construct()

Constructor.

public __construct() : mixed
Tags
Return values
mixed

auto_map_user_preferences()

Map columns using the user's lastest import mappings.

public auto_map_user_preferences(array<string|int, mixed> $headers) : array<string|int, mixed>
Parameters
$headers : array<string|int, mixed>

Header columns.

Tags
Return values
array<string|int, mixed>

get_importer()

Get importer instance.

public static get_importer(string $file[, array<string|int, mixed> $args = [] ]) : CSV_Importer
Parameters
$file : string

File to import.

$args : array<string|int, mixed> = []

Importer arguments.

Tags
Return values
CSV_Importer

Get the URL for the next step's screen.

public get_next_step_link([string $step = '' ]) : string
Parameters
$step : string = ''

slug (default: current step).

Tags
Return values
string

URL for next step if a next step exists. Admin URL if it's the last step. Empty string on failure.

handle_upload()

Handles the CSV upload and initial parsing of the file to prepare for displaying author import options.

public handle_upload() : string|WP_Error
Tags
Return values
string|WP_Error

import()

Import step

public import() : mixed
Tags
Return values
mixed

is_file_valid_csv()

Check whether a file is a valid CSV file.

public static is_file_valid_csv(string $file[, bool $check_path = true ]) : bool
Parameters
$file : string

File path.

$check_path : bool = true

Whether to also check the file is located in a valid location (Default: true).

Tags
Return values
bool

render()

Render the current step and show correct view.

public render() : mixed
Tags
Return values
mixed

upload_form_handler()

Handle the upload form and store options.

public upload_form_handler() : mixed
Tags
Return values
mixed

add_error()

Add error message.

protected add_error(string $message[, array<string|int, mixed> $actions = [] ]) : mixed
Parameters
$message : string

Error message.

$actions : array<string|int, mixed> = []

List of actions with 'url' and 'label'.

Tags
Return values
mixed

auto_map_columns()

Auto map column names.

protected auto_map_columns(array<string|int, mixed> $raw_headers[, bool $num_indexes = true ]) : array<string|int, mixed>
Parameters
$raw_headers : array<string|int, mixed>

Raw header columns.

$num_indexes : bool = true

If should use numbers or raw header columns as indexes.

Tags
Return values
array<string|int, mixed>

done()

Done step.

protected done() : mixed
Tags
Return values
mixed

get_mapping_options()

Get mapping options.

protected get_mapping_options([string $item = '' ]) : array<string|int, mixed>
Parameters
$item : string = ''

Item name.

Tags
Return values
array<string|int, mixed>

get_special_columns()

Get special columns.

protected get_special_columns(array<string|int, mixed> $columns) : array<string|int, mixed>
Parameters
$columns : array<string|int, mixed>

Raw special columns.

Tags
Return values
array<string|int, mixed>

get_valid_csv_filetypes()

Get all the valid filetypes for a CSV file.

protected static get_valid_csv_filetypes() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed>

mapping_form()

Mapping step.

protected mapping_form() : mixed
Tags
Return values
mixed

normalize_columns_names()

Columns to normalize.

protected normalize_columns_names(array<string|int, mixed> $columns) : array<string|int, mixed>
Parameters
$columns : array<string|int, mixed>

List of columns names and keys.

Tags
Return values
array<string|int, mixed>

output_errors()

Add error message.

protected output_errors() : mixed
Tags
Return values
mixed

Output footer view.

protected output_footer() : mixed
Tags
Return values
mixed

output_header()

Output header view.

protected output_header() : mixed
Tags
Return values
mixed

output_steps()

Output steps view.

protected output_steps() : mixed
Tags
Return values
mixed

sanitize_special_column_name_regex()

Sanitize special column name regex.

protected sanitize_special_column_name_regex(string $value) : string
Parameters
$value : string

Raw special column name.

Tags
Return values
string

upload_form()

Output information about the uploading process.

protected upload_form() : mixed
Tags
Return values
mixed

get_acf_custom_fields()

Get ACF custom fields.

private get_acf_custom_fields(string $post_type) : array<string|int, mixed>
Parameters
$post_type : string
Tags
Return values
array<string|int, mixed>

get_custom_fields()

Get custom fields.

private get_custom_fields(string $post_type) : array<string|int, mixed>
Parameters
$post_type : string
Tags
Return values
array<string|int, mixed>

get_ept_custom_fields()

Get Easy Post Types custom fields.

private get_ept_custom_fields(string $post_type) : array<string|int, mixed>
Parameters
$post_type : string
Tags
Return values
array<string|int, mixed>

Search results