Columns

Utility functions for the product table columns.

Tags
author

Barn2 Plugins support@barn2.com

license

GPL-3.0

copyright

Barn2 Media Ltd

Table of Contents

$column_replacements  : array<string|int, mixed>
Some column replacements used for correcting misspelled columns.
$column_defaults  : array<string|int, mixed>
Global column defaults.
check_blank_heading()  : string
If the heading equals the keyword 'blank', returns an empty string.
column_defaults()  : array<string|int, mixed>
Get the default column headings and responsive priorities.
get_column_class()  : string
Get the CSS class for a column - will return 'col-<column>' where <column> is the unprefixed column name.
get_column_data_source()  : string
Get the data source value to use in the internal DataTables data.
get_column_heading()  : string
Get the column heading given a column slug.
get_column_name()  : string
Get the column name to use in the 'data-name' value used by DataTables.
get_column_slug()  : string
Get the column slug given a column slug.
get_column_taxonomy()  : false|string
Get the taxonomy for the specified column name.
get_custom_field()  : false|string
Get the custom field from the column name - so 'cf:thing' becomes 'thing'. Returns false if not a custom field column.
get_custom_taxonomy()  : false|string
Get the product attribute from the column name - so 'att:colour' becomes 'colour'. Returns false if not an attribute column.
get_hidden_filter_column()  : false|string
Get the hidden filter from the column name - so 'hf:colour' becomes 'colour'. Returns false if not a hidden filter column.
get_product_attribute()  : false|string
Get the product attribute from the column name - so 'att:colour' becomes 'colour'. Returns false if not an attribute column.
is_custom_field()  : bool
Is the column a custom field?
is_custom_taxonomy()  : bool
Is the column a custom taxonomy?
is_hidden_filter_column()  : bool
Is the column a hidden filter column?
is_product_attribute()  : bool
Is the column a product attribute?
parse_columns()  : array<string|int, mixed>
Parse the supplied columns into an array, whose keys are the column names, and values are the column headings (if specified).
parse_filters()  : array<string|int, mixed>
Parse the supplied filters into an array, whose keys are the filter names, and values are the filter headings (if specified).
parsed_columns_to_string()  : string
Converts an array of columns in the form [ column => heading ] to a comma-separated string.
sanitize_heading()  : string
Sanitizes a column heading.
unprefix_column()  : string
Unprefix a column, removing the 'cf:', 'att:', or 'tax:' prefix from the column name.

Properties

$column_replacements

Some column replacements used for correcting misspelled columns.

public static array<string|int, mixed> $column_replacements = [ 'ID' => 'id', 'SKU' => 'sku', 'title' => 'name', 'content' => 'description', 'excerpt' => 'summary', 'short-description' => 'summary', // back compat: old column name 'category' => 'categories', 'rating' => 'reviews', 'add-to-cart' => 'buy', // back compat: old column name 'modified' => 'date_modified', ]

$column_defaults

Global column defaults.

private static array<string|int, mixed> $column_defaults = false

Methods

check_blank_heading()

If the heading equals the keyword 'blank', returns an empty string.

public static check_blank_heading(string $heading) : string
Parameters
$heading : string
Return values
string

column_defaults()

Get the default column headings and responsive priorities.

public static column_defaults() : array<string|int, mixed>
Return values
array<string|int, mixed>

The column defaults

get_column_class()

Get the CSS class for a column - will return 'col-<column>' where <column> is the unprefixed column name.

public static get_column_class(string $column) : string
Parameters
$column : string
Return values
string

get_column_data_source()

Get the data source value to use in the internal DataTables data.

public static get_column_data_source(string $column) : string
Parameters
$column : string
Return values
string

get_column_heading()

Get the column heading given a column slug.

public static get_column_heading(mixed $column) : string
Parameters
$column : mixed
Return values
string

get_column_name()

Get the column name to use in the 'data-name' value used by DataTables.

public static get_column_name(string $column) : string
Parameters
$column : string
Return values
string

get_column_slug()

Get the column slug given a column slug.

public static get_column_slug(mixed $column) : string
Parameters
$column : mixed
Return values
string

get_column_taxonomy()

Get the taxonomy for the specified column name.

public static get_column_taxonomy(string $column) : false|string
Parameters
$column : string
Return values
false|string

get_custom_field()

Get the custom field from the column name - so 'cf:thing' becomes 'thing'. Returns false if not a custom field column.

public static get_custom_field(string $column) : false|string
Parameters
$column : string
Return values
false|string

get_custom_taxonomy()

Get the product attribute from the column name - so 'att:colour' becomes 'colour'. Returns false if not an attribute column.

public static get_custom_taxonomy(string $column) : false|string
Parameters
$column : string
Return values
false|string

get_hidden_filter_column()

Get the hidden filter from the column name - so 'hf:colour' becomes 'colour'. Returns false if not a hidden filter column.

public static get_hidden_filter_column(string $column) : false|string
Parameters
$column : string
Return values
false|string

get_product_attribute()

Get the product attribute from the column name - so 'att:colour' becomes 'colour'. Returns false if not an attribute column.

public static get_product_attribute(string $column) : false|string
Parameters
$column : string
Return values
false|string

is_custom_field()

Is the column a custom field?

public static is_custom_field(string $column) : bool
Parameters
$column : string
Return values
bool

is_custom_taxonomy()

Is the column a custom taxonomy?

public static is_custom_taxonomy(string $column) : bool
Parameters
$column : string
Return values
bool

is_hidden_filter_column()

Is the column a hidden filter column?

public static is_hidden_filter_column(string $column) : bool
Parameters
$column : string
Return values
bool

is_product_attribute()

Is the column a product attribute?

public static is_product_attribute(string $column) : bool
Parameters
$column : string
Return values
bool

parse_columns()

Parse the supplied columns into an array, whose keys are the column names, and values are the column headings (if specified).

public static parse_columns(string|array<string|int, string> $columns) : array<string|int, mixed>

Invalid taxonomies are removed, but non-standard columns are kept as they could be custom columns. Custom field keys are not validated.

E.g. parse_columns( 'name,summary,price:Cost,tax:product_region:Region,cf:my_field,buy:Order' );

Returns:

[ 'name' => '', 'summary' => '', 'price' => 'Cost', 'tax:product_region' => 'Region', 'cf:my_field' => '', 'buy' => 'Order' ];

Parameters
$columns : string|array<string|int, string>

The columns to parse as a string or array of strings.

Return values
array<string|int, mixed>

The parsed columns.

parse_filters()

Parse the supplied filters into an array, whose keys are the filter names, and values are the filter headings (if specified).

public static parse_filters(bool|string|array<string|int, string> $filters[, array<string|int, string> $table_columns = [] ]) : array<string|int, mixed>

Invalid filter columns and taxonomies are removed. When $filters = true, the filters are based on the table contents and this is specified by passing the columns in the $table_columns arg.

$filters supports the keyword 'attributes' on its own, or alongside other standard filter columns. When present 'attributes' will be replaced by all global attributes and is there a shorthand way to specify all store attributes without listing them individually.

E.g. parse_filters( 'categories:Category,invalid,tags,tax:product_region:Region' );

Returns:

[ 'categories' => 'Category', 'tags' => '', 'tax:product_region' => 'Region' ];

Parameters
$filters : bool|string|array<string|int, string>

The filters to parse as a bool, string or array of strings.

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

The columns to base the filters on when $filters = true.

Return values
array<string|int, mixed>

The parsed filters, or an empty array if the filters are invalid.

parsed_columns_to_string()

Converts an array of columns in the form [ column => heading ] to a comma-separated string.

public static parsed_columns_to_string(array<string|int, mixed> $columns) : string

E.g. parsed_columns_to_string( [ 'name' => 'Title', 'price' => 'Cost per unit', 'stock' => '', 'buy' => '' ); Returns: 'name:Title,price:Cost per unit,stock,buy'

Parameters
$columns : array<string|int, mixed>

The columns and headings array.

Return values
string

The columns combined to a string.

sanitize_heading()

Sanitizes a column heading.

public static sanitize_heading(string $heading) : string
Parameters
$heading : string
Return values
string

unprefix_column()

Unprefix a column, removing the 'cf:', 'att:', or 'tax:' prefix from the column name.

public static unprefix_column(string $column) : string
Parameters
$column : string
Return values
string

Search results