/**
  * 投稿画面にフィールドを表示
  *
  * @param int $index インデックス番号
  * @param mixed $value 保存されている値(check のときだけ配列)
  * @return string html
  */
 public function get_field($index, $value)
 {
     $name = $this->get_field_name_in_editor($index);
     $disabled = $this->get_disable_attribute($index);
     $choices = SCF::choices_eol_to_array($this->get('choices'));
     $form_field = '';
     foreach ($choices as $choice) {
         $choice = trim($choice);
         $form_field .= sprintf('<option value="%1$s" %2$s>%1$s</option>', esc_html($choice), selected($value, $choice, false));
     }
     return sprintf('<select name="%s" %s>%s</select>', esc_attr($name), disabled(true, $disabled, false), $form_field);
 }
示例#2
0
 /**
  * 投稿画面にフィールドを表示
  *
  * @param int $index インデックス番号
  * @param mixed $value 保存されている値(check のときだけ配列)
  * @return string html
  */
 public function get_field($index, $value)
 {
     $name = $this->get_field_name_in_editor($index);
     $disabled = $this->get_disable_attribute($index);
     $choices = SCF::choices_eol_to_array($this->get('choices'));
     $direction = $this->get('radio_direction');
     $form_field = sprintf('<input type="hidden" name="%s" value="" %s />', esc_attr($name), disabled(true, $disabled, false));
     foreach ($choices as $choice) {
         $choice = trim($choice);
         $form_field .= sprintf('<span class="%s"><label><input type="radio" name="%s" value="%s" %s %s /> %s</label></span>', esc_attr(SCF_Config::PREFIX . 'item-' . $direction), esc_attr($name), esc_attr($choice), checked($value, $choice, false), disabled(true, $disabled, false), esc_html($choice));
     }
     return $form_field;
 }
示例#3
0
 /**
  * 初期値を返す
  *
  * @param Smart_Custom_Fields_Field_Base $Field
  * @param bool $single
  * @return array|strings
  */
 public static function get_default_value($Field, $single = false)
 {
     if (!is_a($Field, 'Smart_Custom_Fields_Field_Base')) {
         if ($single) {
             return '';
         }
         return array();
     }
     $choices = $Field->get('choices');
     $default = $Field->get('default');
     if ($Field->get_attribute('allow-multiple-data')) {
         $choices = SCF::choices_eol_to_array($choices);
         $default = SCF::choices_eol_to_array($default);
         $default_sanitized = array();
         foreach ($default as $key => $value) {
             if (in_array($value, $choices)) {
                 $default_sanitized[$key] = $value;
             }
         }
         return $default_sanitized;
     }
     // 文字列を返す
     if ($single) {
         return $default;
     } else {
         if (is_array($default)) {
             return $default;
         }
         if ($default === '' || $default === false || $default === null) {
             return array();
         }
         return (array) $default;
     }
 }