Skip to content

Commit

Permalink
Merge pull request #16 from LeadSoftInc/empty_fields_on_option_page
Browse files Browse the repository at this point in the history
Fixed saving empty fields on option page
  • Loading branch information
kuzmenko1256 authored Jul 25, 2017
2 parents 756de7c + 3b39973 commit 6a70938
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions inc/cmb2-tabs.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ public function __construct() {
* @param $object_type
* @param $field_type_object
*/
public function render( $field_object, $escaped_value, $object_id, $object_type, $field_type_object ) {
public function render( \CMB2_Field $field_object, $escaped_value, $object_id, $object_type, \CMB2_Types $field_type_object ) {
$this->setting = $field_object->args( 'tabs' );
$this->object_id = $object_id;

// Set layout
$layout = empty( $this->setting['layout'] ) ? 'ui-tabs-horizontal' : "ui-tabs-{$this->setting['layout']}";
$default_data = version_compare( CMB2_VERSION, '2.2.2', '>=' ) ? [
$default_data = version_compare( CMB2_VERSION, '2.2.2', '>=' ) ? array(
'class' => "dtheme-cmb2-tabs $layout",
] : $field_type_object->parse_args( $field_object->data_args(), 'tabs', array(
) : $field_type_object->parse_args( $field_object->data_args(), 'tabs', array(
'class' => "dtheme-cmb2-tabs $layout",
) );

Expand All @@ -61,19 +61,19 @@ public function get_tabs() {
ob_start();
?>

<ul>
<ul>
<?php foreach ( $this->setting['tabs'] as $key => $tab ): ?>
<li><a href="#<?php echo $tab['id']; ?>"><?php echo $tab['title']; ?></a></li>
<li><a href="#<?php echo $tab['id']; ?>"><?php echo $tab['title']; ?></a></li>
<?php endforeach; ?>
</ul>
</ul>

<?php foreach ( $this->setting['tabs'] as $key => $tab ): ?>
<div id="<?php echo $tab['id']; ?>">
<div id="<?php echo $tab['id']; ?>">
<?php
// Render fields from tab
$this->render_fields( $this->setting['config'], $tab['fields'], $this->object_id );
?>
</div>
</div>
<?php endforeach;

return ob_get_clean();
Expand Down Expand Up @@ -117,13 +117,19 @@ public static function save( $override_value, $value, $post_id, $data ) {

if ( $CMB2->is_options_page_mb() ) {
$cmb2_options = cmb2_options( $post_id );
$values = $CMB2->get_sanitized_values( $_POST );
foreach ( $values as $key => $value ) {
$cmb2_options->update( $key, $value );
$id_fields = array_map( function( $field ) {
return $field['id'];
}, $tab['fields'] );

foreach ( $_POST as $key => $value ) {
if ( array_search( $key, $id_fields ) !== false ) {
$cmb2_options->update( $key, $value );
}
}
} else {
$CMB2->save_fields();
}
}
}

}

0 comments on commit 6a70938

Please sign in to comment.