Created
April 12, 2020 20:26
-
-
Save gagimilicevic/695f320dbd5d0813370fcc3e9682d49d to your computer and use it in GitHub Desktop.
Content builder helper functions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Register Flexible Content Group | |
* | |
* @since 1.0.0 | |
*/ | |
public function dwply_universalia_builder_register_flexible_content_group() { | |
if( function_exists('acf_add_local_field_group') ): | |
acf_add_local_field_group(array( | |
'key' => 'group_5e7fbfdd8cbaa', | |
'title' => 'Universalia Content Builder', | |
'fields' => array( | |
array( | |
'key' => 'field_5e7fbff316650', | |
'label' => 'Universalia Components', | |
'name' => 'universalia_components', | |
'type' => 'flexible_content', | |
'instructions' => '', | |
'required' => 0, | |
'conditional_logic' => 0, | |
'wrapper' => array( | |
'width' => '', | |
'class' => '', | |
'id' => '', | |
), | |
'layouts' => array(), | |
'button_label' => 'Add Component', | |
'min' => '', | |
'max' => '', | |
), | |
), | |
'location' => array( | |
array( | |
array( | |
'param' => 'post_type', | |
'operator' => '==', | |
'value' => 'post', | |
), | |
), | |
array( | |
array( | |
'param' => 'post_type', | |
'operator' => '==', | |
'value' => 'page', | |
), | |
), | |
), | |
'menu_order' => 0, | |
'position' => 'acf_after_title', | |
'style' => 'default', | |
'label_placement' => 'top', | |
'instruction_placement' => 'label', | |
'hide_on_screen' => array( | |
0 => 'excerpt', | |
1 => 'revisions', | |
2 => 'send-trackbacks', | |
), | |
'active' => true, | |
'description' => '', | |
)); | |
endif; | |
} | |
/** | |
* Register Wysiwyg Component | |
* | |
* @since 1.0.0 | |
*/ | |
public function dwply_universalia_builder_register_wysiwyg_component( $field ) { | |
$layout = array( | |
'key' => 'layout_5e7fc03442a34', | |
'name' => 'dwply_universalia_builder_wysiwyg_component', | |
'label' => 'WYSIWYG Component', | |
'display' => 'block', | |
'sub_fields' => array( | |
array( | |
'key' => 'field_5e80b2fe4b293', | |
'label' => 'Content', | |
'name' => '', | |
'type' => 'tab', | |
'instructions' => '', | |
'required' => 0, | |
'conditional_logic' => 0, | |
'wrapper' => array( | |
'width' => '', | |
'class' => '', | |
'id' => '', | |
), | |
'placement' => 'top', | |
'endpoint' => 0, | |
), | |
array( | |
'key' => 'field_5e7fc05314c22', | |
'label' => 'WYSIWYG Content', | |
'name' => 'wysiwyg_content', | |
'type' => 'wysiwyg', | |
'instructions' => '', | |
'required' => 0, | |
'conditional_logic' => 0, | |
'wrapper' => array( | |
'width' => '', | |
'class' => '', | |
'id' => '', | |
), | |
'default_value' => '', | |
'tabs' => 'all', | |
'toolbar' => 'full', | |
'media_upload' => 1, | |
'delay' => 0, | |
), | |
), | |
'min' => '', | |
'max' => '', | |
); | |
$field = acf_get_field('field_5e7fbff316650'); | |
$field['layouts'][] = $layout; | |
acf_add_local_field($field); | |
acf_update_field($field); | |
} | |
/** | |
* Register List Posts Component | |
* | |
* @since 1.0.0 | |
*/ | |
public function dwply_universalia_builder_register_list_posts_component( $field ) { | |
$layout = array( | |
'key' => 'layout_5e80bff9454c0', | |
'name' => 'dwply_universalia_builder_list_posts_component', | |
'label' => 'List Posts Component', | |
'display' => 'block', | |
'sub_fields' => array( | |
array( | |
'key' => 'field_5e80bff9454c1', | |
'label' => 'Content', | |
'name' => '', | |
'type' => 'tab', | |
'instructions' => '', | |
'required' => 0, | |
'conditional_logic' => 0, | |
'wrapper' => array( | |
'width' => '', | |
'class' => '', | |
'id' => '', | |
), | |
'placement' => 'top', | |
'endpoint' => 0, | |
), | |
array( | |
'key' => 'field_5e80bff9454c2', | |
'label' => 'Title', | |
'name' => 'list_post_component_title', | |
'type' => 'text', | |
'instructions' => '', | |
'required' => 0, | |
'conditional_logic' => 0, | |
'wrapper' => array( | |
'width' => '', | |
'class' => '', | |
'id' => '', | |
), | |
'default_value' => '', | |
'placeholder' => '', | |
'prepend' => '', | |
'append' => '', | |
'maxlength' => '', | |
), | |
array( | |
'key' => 'field_5e80bff9454c3', | |
'label' => 'Post type', | |
'name' => 'list_posts_post_type', | |
'type' => 'dwply_post_type_selector', | |
'instructions' => '', | |
'required' => 0, | |
'conditional_logic' => 0, | |
'wrapper' => array( | |
'width' => '35', | |
'class' => '', | |
'id' => '', | |
), | |
'font_size' => 14, | |
), | |
array( | |
'key' => 'field_5e80debb6b986', | |
'label' => 'Number of posts', | |
'name' => 'list_posts_number_of_posts', | |
'type' => 'number', | |
'instructions' => '', | |
'required' => 0, | |
'conditional_logic' => 0, | |
'wrapper' => array( | |
'width' => '30', | |
'class' => '', | |
'id' => '', | |
), | |
'default_value' => '', | |
'placeholder' => '', | |
'prepend' => '', | |
'append' => '', | |
'min' => '', | |
'max' => '', | |
'step' => '', | |
), | |
array( | |
'key' => 'field_5e8104f7e4e5b', | |
'label' => 'List posts style', | |
'name' => 'list_posts_style', | |
'type' => 'select', | |
'instructions' => '', | |
'required' => 0, | |
'conditional_logic' => 0, | |
'wrapper' => array( | |
'width' => '35', | |
'class' => '', | |
'id' => '', | |
), | |
'choices' => array( | |
'Style 1' => 'Style 1', | |
'Style 2' => 'Style 2', | |
'Style 3' => 'Style 3', | |
), | |
'default_value' => array( | |
), | |
'allow_null' => 0, | |
'multiple' => 0, | |
'ui' => 0, | |
'return_format' => 'value', | |
'ajax' => 0, | |
'placeholder' => '', | |
), | |
array( | |
'key' => 'field_5e8105adf81a9', | |
'label' => 'Archive Settings', | |
'name' => 'archive_settings', | |
'type' => 'group', | |
'instructions' => '', | |
'required' => 0, | |
'conditional_logic' => 0, | |
'wrapper' => array( | |
'width' => '', | |
'class' => '', | |
'id' => '', | |
), | |
'layout' => 'block', | |
'sub_fields' => array( | |
array( | |
'key' => 'field_5e8105daf81aa', | |
'label' => 'Anchor text for post archive', | |
'name' => 'anchor_text_for_post_archive', | |
'type' => 'text', | |
'instructions' => '', | |
'required' => 0, | |
'conditional_logic' => 0, | |
'wrapper' => array( | |
'width' => '50', | |
'class' => '', | |
'id' => '', | |
), | |
'default_value' => '', | |
'placeholder' => '', | |
'prepend' => '', | |
'append' => '', | |
'maxlength' => '', | |
), | |
array( | |
'key' => 'field_5e8116d178eb2', | |
'label' => 'Custom post archive page', | |
'name' => 'custom_post_archive_link', | |
'type' => 'page_link', | |
'instructions' => '', | |
'required' => 0, | |
'conditional_logic' => 0, | |
'wrapper' => array( | |
'width' => '50', | |
'class' => '', | |
'id' => '', | |
), | |
'post_type' => array( | |
0 => 'page', | |
), | |
'taxonomy' => '', | |
'allow_null' => 1, | |
'allow_archives' => 0, | |
'multiple' => 0, | |
), | |
), | |
), | |
), | |
'min' => '', | |
'max' => '', | |
); | |
$field = acf_get_field('field_5e7fbff316650'); | |
$field['layouts'][] = $layout; | |
acf_add_local_field($field); | |
acf_update_field($field); | |
} | |
/** | |
* Add style tab to component | |
* | |
* @since 1.0.0 | |
*/ | |
public function dwply_universalia_builder_add_style_tab( $field ) { | |
$add_style_tab = array( | |
array( | |
'key' => 'field_5e80b30a4b294', | |
'label' => 'Style', | |
'name' => '', | |
'type' => 'tab', | |
'instructions' => '', | |
'required' => 0, | |
'conditional_logic' => 0, | |
'wrapper' => array( | |
'width' => '', | |
'class' => '', | |
'id' => '', | |
), | |
'placement' => 'top', | |
'endpoint' => 0, | |
), | |
array( | |
'key' => 'field_5e80b3134b295', | |
'label' => 'Class name', | |
'name' => 'class_name', | |
'type' => 'text', | |
'instructions' => '', | |
'required' => 0, | |
'conditional_logic' => 0, | |
'wrapper' => array( | |
'width' => '', | |
'class' => '', | |
'id' => '', | |
), | |
'default_value' => '', | |
'placeholder' => '', | |
'prepend' => '', | |
'append' => '', | |
'maxlength' => '', | |
), | |
array( | |
'key' => 'field_5e80b3244b296', | |
'label' => 'ID name', | |
'name' => 'id_name', | |
'type' => 'text', | |
'instructions' => '', | |
'required' => 0, | |
'conditional_logic' => 0, | |
'wrapper' => array( | |
'width' => '', | |
'class' => '', | |
'id' => '', | |
), | |
'default_value' => '', | |
'placeholder' => '', | |
'prepend' => '', | |
'append' => '', | |
'maxlength' => '', | |
), | |
); | |
$field = acf_get_field('field_5e7fbff316650'); | |
$field['layouts']['sub_fields'][] = $add_style_tab; | |
acf_add_local_field($field); | |
acf_update_field($field); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment