Trait_Has_Icons
Trait for allowing blocks to render icons from a standard set.
Table of Contents
Methods
- get_icon_img() : string
- Returns the HTML for an icon using an IMG element for rendering.
- get_icon_svg() : string
- Returns the HTML for an icon using an SVG element for rendering.
- get_icon_field_schema() : array<string|int, mixed>
- Returns an ACF field schema for the icon field.
- get_icon_location() : array<string|int, mixed>
- Returns icon file location information as an array. The array has the following properties: "path" and "url".
- get_icon_name() : string
- Returns the human readable name of an icon.
- icons() : array<string|int, mixed>
- Returns a keyed array of icons where for each element the key is a unique reference to a particular icon and the value is a human readable icon name.
Methods
get_icon_img()
Returns the HTML for an icon using an IMG element for rendering.
public
get_icon_img([string $base_class = 'example-block' ][, bool $use_default = true ][, string $field_name = 'icon' ]) : string
Parameters
- $base_class : string = 'example-block'
-
(optional) The base string that element classes are appended to.
- $use_default : bool = true
-
(optional) Whether the default icon should be used if the icon field is empty.
- $field_name : string = 'icon'
-
(optional) The name of the field that contains the icon reference. Defaults to "icon".
Return values
string —The icon HTML. Empty string if icon is not set.
get_icon_svg()
Returns the HTML for an icon using an SVG element for rendering.
public
get_icon_svg([string $base_class = 'example-block' ][, bool $use_default = true ][, string $field_name = 'icon' ]) : string
Parameters
- $base_class : string = 'example-block'
-
(optional) The base string that element classes are appended to.
- $use_default : bool = true
-
(optional) Whether the default icon should be used if the icon field is empty.
- $field_name : string = 'icon'
-
(optional) The name of the field that contains the icon reference. Defaults to "icon".
Return values
string —The icon HTML. Empty string if icon is not set.
get_icon_field_schema()
Returns an ACF field schema for the icon field.
protected
get_icon_field_schema(string $key[, bool $include_none = false ][, string $name = 'icon' ]) : array<string|int, mixed>
Parameters
- $key : string
-
The ACF field key.
- $include_none : bool = false
-
(optional) If the choice of no icon should be available. Defaults to false.
- $name : string = 'icon'
-
(optional) The ACF field name. Defaults to "icon".
Return values
array<string|int, mixed> —The ACF field schema.
get_icon_location()
Returns icon file location information as an array. The array has the following properties: "path" and "url".
private
get_icon_location(string $icon) : array<string|int, mixed>
Parameters
- $icon : string
-
The icon name.
Tags
Return values
array<string|int, mixed> —Icon file location information.
get_icon_name()
Returns the human readable name of an icon.
private
get_icon_name(string $icon) : string
Parameters
- $icon : string
-
A unique reference to a particular icon.
Return values
string —The human readable name of an icon or an empty string if $icon is invalid.
icons()
Returns a keyed array of icons where for each element the key is a unique reference to a particular icon and the value is a human readable icon name.
private
icons() : array<string|int, mixed>
Return values
array<string|int, mixed> —A keyed array of icons.