I. Add element
To create new elements for AZP builder you have to hook into azp_register_elements filter with AZP core elements array and return your new elements array. You can place the code in child theme or other plugin.
You can add new element by add new item to the $new_elements array with key is your element type (contains only a-zA-Z0-9 and _ characters. Example: azp_shortcode ). And new item value is an array contains its cofiguration values).
II. Element parameters
This is a list of element parameters:
- name (string): name of the element
- desc (string): element description text
- category (string): this text will be used in filter tab on elements selector window. Default: content, structure, social. You can also add your new one.
- open_settings_on_create (bool): whether to show element settings window after element is added to page or nor.
- showStyleTab (bool): show Style settings tab or not
- showTypographyTab (bool): show Typography settings tab or not
- showAnimationTab (bool): show Animation settings tab or not
- icon (string): element icon url
- template_path (string): absolute path of template file which will use to output the element content. Note: You can omit this param, then the builder will looking in azp_templates folder on your theme for template file.
- attrs (array): is an array contains arrays of element attributes.
When done your new element will appear in elements selector and element settings window like screenshots bellow:
III. Element template
Is this so easy? Yes, it’s incredible easy.
Now the left thing is create a .php file which will output the element content. In the code above we do not declare template_path value so /azp_templates/azp_shortcode.php file in your current theme folder will be used.
When the template file is load by AZP, $azp_attrs, $azp_content and $azp_element variables are passed to the file.
- $azp_attrs (array): is a key/value pair array for element settings ( from attrs array when you define the element ) with key is param_name value. In the template file we will extract it as element parameter variables.
- $azp_content (string): contains content value for the element. Which is value of field with “param_name”=>”content” and “iscontent”=>”yes”.
- $azp_element (string): is element type (key in the $elements variable – azp_shortcode for this element ).
That’s all you need to create new element for AZP builder. We think it’s the simplest, easiest and fastest way.