Download the PHP package wptrt/control-color-alpha without Composer
On this page you can find all versions of the php package wptrt/control-color-alpha. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download wptrt/control-color-alpha
More information about wptrt/control-color-alpha
Files in wptrt/control-color-alpha
Package control-color-alpha
Short Description Color control for the WordPress Customizer with RGBA support.
License GPL-2.0-or-later
Homepage https://github.com/WPTRT/control-color-alpha
Informations about the package control-color-alpha
WPTRT color-alpha
Control
A color control for the WordPress Customizer with support for alpha channel.
This is a customizer control using the react-color colorpicker.
The control will save either a HEX value (#000000
) or RGBA (rgba(0,0,0,0.9)
) depending on the opacity of the selected color. If the color is completely opaque, then it will save a HEX value. If the selected color is not completely opaque (has an alpha value smaller than 1) then the value will be saved as RGBA.
Usage
Registering the Control
This is a control containing a JS template. As such, it should be whitelisted in the Customizer. To do that we can use the WP_Customize_Manager::register_control_type
method:
After we register the control using the above code, we can use it in the customizer using the Customizer API:
Available filters
wptrt_color_picker_alpha_url
You can use this filter to change the URL for control assets. By default the control will work out of the box for any plugins and themes installed in wp-content/themes
and wp-content/plugins
respectively. It is possible however to change the URL by using the wptrt_color_picker_alpha_url
filter:
Sanitization
All controls in the WordPress Customizer should have a sanitize_callback defined. You can write your own function and use it as a sanitization callback, or use the example function below:
Advanced Usage
This control allows you to save the value as either a string
or an array
. The default behavior is to save a string
, but you can easily alter that by using the choices
argument in the control:
The value will then be saved using a format like this:
Array Sanitization
If you choose to save the value of this control as an array
, then you will need to change the sanitization function for this setting. You can write your own, or use the one below.
Autoloading
You'll need to use an autoloader with this. Ideally, this would be Composer. However, we have a basic autoloader available to include with themes if needed.
Composer
From the command line:
WPTRT Autoloader
If using the WPTRT autoloader, use the following code: