I want to make a custom field for the existing field type color, the default from Siteorigin widget bundle. Basically, what I need to create my own UI and backend logic for the color field type.
As this field is used in many places, if I could override the field type directly, will automatically work in every place.
I searched many times, and also dig through the source code of widgets bundle and SO itself, but couldn't find what I needed, even I tried to load my fields folder with 0 priority (highest) but didn't work. Its still displaying the default color field type.
Can anybody point me to some actions or filters, so that, I can de-register and re-register with the same type color? Or if any other workaround possible?
UPDATE
My question focus is for Siteorigin Widgets Bundle Plugin.
I don't want to just override any style variables, rather want to override existing fields. After some research, I found 2 filters that could be used to override existing field(s):
// Give other plugins a way to modify this form.
$form_options = apply_filters( 'siteorigin_widgets_form_options', $form_options, $this );
$form_options = apply_filters( 'siteorigin_widgets_form_options_' . $this->id_base, $form_options, $this );
The two filters get called in method form_options() in class SiteOrigin_Widget but this method is called like this:
public function form( $instance, $form_type = 'widget' ) {
if( $form_type == 'widget' ) {
if( empty( $this->form_options ) ) {
$this->form_options = $this->form_options();
}
$form_options = $this->form_options;
}
...
...
}
But it looks like $this->form_options is never empty and so, method $this->form_options() is never called which in turn never applies the filters siteorigin_widgets_form_options and siteorigin_widgets_form_options_<id_base>
And thus, my chance of modifying the form fields becomes zero with this approach.
What I basically need is for eg. there is an existing field color and I have another custom field adv-color. Now, the challenge is to override all instance of color field to adv-color and thus every instance of the field is overridden. But, it's still a hope.
Please let me know if my approach is wrong or is there is another way to solve this. Example(s) is/are greatly expected.
I don't see a way to de-register and re-register the
colorfield type (or generator).However, if you want to customize the field's UI (or even completely change its look n' feel), you can create a PHP
classwhich extends one of theseclasses:SiteOrigin_Widget_Field_Base,SiteOrigin_Widget_Field_Text_Input_Base, orSiteOrigin_Widget_Field_Color. See a simple example below:You should then load the
classin/during theinithook in WordPress. Example:And then, to force
colorfields to use the customclass(above), add theclassname prefix to the$prefixesarraybelow:Unfortunately, you can't
unsetor removeSiteOrigin_Widget_Field_Colorfrom theclasslist, because the above filter only allows you to filter theclassname prefixes.But in the example callback above, the custom
My_SiteOrigin_Widget_Field_Colorwould be "seen" first by the SiteOrigin Widgets Bundle plugin; hence,colorfields would use the customclassin place of the default one — i.e.SiteOrigin_Widget_Field_Color.For more details on that, see
SiteOrigin_Widget_Field_Factory::get_class_prefixes()and the entireSiteOrigin_Widget_Field_Factorysource code. AndSiteOrigin_Widget::form().See also:
SiteOrigin_Widget_Field_BaseSiteOrigin_Widget_Field_Text_Input_BaseSiteOrigin_Widget_Field_ColorUPDATE
The following example may help you: (or rather, it worked well for me)
However, even if you set the
colorfields to othertype(e.g.adv_color), you'd still need to create the appropriate PHPclassand then add theclassname prefix via thesiteorigin_widgets_field_class_prefixeshook.