/** * __construct * * @param string $group_name * @param bool $repeat * @param array $_fields */ public function __construct($group_name = null, $repeat = false, array $_fields = array()) { $this->name = $group_name; $this->repeat = $repeat === true ? true : false; $fields = array(); foreach ($_fields as $field_attributes) { $Field = SCF::get_form_field_instance($field_attributes['type']); if (!is_a($Field, 'Smart_Custom_Fields_Field_Base')) { continue; } foreach ($field_attributes as $key => $value) { $Field->set($key, $value); } if (!empty($Field)) { $fields[$Field->get('name')] = $Field; } } $this->fields = $fields; }
/** * 投稿画面にカスタムフィールドを表示 */ public function display_meta_box() { $Setting = SCF::add_setting(get_the_ID(), get_the_title()); $Setting->add_group_unshift(); $groups = $Setting->get_groups(); ?> <div class="<?php echo esc_attr(SCF_Config::PREFIX . 'fields-wrapper'); ?> "> <div class="<?php echo esc_attr(SCF_Config::PREFIX . 'groups'); ?> "> <?php foreach ($groups as $group_key => $Group) { ?> <?php $fields = $Group->get_fields(); array_unshift($fields, SCF::get_form_field_instance('text')); ?> <div class="<?php echo esc_attr(SCF_Config::PREFIX . 'group'); ?> <?php $this->add_hide_class($group_key); ?> "> <div class="btn-remove-group"><span class="dashicons dashicons-no-alt"></span></div> <?php $Group->display_options($group_key); ?> <div class="<?php echo esc_attr(SCF_Config::PREFIX . 'fields'); ?> "> <?php foreach ($fields as $field_key => $Field) { ?> <div class="<?php echo esc_attr(SCF_Config::PREFIX . 'field'); ?> <?php $this->add_hide_class($field_key); ?> "> <?php $field_label = $Field->get('label'); if (!$field_label) { $field_label = $Field->get('name'); if (!$field_label) { $field_label = " "; } } ?> <div class="<?php echo esc_attr(SCF_Config::PREFIX . 'icon-handle'); ?> "></div> <b class="btn-remove-field"><span class="dashicons dashicons-no-alt"></span></b> <div class="field-label"><?php echo esc_html($field_label); ?> </div> <table class="<?php $this->add_hide_class(!$Field->get('name')); ?> "> <tr> <th><?php esc_html_e('Type', 'smart-custom-fields'); ?> <span class="<?php echo esc_attr(SCF_Config::PREFIX . 'require'); ?> ">*</span></th> <td> <select name="<?php echo esc_attr($Field->get_field_name_in_setting($group_key, $field_key, 'type')); ?> " class="<?php echo esc_attr(SCF_Config::PREFIX . 'field-select'); ?> " /> <?php foreach ($this->optgroups as $optgroup_name => $optgroup_values) { $optgroup_fields = array(); $optgroup_values['options'] = apply_filters(SCF_Config::PREFIX . 'field-select-' . $optgroup_name, $optgroup_values['options']); foreach ($optgroup_values['options'] as $option_key => $option) { $optgroup_fields[] = sprintf('<option value="%s" %s>%s</option>', esc_attr($option_key), selected($Field->get_attribute('type'), $option_key, false), esc_html($option)); } printf('<optgroup label="%s">%s</optgroup>', $optgroup_values['label'], implode('', $optgroup_fields)); } ?> </select> </td> </tr> <?php $Field->display_options($group_key, $field_key); ?> </table> </div> <?php } ?> </div> <div class="button btn-add-field <?php $this->add_hide_class($Group->is_repeatable()); ?> "><?php esc_html_e('Add Sub field', 'smart-custom-fields'); ?> </div> </div> <?php } ?> </div> <div class="button btn-add-group"><?php esc_html_e('Add Field', 'smart-custom-fields'); ?> </div> </div> <?php wp_nonce_field(SCF_Config::NAME . '-settings', SCF_Config::PREFIX . 'settings-nonce'); ?> <?php }