AbstractCustomizePanel
in package
An abstract implementation of a panel in WP customize.
The main purpose of this abstract class is the following layer:
- It creates a main panel
- That panel can contain multiple sections
- A section contains multiple controls
- A control holds a single setting
If you need a more specific setting override the customize_register method!
Table of Contents
Constants
- WEB_SAFE_FONT_FAMILY = ['Georgia, serif', '"Palatino Linotype", "Book Antiqua", Palatino, serif', '"Times New Roman", Times, serif', 'Arial, Helvetica, sans-serif', '"Arial Black", Gadget, sans-serif', '"Comic Sans MS", cursive, sans-serif', 'Impact, Charcoal, sans-serif', '"Lucida Sans Unicode", "Lucida Grande", sans-serif', 'Tahoma, Geneva, sans-serif', '"Trebuchet MS", Helvetica, sans-serif', 'Verdana, Geneva, sans-serif', '"Courier New", Courier, monospace', '"Lucida Console", Monaco, monospace']
- Cross-browser compatible font families.
Properties
- $manager : WP_Customize_Manager
- The manager received through customize_register.
- $name : string
- The name of this panel.
- $panel : string
- The main panel ID.
- $sections : array<string|int, mixed>
- Cached sections definition.
Methods
- __construct() : mixed
- C'tor.
- customize_register() : mixed
- Add cookie banner section. If you need a more granular customization you can safely override this method!
- enableOptionsAutoload() : mixed
- Write defaults to database via `add_option` to avoid performance issues with `get_option` (autoload).
- getManager() : mixed
- Get manager.
- getName() : mixed
- Get name.
- getPanel() : mixed
- Get main panel id.
- getSections() : mixed
- Return sections for this panel with caching mechanism.
- getSetting() : mixed
- Get value of a setting. Unfortunately, getting the managers' settings does not work as expected because they are only available in customize, and not in frontend. We need to reconstruct the #value method.
- getUrl() : mixed
- Get the live preview url with autofocus.
- gotUpdated() : mixed
- Check depending on the `$response` of `customize_save_response` hook if a specific prefix got changed.
- localizeDefaultValues() : mixed
- Localize for frontend (customize defaults so they can be resetted)
- localizeIds() : mixed
- Localize for frontend (registered panel, section and setting IDs).
- localizeValues() : mixed
- Localize for frontend (customize values)
- resolveSections() : array<string|int, mixed>
- Return sections for this panel. Do not directly use this, use `getSections` instead.
- sanitize_checkbox() : bool
- Sanitize boolean for checkbox. Note: We need to sanitize the value to "y" or "n".
- controlDefaults() : array<string|int, mixed>
- Override this for default control arguments.
- getPanelArgs() : array<string|int, mixed>
- Return main arguments for this panel.
- getSkipControlClasses() : array<string|int, string>
- Override this for default overrides arguments.
- registerSections() : mixed
- Register sections from the dynamic array.
- sectionDefaults() : array<string|int, mixed>
- Override this for default section arguments.
- settingDefaults() : array<string|int, mixed>
- Override this for default setting arguments.
Constants
WEB_SAFE_FONT_FAMILY
Cross-browser compatible font families.
public
mixed
WEB_SAFE_FONT_FAMILY
= ['Georgia, serif', '"Palatino Linotype", "Book Antiqua", Palatino, serif', '"Times New Roman", Times, serif', 'Arial, Helvetica, sans-serif', '"Arial Black", Gadget, sans-serif', '"Comic Sans MS", cursive, sans-serif', 'Impact, Charcoal, sans-serif', '"Lucida Sans Unicode", "Lucida Grande", sans-serif', 'Tahoma, Geneva, sans-serif', '"Trebuchet MS", Helvetica, sans-serif', 'Verdana, Geneva, sans-serif', '"Courier New", Courier, monospace', '"Lucida Console", Monaco, monospace']
Tags
Properties
$manager
The manager received through customize_register.
private
WP_Customize_Manager
$manager
$name
The name of this panel.
private
string
$name
$panel
The main panel ID.
private
string
$panel
$sections
Cached sections definition.
private
array<string|int, mixed>
$sections
Methods
__construct()
C'tor.
public
__construct(string $panel, string $name) : mixed
Parameters
- $panel : string
-
The main panel ID.
- $name : string
-
The name of this panel, e. g. "banner". This is needed for frontend localization
customize_register()
Add cookie banner section. If you need a more granular customization you can safely override this method!
public
customize_register(WP_Customize_Manager $wp_customize) : mixed
Parameters
- $wp_customize : WP_Customize_Manager
enableOptionsAutoload()
Write defaults to database via `add_option` to avoid performance issues with `get_option` (autoload).
public
enableOptionsAutoload() : mixed
Tags
getManager()
Get manager.
public
getManager() : mixed
Tags
getName()
Get name.
public
getName() : mixed
Tags
getPanel()
Get main panel id.
public
getPanel() : mixed
Tags
getSections()
Return sections for this panel with caching mechanism.
public
getSections([bool $force = false ]) : mixed
Parameters
- $force : bool = false
getSetting()
Get value of a setting. Unfortunately, getting the managers' settings does not work as expected because they are only available in customize, and not in frontend. We need to reconstruct the #value method.
public
getSetting(string $id[, bool $resolve = true ]) : mixed
Parameters
- $id : string
-
The unique ID of the setting
- $resolve : bool = true
-
If
false
, it returns always the default values
Tags
getUrl()
Get the live preview url with autofocus.
public
getUrl() : mixed
gotUpdated()
Check depending on the `$response` of `customize_save_response` hook if a specific prefix got changed.
public
static gotUpdated(array<string|int, mixed> $response, string $prefix) : mixed
Parameters
- $response : array<string|int, mixed>
- $prefix : string
localizeDefaultValues()
Localize for frontend (customize defaults so they can be resetted)
public
localizeDefaultValues([string $skipControlClasses = [] ]) : mixed
Parameters
- $skipControlClasses : string = []
localizeIds()
Localize for frontend (registered panel, section and setting IDs).
public
localizeIds() : mixed
localizeValues()
Localize for frontend (customize values)
public
localizeValues([string $skipControlClasses = [] ]) : mixed
Parameters
- $skipControlClasses : string = []
resolveSections()
Return sections for this panel. Do not directly use this, use `getSections` instead.
public
abstract resolveSections() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed> —Documentation follows soon, in the meantime have a look at Real Cookie Banner implementation
sanitize_checkbox()
Sanitize boolean for checkbox. Note: We need to sanitize the value to "y" or "n".
public
static sanitize_checkbox(bool $checked) : bool
Parameters
- $checked : bool
-
Whether or not a box is checked.
Tags
Return values
boolcontrolDefaults()
Override this for default control arguments.
protected
controlDefaults() : array<string|int, mixed>
Return values
array<string|int, mixed>getPanelArgs()
Return main arguments for this panel.
protected
abstract getPanelArgs() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed>getSkipControlClasses()
Override this for default overrides arguments.
protected
getSkipControlClasses() : array<string|int, string>
Return values
array<string|int, string>registerSections()
Register sections from the dynamic array.
protected
registerSections(array<string|int, mixed> $sections) : mixed
Parameters
- $sections : array<string|int, mixed>
-
Result of getSections
sectionDefaults()
Override this for default section arguments.
protected
sectionDefaults() : array<string|int, mixed>
Return values
array<string|int, mixed>settingDefaults()
Override this for default setting arguments.
protected
settingDefaults() : array<string|int, mixed>