File: /storage/v6964/iskcon/public_html/wp-content/themes/tow-temple/tow-settings/pages/header/fields.php
<?php
function tow_register_header_options_metabox() {
/**
* Registers secondary options page, and set main item as parent.
*/
$args = array(
'id' => PREFIX.'_header_options_page',
'title' => 'Header Settings',
'menu_title' => 'Header', // Use menu title, & not title to hide main h2.
'object_types' => array( 'options-page' ),
'option_key' => PREFIX.'_header_options',
'parent_slug' => PREFIX.'_main_options',
'tab_group' => PREFIX.'_main_options',
'tab_title' => 'Header',
'icon_url' => '<i class="bi bi-bounding-box text-warning"></i>',
'rows_limit' => 3,
);
// 'tab_group' property is supported in > 2.4.0.
if ( version_compare( CMB2_VERSION, '2.4.0' ) ) {
$args['display_cb'] = 'tow_page_display';
}
$cmb_options = new_cmb2_box( $args );
// Accordion Start (before fields)
$cmb_options->add_field( array(
'name' => '',
'id' => 'accordion_start',
'type' => 'title',
'before_row' => '
<div class="accordion" id="header-settings">',
'after_row' => ''
) );
/*********** Strat Items 1*********************/
$cmb_options->add_field( array(
'name' => '',
'id' => 'accordion_item-1',
'type' => 'title',
'before_row' => '
<div class="accordion-item">
<h2 class="accordion-header">
<button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#item-1" aria-expanded="false" aria-controls="item-1">
<div class="d-flex flex-column"><span class="fs-6 d-block">HEADER TOP</span> <span class="fs-6 fw-normal">Click to set header top settings</span></div>
</button>
</h2>
<div id="item-1" class="accordion-collapse collapse" data-bs-parent="#header-settings">
<div class="accordion-body">',
'after_row' => ''
) );
/********** Fields Start ************/
$cmb_options->add_field( array(
'name' => 'Show header top',
'id' => PREFIX.'-header-top-show',
'type' => 'radio_inline',
'options' => array(
1 => __( 'Yes', 'cmb2' ),
0 => __( 'No', 'cmb2' ),
),
'default' => 1,
) );
$cmb_options->add_field( array(
'name' => 'Show social icons',
'id' => PREFIX.'-header-top-social-show',
'type' => 'radio_inline',
'options' => array(
1 => __( 'Yes', 'cmb2' ),
0 => __( 'No', 'cmb2' ),
),
'default' => 1,
) );
$cmb_options->add_field( array(
'name' => 'Show social icons',
'id' => PREFIX.'-header-top-social-show',
'type' => 'radio_inline',
'options' => array(
1 => __( 'Yes', 'cmb2' ),
0 => __( 'No', 'cmb2' ),
),
'default' => 1,
) );
$cmb_options->add_field( array(
'name' => 'Phone number',
'id' => PREFIX.'-header-top-phone',
'type' => 'text',
'desc' => 'Phone number show on top',
'default' => '123 4567 890',
) );
$cmb_options->add_field( array(
'name' => 'Email',
'id' => PREFIX.'-header-top-email',
'type' => 'text',
'desc' => 'Email show on top',
'default' => 'info@gmail.com',
) );
$cmb_options->add_field( array(
'name' => 'Show middle links section',
'id' => PREFIX.'-header-top-middle-show',
'type' => 'radio_inline',
'options' => array(
1 => __( 'Yes', 'cmb2' ),
0 => __( 'No', 'cmb2' ),
),
'default' => 1,
) );
/***************** Repeater Start ***********************/
$cmb_options->add_field( array(
'name' => 'Middle section links',
'desc' => '(Add multiple links in header top middle section)',
'type' => 'title',
'id' => 'header-top-middle-section-links-row-start',
'before_row' => '
<div class="row">
<div class="col-sm-3">
',
'after_row' => '</div><div class="col-sm-9">'
) );
$group_field_id = $cmb_options->add_field( array(
'id' => PREFIX.'-header-top-middle-section-links',
'type' => 'group',
// 'repeatable' => false, // use false if you want non-repeatable group
'options' => array(
'group_title' => __( 'Link {#}', 'cmb2' ), // since version 1.1.4, {#} gets replaced by row number
'add_button' => __( 'Add Another Link', 'cmb2' ),
'remove_button' => __( 'Remove Link', 'cmb2' ),
'sortable' => true,
'closed' => true, // true to have the groups closed by default
// 'remove_confirm' => esc_html__( 'Are you sure you want to remove?', 'cmb2' ), // Performs confirmation before removing group.
),
'after_group' => 'update_repeatable_titles_js',
) );
$cmb_options->add_group_field( $group_field_id, array(
'name' => 'Link Title',
'id' => 'title',
'type' => 'text',
// 'repeatable' => true, // Repeatable fields are supported w/in repeatable groups (for most types)
) );
$cmb_options->add_group_field( $group_field_id, array(
'name' => 'Link Url',
'id' => 'url',
'type' => 'text',
// 'repeatable' => true, // Repeatable fields are supported w/in repeatable groups (for most types)
) );
$cmb_options->add_field( array(
'name' => '',
'type' => 'title',
'id' => 'header-top-middle-section-links-row-end',
'after_row' => '</div></div>'
) );
/***************** Repeater Ends ***********************/
/********** Fields Ends ************/
$cmb_options->add_field( array(
'name' => '',
'id' => 'accordion_end-1',
'type' => 'title',
'before_row' => '',
'after_row' => '</div></div></div>'
) );
/************** End Items 1 *******************************/
/*********** Strat Items 2*********************/
$cmb_options->add_field( array(
'name' => '',
'id' => 'accordion_item-2',
'type' => 'title',
'before_row' => '
<div class="accordion-item">
<h2 class="accordion-header">
<button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#item-2" aria-expanded="false" aria-controls="item-2">
<div class="d-flex flex-column"><span class="fs-6 d-block">MAIN HEADER</span> <span class="fs-6 fw-normal">Click to set main header settings</span></div>
</button>
</h2>
<div id="item-2" class="accordion-collapse collapse" data-bs-parent="#header-settings">
<div class="accordion-body">',
'after_row' => ''
) );
/********** Fields Start ************/
$cmb_options->add_field( array(
'name' => 'Header',
'id' => PREFIX.'-header-show',
'type' => 'radio_inline',
'options' => array(
1 => __( 'Show', 'cmb2' ),
0 => __( 'Hide', 'cmb2' ),
),
'default' => 1,
) );
$cmb_options->add_field( array(
'name' => 'Search Icon ( Right Side )',
'id' => PREFIX.'-header-search',
'type' => 'radio_inline',
'options' => array(
1 => __( 'Show', 'cmb2' ),
0 => __( 'Hide', 'cmb2' ),
),
'default' => 1,
) );
$cmb_options->add_field( array(
'name' => 'Shopping Cart Icon ( Right Side )',
'id' => PREFIX.'-header-cart',
'type' => 'radio_inline',
'options' => array(
1 => __( 'Show', 'cmb2' ),
0 => __( 'Hide', 'cmb2' ),
),
'default' => 1,
) );
$cmb_options->add_field( array(
'name' => 'Background Color',
'desc' => 'Click to select color',
'id' => 'header_bg_color',
'type' => 'colorpicker',
'default' => '#ffffff',
'options' => array(
'alpha' => true // Make this a rgba color picker.
),
) );
/********** Fields Ends ************/
$cmb_options->add_field( array(
'name' => '',
'id' => 'accordion_end-2',
'type' => 'title',
'before_row' => '',
'after_row' => '</div></div></div>'
) );
/************** End Items 1 *******************************/
$cmb_options->add_field( array(
'name' => '',
'id' => 'accordion_end',
'type' => 'title',
'before_row' => '',
'after_row' => '</div>'
) );
}
add_action( 'cmb2_admin_init', 'tow_register_header_options_metabox' );
function update_repeatable_titles_js() {
//add_action( is_admin() ? 'admin_footer' : 'wp_footer', 'add_js_for_update_repeatable_titles_to_footer' );
?>
<script type="text/javascript">
jQuery( function( $ ) {
/***** Global var used for repeater title ********/
$tow_option_page_global_var = $( document.getElementById( 'tow_header_options_page' ) );
});
</script>
<?php
}