File: /storage/v6964/iskcon/public_html/wp-content/themes/tow-temple/tow-settings/pages/social/fields.php
<?php
function tow_register_social_options_metabox() {
/**
* Registers secondary options page, and set main item as parent.
*/
$args = array(
'id' => PREFIX.'_social_options_page',
'title' => 'Social Settings',
'menu_title' => 'Social', // Use menu title, & not title to hide main h2.
'object_types' => array( 'options-page' ),
'option_key' => PREFIX.'_social_options',
'parent_slug' => PREFIX.'_main_options',
'tab_group' => PREFIX.'_main_options',
'tab_title' => 'Social',
'icon_url' => '<i class="bi bi-people text-warning"></i>',
);
// '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 );
/***************** Repeater Start ***********************/
$cmb_options->add_field( array(
'name' => 'Social Media Links',
'desc' => '(You can add multiple links)',
'type' => 'title',
'id' => 'social-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.'-social-links',
'type' => 'group',
// 'repeatable' => false, // use false if you want non-repeatable group
'options' => array(
'group_title' => __( 'Social Media {#}', 'cmb2' ), // since version 1.1.4, {#} gets replaced by row number
'add_button' => __( 'Add Another Social Media', 'cmb2' ),
'remove_button' => __( 'Remove', '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_social_repeatable_titles_js',
) );
$cmb_options->add_group_field( $group_field_id, array(
'name' => 'Name',
'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' => 'Icon',
'id' => 'icon',
'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' => '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 ***********************/
}
add_action( 'cmb2_admin_init', 'tow_register_social_options_metabox' );
function update_social_repeatable_titles_js() {
?>
<script type="text/javascript">
jQuery( function( $ ) {
/***** Global var used for repeater title ********/
$tow_option_page_global_var = $( document.getElementById( 'tow_social_options_page' ) );
});
</script>
<?php
}