name() should include name="" and
* fields are not
*/
if ( ! class_exists( 'Exopite_Simple_Options_Framework_Field_group' ) ) {
class Exopite_Simple_Options_Framework_Field_group extends Exopite_Simple_Options_Framework_Fields {
public function __construct( $field, $value = '', $unique = '', $config = array() ) {
parent::__construct( $field, $value, $unique, $config );
$defaults = array(
'group_title' => esc_attr( 'Group Title', 'exopite-sof' ),
'repeater' => false,
'cloneable' => true,
'sortable' => true,
'accordion' => true,
'closed' => true,
'limit' => 0,
'button_title' => esc_attr( 'Add new', 'exopite-sof' ),
);
$options = ( ! empty( $this->field['options'] ) ) ? $this->field['options'] : array();
$this->field['options'] = wp_parse_args( $options, $defaults );
$this->group_title = ( isset( $this->field['options']['group_title'] ) ) ? $this->field['options']['group_title'] : $defaults['group_title'];
$this->is_repeater = ( isset( $this->field['options']['repeater'] ) ) ? (bool) $this->field['options']['repeater'] : $defaults['repeater'];
$this->is_accordion = ( isset( $this->field['options']['accordion'] ) ) ? (bool) $this->field['options']['accordion'] : $defaults['accordion'];
$this->is_accordion_closed = ( isset( $this->field['options']['closed'] ) ) ? (bool) $this->field['options']['closed'] : $defaults['closed'];
$this->limit = ( isset( $this->field['options']['limit'] ) ) ? (int) $this->field['options']['limit'] : $defaults['limit'];
$this->is_multilang = ( isset( $this->config['is_multilang'] ) ) ? (bool) $this->config['is_multilang'] : false;
if ( ! $this->is_repeater ) {
$this->is_cloneable = false;
$this->is_sortable = false;
} else {
$this->is_cloneable = ( isset( $this->field['options']['cloneable'] ) ) ? (bool) $this->field['options']['cloneable'] : $defaults['cloneable'];
$this->is_sortable = ( isset( $this->field['options']['sortable'] ) ) ? (bool) $this->field['options']['sortable'] : $defaults['sortable'];
}
}
public function output() {
echo $this->element_before();
$unallows = array();
// $unallows = array( 'group' );
// $unallows = array( 'group', 'tab' );
$fields = array_values( $this->field['fields'] );
$unique_id = ( ! empty( $this->unique ) ) ? $this->unique : $this->field['id'];
$multilang_array_index = ( $this->is_multilang ) ? "[{$this->config['multilang']['current']}]" : "";
if ( $this->config['is_options_simple'] ) {
$parent_array = $this->field['id'];
} else {
$parent_array = $this->unique . '[' . $this->field['id'] . ']';
}
if ( $this->is_repeater ) {
if ( $this->config['is_options_simple'] ) {
$base_id = array(
'id' => "{$this->field['id']}[REPLACEME]",
'is_options_simple' => true
);
} else {
$base_id = array(
'id' => $this->unique . $multilang_array_index . '[' . $this->field['id'] . ']' . '[REPLACEME]'
);
}
} else {
if ( $this->config['is_options_simple'] ) {
$base_id = array(
'id' => "{$this->field['id']}",
'is_options_simple' => true
);
} else {
$base_id = array(
'id' => $this->unique . $multilang_array_index . '[' . $this->field['id'] . ']'
);
}
}
$muster_classes = array();
if ( $this->is_repeater ) {
$muster_classes = array( 'exopite-sof-cloneable__muster', 'exopite-sof-cloneable__muster--hidden' );
if ( $this->is_accordion ) {
$muster_classes[] = 'exopite-sof-accordion--hidden';
$muster_classes[] = 'exopite-sof-accordion__item';
}
} else {
if ( $this->is_accordion ) {
$muster_classes[] = 'exopite-sof-accordion__item';
if ( $this->is_accordion_closed ) {
$muster_classes[] = 'exopite-sof-accordion--hidden';
}
}
}
$limit = $this->limit;
$sortable = $this->is_sortable;
$classes = array( 'exopite-sof-group' );
if ( $this->is_accordion ) {
$classes[] = 'exopite-sof-accordion';
}
echo '
';
$wrapper_classes = array( 'exopite-sof-accordion__wrapper' );
if ( $this->is_accordion && ! $this->is_repeater ) {
echo '
';
}
echo '
';
if ( $this->is_repeater || ! empty( $this->group_title ) ) {
echo '
' . $this->group_title . '';
if ( $this->is_repeater ) {
echo '';
if ( $sortable ) {
echo '';
}
if ( $this->is_cloneable ) {
echo '';
}
echo '';
echo '';
}
echo '
';
}
echo '
';
$self = new Exopite_Simple_Options_Framework( $base_id, null );
$self->config['multilang'] = $this->config['multilang'];
$num = 0;
foreach ( $fields as $field ) {
if ( in_array( $field['type'], $unallows ) ) {
$field['_notice'] = true;
continue;
}
$class = 'Exopite_Simple_Options_Framework_Field_' . $field['type'];
if ( $this->config['is_options_simple'] ) {
$field['is_options_simple'] = true;
}
$field['sub'] = true;
$field_default = ( isset( $field['default'] ) ) ? $field['default'] : '';
// Set repeater default field fields as disabled,
// to prevent save them.
// If repeater, template field has no values
if ( $this->is_repeater ) {
$field_value = null;
$field_attributes = array(
'disabled' => 'only-key',
);
if ( isset( $field['attributes'] ) && is_array( $field['attributes'] ) ) {
$field['attributes'] += $field_attributes;
} else {
$field['attributes'] = $field_attributes;
}
} else {
if ( is_serialized( $this->value ) ) {
$this->value = unserialize( $this->value );
}
$field_value = ( isset( $field['id'] ) && isset( $this->value[ $field['id'] ] ) ) ? $this->value[ $field['id'] ] : '';
$field_value = ( $this->is_repeater ) ? null : $field_value;
}
$self->add_field( $field, $field_value );
$num ++;
}
echo '
'; // exopite-sof-cloneable-content
echo '
'; // exopite-sof-cloneable__item
if ( $this->is_accordion && ! $this->is_repeater ) {
echo '
'; // exopite-sof-accordion__wrapper
}
// IF REPEATER
if ( $this->field['options']['repeater'] ) {
$classes = array( 'exopite-sof-cloneable__wrapper', 'exopite-sof-accordion__wrapper' );
if ( isset( $this->field['options']['mode'] ) && $this->field['options']['mode'] == 'compact' ) {
$classes[] = 'exopite-sof-group-compact';
}
if ( isset( $this->config['type'] ) && $this->config['type'] == 'metabox' && isset( $this->config['options'] ) && $this->config['options'] == 'simple' ) {
echo '
';
} else {
$data_multilang = ( $this->config['multilang'] ) ? true : false;
echo '
';
}
if ( $this->value ) {
if ( $this->config['is_options_simple'] ) {
if ( is_serialized( $this->value ) ) {
$this->value = unserialize( $this->value );
}
}
$num = 0;
foreach ( $this->value as $key => $value ) {
/**
* If multilang, then
* - check if first element is current language is exist
* - is a string (if changed from single language) but not current language
* then skip.
* (without this check group will display from other languages elements as empty)
*/
echo '
';
echo '
' . $this->field['options']['group_title'] . '';
echo '';
if ( $sortable ) {
echo '';
}
if ( $this->is_cloneable ) {
echo '';
}
echo '';
echo '';
echo '
';
echo '
';
if ( $this->config['is_options_simple'] ) {
$self->unique = $this->field['id'] . '[' . $num . ']';
} else {
$self->unique = $this->unique . $multilang_array_index . '[' . $this->field['id'] . '][' . $num . ']';
}
foreach ( $fields as $field ) {
$field['sub'] = true;
if ( $this->config['is_options_simple'] ) {
$field['is_options_simple'] = true;
}
if ( in_array( $field['type'], $unallows ) ) {
continue;
}
$value = ( isset( $this->value[ $num ][ $field['id'] ] ) ) ? $this->value[ $num ][ $field['id'] ] : '';
$self->add_field( $field, $value );
}
echo '
'; // exopite-sof-cloneable__content
echo '
'; // exopite-sof-cloneable__item
$num ++;
}
}
echo '
'; // exopite-sof-cloneable__wrapper
echo '
' . esc_attr__( '最多数量:', 'exopite-sof' ) . ' ' . $this->field['options']['limit'] . '个
';
echo '
' . $this->field['options']['button_title'] . '';
}
echo '
'; // exopite-sof-group
echo $this->element_after();
}
}
}