field, array(
'max' => 0,
'min' => 0,
'fields' => array(),
'button_title' => esc_html__( 'Add New', 'sakurairo_csf' ),
'accordion_title_prefix' => '',
'accordion_title_number' => false,
'accordion_title_auto' => true,
'accordion_title_by' => array(),
'accordion_title_by_prefix' => ' ',
) );
$title_prefix = ( ! empty( $args['accordion_title_prefix'] ) ) ? $args['accordion_title_prefix'] : '';
$title_number = ( ! empty( $args['accordion_title_number'] ) ) ? true : false;
$title_auto = ( ! empty( $args['accordion_title_auto'] ) ) ? true : false;
$title_first = ( isset( $this->field['fields'][0]['id'] ) ) ? $this->field['fields'][0]['id'] : $this->field['fields'][1]['id'];
$title_by = ( is_array( $args['accordion_title_by'] ) ) ? $args['accordion_title_by'] : (array) $args['accordion_title_by'];
$title_by = ( empty( $title_by ) ) ? array( $title_first ) : $title_by;
$title_by_prefix = ( ! empty( $args['accordion_title_by_prefix'] ) ) ? $args['accordion_title_by_prefix'] : '';
if ( preg_match( '/'. preg_quote( '['. $this->field['id'] .']' ) .'/', $this->unique ) ) {
echo '
'. esc_html__( 'Error: Field ID conflict.', 'sakurairo_csf' ) .'
';
} else {
echo $this->field_before();
echo '';
echo '
';
echo '';
echo '';
echo '';
echo '
';
echo '
';
echo '';
echo ( $title_number ) ? '' : '';
echo ( $title_prefix ) ? ''. esc_attr( $title_prefix ) .'' : '';
echo ( $title_auto ) ? '' : '';
echo '';
echo '
';
echo '
';
foreach ( $this->field['fields'] as $field ) {
$field_default = ( isset( $field['default'] ) ) ? $field['default'] : '';
$field_unique = ( ! empty( $this->unique ) ) ? $this->unique .'['. $this->field['id'] .'][0]' : $this->field['id'] .'[0]';
Sakurairo_CSF::field( $field, $field_default, '___'. $field_unique, 'field/group' );
}
echo '
';
echo '
';
echo '';
if ( ! empty( $this->value ) ) {
$num = 0;
foreach ( $this->value as $value ) {
$title = '';
if ( ! empty( $title_by ) ) {
$titles = array();
foreach ( $title_by as $title_key ) {
if ( isset( $value[ $title_key ] ) ) {
$titles[] = $value[ $title_key ];
}
}
$title = join( $title_by_prefix, $titles );
}
$title = ( is_array( $title ) ) ? reset( $title ) : $title;
echo '
';
echo '
';
echo '';
echo '';
echo '';
echo '
';
echo '
';
echo '';
echo ( $title_number ) ? ''. esc_attr( $num+1 ) .'.' : '';
echo ( $title_prefix ) ? ''. esc_attr( $title_prefix ) .'' : '';
echo ( $title_auto ) ? '' . esc_attr( $title ) .'' : '';
echo '';
echo '
';
echo '
';
foreach ( $this->field['fields'] as $field ) {
$field_unique = ( ! empty( $this->unique ) ) ? $this->unique .'['. $this->field['id'] .']['. $num .']' : $this->field['id'] .'['. $num .']';
$field_value = ( isset( $field['id'] ) && isset( $value[$field['id']] ) ) ? $value[$field['id']] : '';
Sakurairo_CSF::field( $field, $field_value, $field_unique, 'field/group' );
}
echo '
';
echo '
';
$num++;
}
}
echo '
';
echo ''. esc_html__( 'You cannot add more.', 'sakurairo_csf' ) .'
';
echo ''. esc_html__( 'You cannot remove more.', 'sakurairo_csf' ) .'
';
echo ''. $args['button_title'] .'';
echo $this->field_after();
}
}
public function enqueue() {
if ( ! wp_script_is( 'jquery-ui-accordion' ) ) {
wp_enqueue_script( 'jquery-ui-accordion' );
}
if ( ! wp_script_is( 'jquery-ui-sortable' ) ) {
wp_enqueue_script( 'jquery-ui-sortable' );
}
}
}
}