Skip to content

Instantly share code, notes, and snippets.

@rilwis
Created November 13, 2017 04:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rilwis/46fd5cdf262b9bcc7f7d9b906861796d to your computer and use it in GitHub Desktop.
Save rilwis/46fd5cdf262b9bcc7f7d9b906861796d to your computer and use it in GitHub Desktop.
Cloneable group inheriting values from previous group
<?php
$meta_boxes[] = array(
'title' => __( 'Content blocks' ),
'post_types' => 'page',
'fields' => array(
array(
'id' => 'content-block',
'type' => 'group',
'clone' => true,
'sort_clone' => true,
'collapsible' => true,
'group_title' => array( 'field' => 'select-content-block' ),
'save_state' => true,
'fields' => array(
array(
'id' => 'select-content-block',
'name' => __( 'Create a content block', 'rwmb' ),
'type' => 'select',
'multiple' => false,
'placeholder' => 'Select',
'options' => array(
'text' => 'Freeform text',
'slideshow' => 'Slideshow',
'gallery' => 'Gallery',
'image-and-text' => 'Image and text',
'menu' => 'Menu',
'call-to-action' => 'Call to action',
'products' => 'Product(s)',
)
),
// TEXT
array(
'id' => 'content-block-text',
'type' => 'group',
'visible' => array('select-content-block', '=', 'text'),
'fields' => array(
array(
'id' => 'content-block-text_text-format',
'name' => __( 'Text format', 'rwmb' ),
'type' => 'select',
'multiple' => false,
'placeholder' => 'Select',
'options' => array(
'standard' => 'Standard',
'blockquote' => 'Blockquote'
)
),
array(
'id' => 'content-block-text_text',
'name' => __( 'Text', 'rwmb' ),
'type' => 'wysiwyg',
'options' => array(
'media_buttons' => false,
'textarea_rows' => 5
)
),
array(
'id' => 'content-block-text_text-align',
'name' => __( 'Text align', 'rwmb' ),
'type' => 'select',
'placeholder' => 'Left',
'multiple' => false,
'options' => array(
'ac' => 'Centre',
'ar' => 'Right'
),
'desc' => 'Default is left',
'visible' => array('content-block-text_text-format', '=', 'blockquote'),
),
),
),
// SLIDESHOW
array(
'id' => 'content-block-slideshow',
'type' => 'group',
'visible' => array('select-content-block', '=', 'slideshow'),
'fields' => array(
array(
'id' => 'content-block-slideshow_slideshow-format',
'name' => __( 'Slideshow format', 'rwmb' ),
'type' => 'select',
'placeholder' => 'Select',
'multiple' => false,
'options' => array(
'standard' => 'Standard',
'horizontal' => 'Horizontal scrolling',
'group' => 'Group'
)
),
array(
'id' => 'content-block-slideshow_slideshow-images',
'name' => __( 'Slideshow images', 'rwmb' ),
'type' => 'image_advanced',
'visible' => array (
'when' => array (
array (
'content-block-slideshow_slideshow-format', '=', 'standard',
),
array (
'content-block-slideshow_slideshow-format', '=', 'horizontal'
),
),
'relation' => 'or',
),
),
array(
'id' => 'content-block-slideshow_title',
'name' => __( 'Slideshow title', 'rwmb' ),
'type' => 'text',
'visible' => array (
'when' => array (
array (
'content-block-slideshow_slideshow-format', '=', 'standard',
),
array (
'content-block-slideshow_slideshow-format', '=', 'horizontal'
),
),
'relation' => 'or',
),
),
array(
'id' => 'content-block-slideshow_subtitle',
'name' => __( 'Slideshow subtitle', 'rwmb' ),
'type' => 'text',
'visible' => array (
'when' => array (
array (
'content-block-slideshow_slideshow-format', '=', 'standard',
),
array (
'content-block-slideshow_slideshow-format', '=', 'horizontal'
),
),
'relation' => 'or',
),
),
// Standard
array(
'id' => 'content-block-slideshow_aside',
'name' => __( 'Slideshow aside', 'rwmb' ),
'type' => 'text',
'visible' => array('content-block-slideshow_slideshow-format', '=', 'standard'),
),
array(
'id' => 'content-block-slideshow_title-position',
'name' => __( 'Title / Subtitle position', 'rwmb' ),
'type' => 'select',
'placeholder' => 'Select',
'multiple' => false,
'visible' => array('content-block-slideshow_slideshow-format', '=', 'standard'),
'options' => array(
'top' => 'Top',
'overlay' => 'Overlay'
)
),
array(
'id' => 'content-block-slideshow_description',
'name' => __( 'Slideshow description', 'rwmb' ),
'type' => 'wysiwyg',
'visible' => array('content-block-slideshow_slideshow-format', '=', 'standard'),
'options' => array(
'media_buttons' => false,
'textarea_rows' => 5
)
),
// Horizontal
array(
'id' => 'content-block-slideshow_number_slides_per_row',
'name' => __( 'Number of slides per row', 'rwmb' ),
'type' => 'select',
'multiple' => false,
'placeholder' => 'Select',
'options' => array(
'2' => '2',
'3' => '3',
'4' => '4'
),
'visible' => array('content-block-slideshow_slideshow-format', '=', 'horizontal'),
),
// Group
array(
'id' => 'content-block-slideshow_group-title',
'name' => __( 'Group title', 'rwmb' ),
'type' => 'text',
'placeholder' => 'eg. Featured artists',
'visible' => array('content-block-slideshow_slideshow-format', '=', 'group'),
),
array(
'id' => 'content-block-slideshow_slideshow-format-group',
'type' => 'group',
'clone' => true,
'sort_clone' => true,
'visible' => array('content-block-slideshow_slideshow-format', '=', 'group'),
'fields' => array(
array(
'id' => 'content-block-slideshow_slideshow-format-group_slide-title',
'name' => __( 'Slide title', 'rwmb' ),
'type' => 'text',
'placeholder' => 'eg. Ian McKeever'
),
array(
'id' => 'content-block-slideshow_slideshow-format-group_slide-image',
'name' => __( 'Slideshow image', 'rwmb' ),
'type' => 'image_advanced',
'max_file_uploads' => 1,
),
array(
'id' => 'content-block-slideshow_slideshow-format-group_slide-link',
'name' => __( 'Slideshow link', 'rwmb' ),
'type' => 'select',
'multiple' => false,
'placeholder' => 'Select',
'options' => array(
'page' => 'Page',
'custom' => 'Custom link'
),
),
array(
'id' => 'content-block-slideshow_slideshow-format-group_slide-link-custom',
'name' => __( 'Slide title', 'rwmb' ),
'type' => 'url',
'visible' => array('content-block-slideshow_slideshow-format-group_slide-link', '=', 'custom')
),
array(
'id' => 'content-block-slideshow_slideshow-format-group_slide-link-page',
'name' => __( 'Page to link slide', 'rwmb' ),
'type' => 'select',
'placeholder' => 'Select page',
'options' => $pageoptions,
'visible' => array('content-block-slideshow_slideshow-format-group_slide-link', '=', 'page')
),
),
),
),
),
// GALLERY
array(
'id' => 'content-block-gallery',
'type' => 'group',
'visible' => array('select-content-block', '=', 'gallery'),
'fields' => array(
array(
'id' => 'content-block-gallery_gallery-format',
'name' => __( 'Gallery format', 'rwmb' ),
'type' => 'select',
'placeholder' => 'Select',
'multiple' => false,
'options' => array(
'standard' => 'Standard',
'series-index' => 'Series index'
)
),
// Standard
array(
'id' => 'content-block-gallery_gallery-images',
'name' => __( 'Gallery images', 'rwmb' ),
'type' => 'image_advanced',
'multiple' => true,
'visible' => array('content-block-gallery_gallery-format', '=', 'standard'),
),
array(
'id' => 'content-block-gallery_number-of-columns',
'name' => __( 'Number of columns', 'rwmb' ),
'type' => 'select',
'multiple' => false,
'visible' => array('content-block-gallery_gallery-format', '=', 'standard'),
'placeholder' => 'Select',
'options' => array(
'1' => '1',
'2' => '2',
'3' => '3',
'4' => '4'
)
),
array(
'id' => 'content-block-gallery_gallery-image-format',
'name' => __( 'Gallery image format', 'rwmb' ),
'type' => 'select',
'placeholder' => 'Select',
'multiple' => false,
'visible' => array('content-block-gallery_gallery-format', '=', 'standard'),
'options' => array(
'large' => 'Standard',
'big-square-crop' => 'Square'
)
),
array(
'id' => 'content-block-gallery_include-image-titles',
'name' => __( 'Include image titles?', 'rwmb' ),
'type' => 'checkbox',
'visible' => array('content-block-gallery_gallery-format', '=', 'standard'),
),
array(
'id' => 'content-block-gallery_include-image-captions',
'name' => __( 'Include image captions?', 'rwmb' ),
'type' => 'checkbox',
'visible' => array('content-block-gallery_gallery-format', '=', 'standard'),
),
array(
'id' => 'content-block-gallery_edge-to-edge',
'name' => __( 'Edge-to-edge images?', 'rwmb' ),
'type' => 'checkbox',
'visible' => array('content-block-gallery_gallery-format', '=', 'standard'),
),
array(
'id' => 'content-block-gallery_alt-value-as-link',
'name' => __( 'Use <em>Alt</em> value as link?', 'rwmb' ),
'type' => 'checkbox',
'visible' => array('content-block-gallery_gallery-format', '=', 'standard'),
),
// Series index
array(
'id' => 'content-block-gallery_gallery-format_series-index',
'type' => 'group',
'clone' => true,
'sort_clone' => true,
'name' => 'Series indexes',
'visible' => array('content-block-gallery_gallery-format', '=', 'series-index'),
'fields' => array(
array(
'id' => 'content-block-gallery_gallery-format_series-index_series-title',
'name' => __( 'Index title', 'rwmb' ),
'type' => 'text',
),
array(
'id' => 'content-block-gallery_gallery-format_series-index_images',
'name' => __( 'Index images', 'rwmb' ),
'type' => 'image_advanced',
'multiple' => true
),
array(
'id' => 'content-block-gallery_gallery-format_series-index_number-of-columns',
'name' => __( 'Number of columns', 'rwmb' ),
'type' => 'select',
'multiple' => false,
'placeholder' => 'Select',
'options' => array(
'1' => '1',
'2' => '2',
'3' => '3',
'4' => '4'
)
),
),
),
),
),
// IMAGE AND TEXT
array(
'id' => 'content-block-image-and-text',
'type' => 'group',
'visible' => array('select-content-block', '=', 'image-and-text'),
'fields' => array(
array(
'id' => 'content-block-image-and-text_image-and-text-format',
'name' => __( 'Image and text format', 'rwmb' ),
'type' => 'select',
'multiple' => false,
'placeholder' => 'Select',
'options' => array(
'freeform' => 'Freeform',
'page' => 'Page'
)
),
// Freeform
array(
'id' => 'content-block-image-and-text_freeform-images',
'name' => __( 'Select image', 'rwmb' ),
'type' => 'image_advanced',
'max_file_uploads' => 1,
'multiple' => false,
'visible' => array('content-block-image-and-text_image-and-text-format', '=', 'freeform'),
),
array(
'id' => 'content-block-image-and-text_freeform-text',
'name' => __( 'Text', 'rwmb' ),
'type' => 'wysiwyg',
'options' => array(
'media_buttons' => false,
'textarea_rows' => 5
),
'visible' => array('content-block-image-and-text_image-and-text-format', '=', 'freeform'),
),
// Page
array(
'id' => 'content-block-image-and-text_select_page',
'name' => __( 'Page', 'rwmb' ),
'type' => 'select',
'placeholder' => 'Select page',
'options' => $pageoptions,
'description' => 'Selected page must have a Featured Image and Excerpt to display correctly',
'visible' => array('content-block-image-and-text_image-and-text-format', '=', 'page'),
),
array(
'id' => 'content-block-image-and-text_select_page_use-alternative-title',
'name' => __( 'Use another title?', 'rwmb' ),
'type' => 'checkbox',
'visible' => array('content-block-image-and-text_image-and-text-format', '=', 'page'),
'desc' => 'The page title then becomes a subtitle'
),
array(
'id' => 'content-block-image-and-text_select_page_alternative-title',
'name' => __( 'Alternative title', 'rwmb' ),
'type' => 'text',
'visible' => array('content-block-image-and-text_select_page_use-alternative-title', '=', true),
),
// Globals
array(
'id' => 'content-block-image-and-text_image-and-text-position',
'name' => __( 'Image and text position', 'rwmb' ),
'type' => 'select',
'multiple' => false,
'placeholder' => 'Select',
'options' => array(
'image-left-text-right' => 'Image left text right',
'image-right-text-left' => 'Image right text left',
)
),
array(
'id' => 'content-block-image-and-text_edge-to-edge',
'name' => __( 'Edge-to-edge images?', 'rwmb' ),
'type' => 'checkbox',
),
),
),
// MENU
array(
'id' => 'content-block-menu',
'type' => 'group',
'visible' => array('select-content-block', '=', 'menu'),
'fields' => array(
array(
'id' => 'content-block-menu_menu-format',
'name' => __( 'Menu format', 'rwmb' ),
'type' => 'select',
'multiple' => false,
'placeholder' => 'Select',
'options' => array(
'subpages' => 'Subpages'
)
),
),
),
// CALL TO ACTION
array(
'id' => 'content-block-call-to-action',
'type' => 'group',
'visible' => array('select-content-block', '=', 'call-to-action'),
'fields' => array(
array(
'id' => 'content-block-call-to-action_text',
'name' => __( 'Call to action text', 'rwmb' ),
'type' => 'text'
),
array(
'id' => 'content-block-call-to-action_what-link',
'name' => __( 'Use different text for the link', 'rwmb' ),
'type' => 'checkbox',
'desc' => 'By default the call to action text is used as a link'
),
array(
'id' => 'content-block-call-to-action_text-link',
'name' => __( 'Call to action link text', 'rwmb' ),
'type' => 'text',
'visible' => array('content-block-call-to-action_what-link', '=', true),
),
array(
'id' => 'content-block-call-to-action_link',
'name' => __( 'Call to action link', 'rwmb' ),
'type' => 'text'
),
array(
'id' => 'content-block-call-to-action_text-align',
'name' => __( 'Text align', 'rwmb' ),
'type' => 'select',
'placeholder' => 'Centre',
'multiple' => false,
'options' => array(
'al' => 'Left',
'ar' => 'Right'
),
'desc' => 'Default is centre',
),
),
),
// PRODUCTS
array(
'id' => 'content-block-products',
'type' => 'group',
'visible' => array('select-content-block', '=', 'products'),
'fields' => array(
array(
'id' => '{$prefix}content-block-products_select-products',
'name' => __( 'Select products', 'rwmb' ),
'type' => 'select',
'multiple' => false,
'placeholder' => 'Select',
'options' => array(
'current-artist' => 'Current artist'
)
),
),
),
),
),
),
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment