Version Description
- Change method SCF::get_field to SCF::get_value_by_field
- Change method SCF::get_sub_field to SCF::get_values_by_group
- Add method SCF::get_field
- Add method SCF::choices_eol_to_array
- remove method Smart_Custom_Fields_Field_Base::get_choices
Download this release
Release Info
Developer | inc2734 |
Plugin | Smart Custom Fields |
Version | 1.1.3 |
Comparing to | |
See all releases |
Code changes from version 1.1.2 to 1.1.3
- classes/class.field-base.php +3 -12
- classes/class.revisions.php +12 -12
- classes/class.scf.php +68 -29
- classes/class.settings.php +2 -2
- classes/fields/class.field-check.php +3 -3
- classes/fields/class.field-radio.php +3 -3
- classes/fields/class.field-select.php +3 -3
- css/settings.css +12 -0
- readme.txt +8 -1
- smart-custom-fields.php +19 -19
classes/class.field-base.php
CHANGED
@@ -1,10 +1,10 @@
|
|
1 |
<?php
|
2 |
/**
|
3 |
* Smart_Custom_Fields_Field_Base
|
4 |
-
* Version : 1.0.
|
5 |
* Author : Takashi Kitajima
|
6 |
* Created : October 7, 2014
|
7 |
-
* Modified :
|
8 |
* License : GPLv2
|
9 |
* License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
*/
|
@@ -54,7 +54,7 @@ abstract class Smart_Custom_Fields_Field_Base {
|
|
54 |
add_action( SCF_Config::PREFIX . 'field-options', array( $this, '_display_field_options' ), 10, 3 );
|
55 |
$this->after_loaded();
|
56 |
|
57 |
-
SCF::
|
58 |
}
|
59 |
|
60 |
/**
|
@@ -178,13 +178,4 @@ abstract class Smart_Custom_Fields_Field_Base {
|
|
178 |
public function allow_multiple_data() {
|
179 |
return $this->allow_multiple_data;
|
180 |
}
|
181 |
-
|
182 |
-
/**
|
183 |
-
* get_choices
|
184 |
-
* @param string $choices
|
185 |
-
* @return array
|
186 |
-
*/
|
187 |
-
public function get_choices( $choices ) {
|
188 |
-
return explode( "\n", $choices );
|
189 |
-
}
|
190 |
}
|
1 |
<?php
|
2 |
/**
|
3 |
* Smart_Custom_Fields_Field_Base
|
4 |
+
* Version : 1.0.3
|
5 |
* Author : Takashi Kitajima
|
6 |
* Created : October 7, 2014
|
7 |
+
* Modified : February 10, 2015
|
8 |
* License : GPLv2
|
9 |
* License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
*/
|
54 |
add_action( SCF_Config::PREFIX . 'field-options', array( $this, '_display_field_options' ), 10, 3 );
|
55 |
$this->after_loaded();
|
56 |
|
57 |
+
SCF::add_form_field_instance( $this );
|
58 |
}
|
59 |
|
60 |
/**
|
178 |
public function allow_multiple_data() {
|
179 |
return $this->allow_multiple_data;
|
180 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
181 |
}
|
classes/class.revisions.php
CHANGED
@@ -1,10 +1,10 @@
|
|
1 |
<?php
|
2 |
/**
|
3 |
* Smart_Custom_Fields_Revisions
|
4 |
-
* Version : 1.0.
|
5 |
* Author : Takashi Kitajima
|
6 |
* Created : September 23, 2014
|
7 |
-
* Modified :
|
8 |
* License : GPLv2
|
9 |
* License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
*/
|
@@ -43,15 +43,15 @@ class Smart_Custom_Fields_Revisions {
|
|
43 |
$settings = SCF::get_settings( $post_type );
|
44 |
foreach ( $settings as $setting ) {
|
45 |
foreach ( $setting as $group ) {
|
46 |
-
foreach ( $group['fields'] as $field ) {
|
47 |
-
delete_post_meta( $post->ID, $
|
48 |
-
$value = SCF::get( $
|
49 |
if ( is_array( $value ) ) {
|
50 |
foreach ( $value as $val ) {
|
51 |
-
add_post_meta( $post->ID, $
|
52 |
}
|
53 |
} else {
|
54 |
-
add_post_meta( $post->ID, $
|
55 |
}
|
56 |
}
|
57 |
}
|
@@ -87,16 +87,16 @@ class Smart_Custom_Fields_Revisions {
|
|
87 |
foreach ( $settings as $setting ) {
|
88 |
foreach ( $setting as $group ) {
|
89 |
$is_repeat = ( isset( $group['repeat'] ) && $group['repeat'] === true ) ? true : false;
|
90 |
-
foreach ( $group['fields'] as $field ) {
|
91 |
-
delete_metadata( 'post', $post_id, $
|
92 |
|
93 |
if ( $is_repeat && $field['allow-multiple-data'] ) {
|
94 |
-
$repeat_multiple_data_fields = $_POST[SCF_Config::NAME][$
|
95 |
foreach ( $repeat_multiple_data_fields as $values ) {
|
96 |
if ( is_array( $values ) ) {
|
97 |
-
$repeat_multiple_data[$
|
98 |
} else {
|
99 |
-
$repeat_multiple_data[$
|
100 |
}
|
101 |
}
|
102 |
}
|
1 |
<?php
|
2 |
/**
|
3 |
* Smart_Custom_Fields_Revisions
|
4 |
+
* Version : 1.0.2
|
5 |
* Author : Takashi Kitajima
|
6 |
* Created : September 23, 2014
|
7 |
+
* Modified : February 10, 2015
|
8 |
* License : GPLv2
|
9 |
* License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
*/
|
43 |
$settings = SCF::get_settings( $post_type );
|
44 |
foreach ( $settings as $setting ) {
|
45 |
foreach ( $setting as $group ) {
|
46 |
+
foreach ( $group['fields'] as $field_name => $field ) {
|
47 |
+
delete_post_meta( $post->ID, $field_name );
|
48 |
+
$value = SCF::get( $field_name, $revision->ID );
|
49 |
if ( is_array( $value ) ) {
|
50 |
foreach ( $value as $val ) {
|
51 |
+
add_post_meta( $post->ID, $field_name, $val );
|
52 |
}
|
53 |
} else {
|
54 |
+
add_post_meta( $post->ID, $field_name, $value );
|
55 |
}
|
56 |
}
|
57 |
}
|
87 |
foreach ( $settings as $setting ) {
|
88 |
foreach ( $setting as $group ) {
|
89 |
$is_repeat = ( isset( $group['repeat'] ) && $group['repeat'] === true ) ? true : false;
|
90 |
+
foreach ( $group['fields'] as $field_name => $field ) {
|
91 |
+
delete_metadata( 'post', $post_id, $field_name );
|
92 |
|
93 |
if ( $is_repeat && $field['allow-multiple-data'] ) {
|
94 |
+
$repeat_multiple_data_fields = $_POST[SCF_Config::NAME][$field_name];
|
95 |
foreach ( $repeat_multiple_data_fields as $values ) {
|
96 |
if ( is_array( $values ) ) {
|
97 |
+
$repeat_multiple_data[$field_name][] = count( $values );
|
98 |
} else {
|
99 |
+
$repeat_multiple_data[$field_name][] = 0;
|
100 |
}
|
101 |
}
|
102 |
}
|
classes/class.scf.php
CHANGED
@@ -1,17 +1,17 @@
|
|
1 |
<?php
|
2 |
/**
|
3 |
* SCF
|
4 |
-
* Version : 1.0.
|
5 |
* Author : Takashi Kitajima
|
6 |
* Created : September 23, 2014
|
7 |
-
* Modified :
|
8 |
* License : GPLv2
|
9 |
* License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
*/
|
11 |
class SCF {
|
12 |
|
13 |
/**
|
14 |
-
* Smart Custom Fields
|
15 |
*/
|
16 |
protected static $fields = array();
|
17 |
|
@@ -64,12 +64,12 @@ class SCF {
|
|
64 |
// グループ名と一致する場合はそのグループ内のフィールドを配列で返す
|
65 |
$is_repeat = ( isset( $group['repeat'] ) && $group['repeat'] === true ) ? true : false;
|
66 |
if ( $is_repeat && !empty( $group['group-name'] ) ) {
|
67 |
-
$return_post_meta[$group['group-name']] = self::
|
68 |
}
|
69 |
// グループ名と一致しない場合は一致するフィールドを返す
|
70 |
else {
|
71 |
-
foreach ( $group['fields'] as $field ) {
|
72 |
-
$return_post_meta[$
|
73 |
}
|
74 |
}
|
75 |
}
|
@@ -107,15 +107,12 @@ class SCF {
|
|
107 |
// グループ名と一致する場合はそのグループ内のフィールドを配列で返す
|
108 |
$is_repeat = ( isset( $group['repeat'] ) && $group['repeat'] === true ) ? true : false;
|
109 |
if ( $is_repeat && !empty( $group['group-name'] ) && $group['group-name'] === $name ) {
|
110 |
-
return self::
|
111 |
}
|
112 |
// グループ名と一致しない場合は一致するフィールドを返す
|
113 |
else {
|
114 |
-
|
115 |
-
|
116 |
-
continue;
|
117 |
-
}
|
118 |
-
$post_meta = self::get_field( $post_id, $field, $is_repeat );
|
119 |
if ( !is_null( $post_meta ) ) {
|
120 |
return $post_meta;
|
121 |
}
|
@@ -164,28 +161,28 @@ class SCF {
|
|
164 |
}
|
165 |
|
166 |
/**
|
167 |
-
*
|
168 |
* @param int $post_id
|
169 |
* @param string $group_name
|
170 |
* @param array $fields
|
171 |
* @return mixed $post_meta
|
172 |
*/
|
173 |
-
protected static function
|
174 |
$post_meta = array();
|
175 |
-
foreach ( $fields as $field ) {
|
176 |
-
$_post_meta = get_post_meta( $post_id, $
|
177 |
// チェックボックスの場合
|
178 |
$repeat_multiple_data = self::get_repeat_multiple_data( $post_id );
|
179 |
-
if ( is_array( $repeat_multiple_data ) && array_key_exists( $
|
180 |
$start = 0;
|
181 |
-
foreach ( $repeat_multiple_data[$
|
182 |
if ( $repeat_multiple_value === 0 ) {
|
183 |
$value = array();
|
184 |
} else {
|
185 |
$value = array_slice( $_post_meta, $start, $repeat_multiple_value );
|
186 |
$start += $repeat_multiple_value;
|
187 |
}
|
188 |
-
$post_meta[$repeat_multiple_key][$
|
189 |
}
|
190 |
}
|
191 |
// チェックボックス以外
|
@@ -197,7 +194,7 @@ class SCF {
|
|
197 |
if ( get_post_status( $value ) !== 'publish' )
|
198 |
continue;
|
199 |
}
|
200 |
-
$post_meta[$_post_meta_key][$
|
201 |
}
|
202 |
}
|
203 |
}
|
@@ -206,13 +203,13 @@ class SCF {
|
|
206 |
}
|
207 |
|
208 |
/**
|
209 |
-
*
|
210 |
* @param int $post_id
|
211 |
* @param array $field
|
212 |
-
* @param bool $is_repeat
|
213 |
* @return mixed $post_meta
|
214 |
*/
|
215 |
-
protected static function
|
216 |
if ( $field['allow-multiple-data'] || $is_repeat ) {
|
217 |
$post_meta = get_post_meta( $post_id, $field['name'] );
|
218 |
} else {
|
@@ -252,6 +249,7 @@ class SCF {
|
|
252 |
|
253 |
/**
|
254 |
* get_settings_posts
|
|
|
255 |
* @param int $post_type
|
256 |
* @param array $settings
|
257 |
*/
|
@@ -326,7 +324,9 @@ class SCF {
|
|
326 |
foreach ( $settings as $setting_key => $setting ) {
|
327 |
foreach ( $setting as $group_key => $group ) {
|
328 |
foreach ( $group['fields'] as $field_key => $field ) {
|
329 |
-
$settings[$setting_key][$group_key]['fields'][$field_key]
|
|
|
|
|
330 |
}
|
331 |
}
|
332 |
}
|
@@ -381,10 +381,11 @@ class SCF {
|
|
381 |
}
|
382 |
|
383 |
/**
|
384 |
-
*
|
|
|
385 |
* @param Smart_Custom_Fields_Field_Base $instance
|
386 |
*/
|
387 |
-
public static function
|
388 |
$instance_name = $instance->get_name();
|
389 |
if ( !empty( $instance_name ) ) {
|
390 |
self::$fields[$instance_name] = $instance;
|
@@ -392,13 +393,51 @@ class SCF {
|
|
392 |
}
|
393 |
|
394 |
/**
|
395 |
-
*
|
396 |
-
*
|
|
|
397 |
* @param Smart_Custom_Fields_Field_Base
|
398 |
*/
|
399 |
-
public static function
|
400 |
if ( !empty( self::$fields[$field_name] ) ) {
|
401 |
return self::$fields[$field_name];
|
402 |
}
|
403 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
404 |
}
|
1 |
<?php
|
2 |
/**
|
3 |
* SCF
|
4 |
+
* Version : 1.0.3
|
5 |
* Author : Takashi Kitajima
|
6 |
* Created : September 23, 2014
|
7 |
+
* Modified : February 10, 2015
|
8 |
* License : GPLv2
|
9 |
* License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
*/
|
11 |
class SCF {
|
12 |
|
13 |
/**
|
14 |
+
* Smart Custom Fields に登録されているフォームフィールド(field)のインスタンスの配列
|
15 |
*/
|
16 |
protected static $fields = array();
|
17 |
|
64 |
// グループ名と一致する場合はそのグループ内のフィールドを配列で返す
|
65 |
$is_repeat = ( isset( $group['repeat'] ) && $group['repeat'] === true ) ? true : false;
|
66 |
if ( $is_repeat && !empty( $group['group-name'] ) ) {
|
67 |
+
$return_post_meta[$group['group-name']] = self::get_values_by_group( $post_id, $group['group-name'], $group['fields'] );
|
68 |
}
|
69 |
// グループ名と一致しない場合は一致するフィールドを返す
|
70 |
else {
|
71 |
+
foreach ( $group['fields'] as $field_name => $field ) {
|
72 |
+
$return_post_meta[$field_name] = self::get_value_by_field( $post_id, $field, $is_repeat );
|
73 |
}
|
74 |
}
|
75 |
}
|
107 |
// グループ名と一致する場合はそのグループ内のフィールドを配列で返す
|
108 |
$is_repeat = ( isset( $group['repeat'] ) && $group['repeat'] === true ) ? true : false;
|
109 |
if ( $is_repeat && !empty( $group['group-name'] ) && $group['group-name'] === $name ) {
|
110 |
+
return self::get_values_by_group( $post_id, $name, $group['fields'] );
|
111 |
}
|
112 |
// グループ名と一致しない場合は一致するフィールドを返す
|
113 |
else {
|
114 |
+
if ( isset( $group['fields'][$name] ) ) {
|
115 |
+
$post_meta = self::get_value_by_field( $post_id, $group['fields'][$name], $is_repeat );
|
|
|
|
|
|
|
116 |
if ( !is_null( $post_meta ) ) {
|
117 |
return $post_meta;
|
118 |
}
|
161 |
}
|
162 |
|
163 |
/**
|
164 |
+
* get_values_by_group
|
165 |
* @param int $post_id
|
166 |
* @param string $group_name
|
167 |
* @param array $fields
|
168 |
* @return mixed $post_meta
|
169 |
*/
|
170 |
+
protected static function get_values_by_group( $post_id, $group_name, $fields ) {
|
171 |
$post_meta = array();
|
172 |
+
foreach ( $fields as $field_name => $field ) {
|
173 |
+
$_post_meta = get_post_meta( $post_id, $field_name );
|
174 |
// チェックボックスの場合
|
175 |
$repeat_multiple_data = self::get_repeat_multiple_data( $post_id );
|
176 |
+
if ( is_array( $repeat_multiple_data ) && array_key_exists( $field_name, $repeat_multiple_data ) ) {
|
177 |
$start = 0;
|
178 |
+
foreach ( $repeat_multiple_data[$field_name] as $repeat_multiple_key => $repeat_multiple_value ) {
|
179 |
if ( $repeat_multiple_value === 0 ) {
|
180 |
$value = array();
|
181 |
} else {
|
182 |
$value = array_slice( $_post_meta, $start, $repeat_multiple_value );
|
183 |
$start += $repeat_multiple_value;
|
184 |
}
|
185 |
+
$post_meta[$repeat_multiple_key][$field_name] = $value;
|
186 |
}
|
187 |
}
|
188 |
// チェックボックス以外
|
194 |
if ( get_post_status( $value ) !== 'publish' )
|
195 |
continue;
|
196 |
}
|
197 |
+
$post_meta[$_post_meta_key][$field_name] = $value;
|
198 |
}
|
199 |
}
|
200 |
}
|
203 |
}
|
204 |
|
205 |
/**
|
206 |
+
* get_value_by_field
|
207 |
* @param int $post_id
|
208 |
* @param array $field
|
209 |
+
* @param bool $is_repeat このフィールドが所属するグループが repeat かどうか
|
210 |
* @return mixed $post_meta
|
211 |
*/
|
212 |
+
protected static function get_value_by_field( $post_id, $field, $is_repeat ) {
|
213 |
if ( $field['allow-multiple-data'] || $is_repeat ) {
|
214 |
$post_meta = get_post_meta( $post_id, $field['name'] );
|
215 |
} else {
|
249 |
|
250 |
/**
|
251 |
* get_settings_posts
|
252 |
+
* その投稿タイプで有効になっている SCF を取得
|
253 |
* @param int $post_type
|
254 |
* @param array $settings
|
255 |
*/
|
324 |
foreach ( $settings as $setting_key => $setting ) {
|
325 |
foreach ( $setting as $group_key => $group ) {
|
326 |
foreach ( $group['fields'] as $field_key => $field ) {
|
327 |
+
unset( $settings[$setting_key][$group_key]['fields'][$field_key] );
|
328 |
+
$field['allow-multiple-data'] = self::$fields[$field['type']]->allow_multiple_data();
|
329 |
+
$settings[$setting_key][$group_key]['fields'][$field['name']] = $field;
|
330 |
}
|
331 |
}
|
332 |
}
|
381 |
}
|
382 |
|
383 |
/**
|
384 |
+
* add_form_field_instance
|
385 |
+
* フォームフィールドを追加
|
386 |
* @param Smart_Custom_Fields_Field_Base $instance
|
387 |
*/
|
388 |
+
public static function add_form_field_instance( Smart_Custom_Fields_Field_Base $instance ) {
|
389 |
$instance_name = $instance->get_name();
|
390 |
if ( !empty( $instance_name ) ) {
|
391 |
self::$fields[$instance_name] = $instance;
|
393 |
}
|
394 |
|
395 |
/**
|
396 |
+
* get_form_field_instance
|
397 |
+
* フォームフィールドの情報を取得
|
398 |
+
* @param string $field_name フォームフィールドの name
|
399 |
* @param Smart_Custom_Fields_Field_Base
|
400 |
*/
|
401 |
+
public static function get_form_field_instance( $field_name ) {
|
402 |
if ( !empty( self::$fields[$field_name] ) ) {
|
403 |
return self::$fields[$field_name];
|
404 |
}
|
405 |
}
|
406 |
+
|
407 |
+
/**
|
408 |
+
* get_field
|
409 |
+
* カスタムフィールドの設定情報を取得
|
410 |
+
* @param int $post_id
|
411 |
+
* @param string $field_name カスタムフィールドの名前
|
412 |
+
* @return array
|
413 |
+
*/
|
414 |
+
public static function get_field( $post_type, $field_name ) {
|
415 |
+
$settings = self::get_settings( $post_type );
|
416 |
+
foreach ( $settings as $setting ) {
|
417 |
+
foreach ( $setting as $group ) {
|
418 |
+
if ( isset( $group['fields'][$field_name] ) ) {
|
419 |
+
$field = $group['fields'][$field_name];
|
420 |
+
if ( isset( $field['choices'] ) ) {
|
421 |
+
$field['choices'] = self::choices_eol_to_array( $field['choices'] );
|
422 |
+
}
|
423 |
+
return $field;
|
424 |
+
}
|
425 |
+
}
|
426 |
+
}
|
427 |
+
return array();
|
428 |
+
}
|
429 |
+
|
430 |
+
/**
|
431 |
+
* choices_eol_to_array
|
432 |
+
* 改行区切りの $choices を配列に変換
|
433 |
+
* @param string $choices
|
434 |
+
* @return array
|
435 |
+
*/
|
436 |
+
public static function choices_eol_to_array( $choices ) {
|
437 |
+
if ( !is_array( $choices ) ) {
|
438 |
+
$choices = str_replace( array( "\r\n", "\r", "\n" ), "\n", $choices );
|
439 |
+
return explode( "\n", $choices );
|
440 |
+
}
|
441 |
+
return $choices;
|
442 |
+
}
|
443 |
}
|
classes/class.settings.php
CHANGED
@@ -128,7 +128,7 @@ class Smart_Custom_Fields_Settings {
|
|
128 |
array_unshift( $group['fields'], array() );
|
129 |
?>
|
130 |
<div class="<?php echo esc_attr( SCF_Config::PREFIX . 'group' ); ?> <?php $this->add_hide_class( $group_key ); ?>">
|
131 |
-
<div class="btn-remove-group"><
|
132 |
<div class="<?php echo esc_attr( SCF_Config::PREFIX . 'group-repeat' ); ?>">
|
133 |
<div class="<?php echo esc_attr( SCF_Config::PREFIX . 'icon-handle' ); ?>"></div>
|
134 |
<label>
|
@@ -167,7 +167,7 @@ class Smart_Custom_Fields_Settings {
|
|
167 |
}
|
168 |
?>
|
169 |
<div class="<?php echo esc_attr( SCF_Config::PREFIX . 'icon-handle' ); ?>"></div>
|
170 |
-
<b class="btn-remove-field"
|
171 |
<div class="field-label"><?php echo esc_html( $field_label ); ?></div>
|
172 |
<table class="<?php $this->add_hide_class( !$this->get( 'name', $field ) ); ?>">
|
173 |
<tr>
|
128 |
array_unshift( $group['fields'], array() );
|
129 |
?>
|
130 |
<div class="<?php echo esc_attr( SCF_Config::PREFIX . 'group' ); ?> <?php $this->add_hide_class( $group_key ); ?>">
|
131 |
+
<div class="btn-remove-group"><span class="dashicons dashicons-no-alt"></span></div>
|
132 |
<div class="<?php echo esc_attr( SCF_Config::PREFIX . 'group-repeat' ); ?>">
|
133 |
<div class="<?php echo esc_attr( SCF_Config::PREFIX . 'icon-handle' ); ?>"></div>
|
134 |
<label>
|
167 |
}
|
168 |
?>
|
169 |
<div class="<?php echo esc_attr( SCF_Config::PREFIX . 'icon-handle' ); ?>"></div>
|
170 |
+
<b class="btn-remove-field"><span class="dashicons dashicons-no-alt"></span></b>
|
171 |
<div class="field-label"><?php echo esc_html( $field_label ); ?></div>
|
172 |
<table class="<?php $this->add_hide_class( !$this->get( 'name', $field ) ); ?>">
|
173 |
<tr>
|
classes/fields/class.field-check.php
CHANGED
@@ -1,10 +1,10 @@
|
|
1 |
<?php
|
2 |
/**
|
3 |
* Smart_Custom_Fields_Field_Check
|
4 |
-
* Version : 1.0.
|
5 |
* Author : Takashi Kitajima
|
6 |
* Created : October 7, 2014
|
7 |
-
* Modified :
|
8 |
* License : GPLv2
|
9 |
* License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
*/
|
@@ -32,7 +32,7 @@ class Smart_Custom_Fields_Field_Check extends Smart_Custom_Fields_Field_Base {
|
|
32 |
public function get_field( $field, $index, $value ) {
|
33 |
$name = $this->get_name_attribute( $field['name'], $index );
|
34 |
$disabled = $this->get_disable_attribute( $index );
|
35 |
-
$choices =
|
36 |
|
37 |
$form_field = sprintf(
|
38 |
'<input type="hidden" name="%s" value="" %s />',
|
1 |
<?php
|
2 |
/**
|
3 |
* Smart_Custom_Fields_Field_Check
|
4 |
+
* Version : 1.0.2
|
5 |
* Author : Takashi Kitajima
|
6 |
* Created : October 7, 2014
|
7 |
+
* Modified : February 10, 2015
|
8 |
* License : GPLv2
|
9 |
* License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
*/
|
32 |
public function get_field( $field, $index, $value ) {
|
33 |
$name = $this->get_name_attribute( $field['name'], $index );
|
34 |
$disabled = $this->get_disable_attribute( $index );
|
35 |
+
$choices = SCF::choices_eol_to_array( $field['choices'] );
|
36 |
|
37 |
$form_field = sprintf(
|
38 |
'<input type="hidden" name="%s" value="" %s />',
|
classes/fields/class.field-radio.php
CHANGED
@@ -1,10 +1,10 @@
|
|
1 |
<?php
|
2 |
/**
|
3 |
* Smart_Custom_Fields_Field_Radio
|
4 |
-
* Version : 1.0.
|
5 |
* Author : Takashi Kitajima
|
6 |
* Created : October 7, 2014
|
7 |
-
* Modified :
|
8 |
* License : GPLv2
|
9 |
* License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
*/
|
@@ -31,7 +31,7 @@ class Smart_Custom_Fields_Field_Radio extends Smart_Custom_Fields_Field_Base {
|
|
31 |
public function get_field( $field, $index, $value ) {
|
32 |
$name = $this->get_name_attribute( $field['name'], $index );
|
33 |
$disabled = $this->get_disable_attribute( $index );
|
34 |
-
$choices =
|
35 |
|
36 |
$form_field = sprintf(
|
37 |
'<input type="hidden" name="%s" value="" %s />',
|
1 |
<?php
|
2 |
/**
|
3 |
* Smart_Custom_Fields_Field_Radio
|
4 |
+
* Version : 1.0.1
|
5 |
* Author : Takashi Kitajima
|
6 |
* Created : October 7, 2014
|
7 |
+
* Modified : February 10, 2015
|
8 |
* License : GPLv2
|
9 |
* License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
*/
|
31 |
public function get_field( $field, $index, $value ) {
|
32 |
$name = $this->get_name_attribute( $field['name'], $index );
|
33 |
$disabled = $this->get_disable_attribute( $index );
|
34 |
+
$choices = SCF::choices_eol_to_array( $field['choices'] );
|
35 |
|
36 |
$form_field = sprintf(
|
37 |
'<input type="hidden" name="%s" value="" %s />',
|
classes/fields/class.field-select.php
CHANGED
@@ -1,10 +1,10 @@
|
|
1 |
<?php
|
2 |
/**
|
3 |
* Smart_Custom_Fields_Field_Select
|
4 |
-
* Version : 1.0.
|
5 |
* Author : Takashi Kitajima
|
6 |
* Created : October 7, 2014
|
7 |
-
* Modified :
|
8 |
* License : GPLv2
|
9 |
* License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
*/
|
@@ -31,7 +31,7 @@ class Smart_Custom_Fields_Field_Select extends Smart_Custom_Fields_Field_Base {
|
|
31 |
public function get_field( $field, $index, $value ) {
|
32 |
$name = $this->get_name_attribute( $field['name'], $index );
|
33 |
$disabled = $this->get_disable_attribute( $index );
|
34 |
-
$choices =
|
35 |
|
36 |
$form_field = '';
|
37 |
foreach ( $choices as $choice ) {
|
1 |
<?php
|
2 |
/**
|
3 |
* Smart_Custom_Fields_Field_Select
|
4 |
+
* Version : 1.0.1
|
5 |
* Author : Takashi Kitajima
|
6 |
* Created : October 7, 2014
|
7 |
+
* Modified : February 10, 2015
|
8 |
* License : GPLv2
|
9 |
* License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
*/
|
31 |
public function get_field( $field, $index, $value ) {
|
32 |
$name = $this->get_name_attribute( $field['name'], $index );
|
33 |
$disabled = $this->get_disable_attribute( $index );
|
34 |
+
$choices = SCF::choices_eol_to_array( $field['choices'] );
|
35 |
|
36 |
$form_field = '';
|
37 |
foreach ( $choices as $choice ) {
|
css/settings.css
CHANGED
@@ -51,6 +51,12 @@
|
|
51 |
top: 10px;
|
52 |
right: 10px;
|
53 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
54 |
|
55 |
/**
|
56 |
* .btn-add-field
|
@@ -157,6 +163,12 @@
|
|
157 |
cursor: pointer;
|
158 |
float: right;
|
159 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
160 |
|
161 |
/** ==================================================
|
162 |
* #smart-cf-meta-box-condition
|
51 |
top: 10px;
|
52 |
right: 10px;
|
53 |
}
|
54 |
+
.smart-cf-group .btn-remove-group .dashicons,
|
55 |
+
.smart-cf-group .btn-remove-group .dashicons:before {
|
56 |
+
font-size: 14px;
|
57 |
+
height: 14px;
|
58 |
+
width: 14px;
|
59 |
+
}
|
60 |
|
61 |
/**
|
62 |
* .btn-add-field
|
163 |
cursor: pointer;
|
164 |
float: right;
|
165 |
}
|
166 |
+
.smart-cf-group .smart-cf-field .btn-remove-field .dashicons,
|
167 |
+
.smart-cf-group .smart-cf-field .btn-remove-field .dashicons:before {
|
168 |
+
font-size: 14px;
|
169 |
+
height: 14px;
|
170 |
+
width: 14px;
|
171 |
+
}
|
172 |
|
173 |
/** ==================================================
|
174 |
* #smart-cf-meta-box-condition
|
readme.txt
CHANGED
@@ -4,7 +4,7 @@ Donate link: http://www.amazon.co.jp/registry/wishlist/39ANKRNSTNW40
|
|
4 |
Tags: plugin, custom field, custom, field, meta, meta field, repeat, repeatable
|
5 |
Requires at least: 3.9
|
6 |
Tested up to: 4.1
|
7 |
-
Stable tag: 1.1.
|
8 |
License: GPLv2
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
@@ -62,6 +62,13 @@ https://github.com/inc2734/smart-custom-fields/
|
|
62 |
|
63 |
== Changelog ==
|
64 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
65 |
= 1.1.2 =
|
66 |
* Add action hook smart-cf-fields-loaded
|
67 |
|
4 |
Tags: plugin, custom field, custom, field, meta, meta field, repeat, repeatable
|
5 |
Requires at least: 3.9
|
6 |
Tested up to: 4.1
|
7 |
+
Stable tag: 1.1.3
|
8 |
License: GPLv2
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
62 |
|
63 |
== Changelog ==
|
64 |
|
65 |
+
= 1.1.3 =
|
66 |
+
* Change method SCF::get_field to SCF::get_value_by_field
|
67 |
+
* Change method SCF::get_sub_field to SCF::get_values_by_group
|
68 |
+
* Add method SCF::get_field
|
69 |
+
* Add method SCF::choices_eol_to_array
|
70 |
+
* remove method Smart_Custom_Fields_Field_Base::get_choices
|
71 |
+
|
72 |
= 1.1.2 =
|
73 |
* Add action hook smart-cf-fields-loaded
|
74 |
|
smart-custom-fields.php
CHANGED
@@ -3,11 +3,11 @@
|
|
3 |
* Plugin name: Smart Custom Fields
|
4 |
* Plugin URI: https://github.com/inc2734/smart-custom-fields/
|
5 |
* Description: Smart Custom Fields is a simple plugin that management custom fields.
|
6 |
-
* Version: 1.1.
|
7 |
* Author: Takashi Kitajima
|
8 |
* Author URI: http://2inc.org
|
9 |
* Created: October 9, 2014
|
10 |
-
* Modified: February
|
11 |
* Text Domain: smart-custom-fields
|
12 |
* Domain Path: /languages/
|
13 |
* License: GPLv2
|
@@ -220,20 +220,20 @@ class Smart_Custom_Fields {
|
|
220 |
foreach ( $settings as $setting ) {
|
221 |
foreach ( $setting as $group ) {
|
222 |
$is_repeat = ( isset( $group['repeat'] ) && $group['repeat'] === true ) ? true : false;
|
223 |
-
foreach ( $group['fields'] as $field ) {
|
224 |
-
delete_post_meta( $post_id, $
|
225 |
|
226 |
if ( $field['allow-multiple-data'] ) {
|
227 |
-
$multiple_data_fields[] = $
|
228 |
}
|
229 |
|
230 |
if ( $is_repeat && $field['allow-multiple-data'] ) {
|
231 |
-
$repeat_multiple_data_fields = $_POST[SCF_Config::NAME][$
|
232 |
foreach ( $repeat_multiple_data_fields as $values ) {
|
233 |
if ( is_array( $values ) ) {
|
234 |
-
$repeat_multiple_data[$
|
235 |
} else {
|
236 |
-
$repeat_multiple_data[$
|
237 |
}
|
238 |
}
|
239 |
}
|
@@ -327,15 +327,15 @@ class Smart_Custom_Fields {
|
|
327 |
// ループだけどループがないとき(新規登録時とか)は1つだけ入れる
|
328 |
if ( isset( $group['repeat'] ) && $group['repeat'] === true ) {
|
329 |
$loop_count = 1;
|
330 |
-
foreach ( $group['fields'] as $field ) {
|
331 |
-
if ( isset( $post_custom[$
|
332 |
-
$post_meta = $post_custom[$
|
333 |
$post_meta_count = count( $post_meta );
|
334 |
// 同名のカスタムフィールドが複数のとき(チェックボックス or ループ)
|
335 |
if ( $post_meta_count > 1 ) {
|
336 |
// チェックボックスの場合
|
337 |
-
if ( is_array( $repeat_multiple_data ) && array_key_exists( $
|
338 |
-
$repeat_multiple_data_count = count( $repeat_multiple_data[$
|
339 |
if ( $loop_count < $repeat_multiple_data_count )
|
340 |
$loop_count = $repeat_multiple_data_count;
|
341 |
}
|
@@ -436,10 +436,10 @@ class Smart_Custom_Fields {
|
|
436 |
$btn_repeat
|
437 |
);
|
438 |
|
439 |
-
foreach ( $fields as $field ) {
|
440 |
$field_label = $field['label'];
|
441 |
if ( !$field_label ) {
|
442 |
-
$field_label = $
|
443 |
}
|
444 |
|
445 |
// 複数値許可フィールドのとき
|
@@ -447,9 +447,9 @@ class Smart_Custom_Fields {
|
|
447 |
if ( $field['allow-multiple-data'] ) {
|
448 |
$value = array();
|
449 |
if ( !SCF::is_empty( $field['default'] ) && ( $post_status === 'auto-draft' || is_null( $index ) ) ) {
|
450 |
-
$value = SCF::
|
451 |
}
|
452 |
-
$_value = $this->get_multiple_data_field_value( $post_id, $
|
453 |
}
|
454 |
// 複数不値許可フィールドのとき
|
455 |
else {
|
@@ -459,7 +459,7 @@ class Smart_Custom_Fields {
|
|
459 |
$value = $field['default'];
|
460 |
}
|
461 |
}
|
462 |
-
$_value = $this->get_single_data_field_value( $post_id, $
|
463 |
}
|
464 |
if ( !is_null( $_value ) ) {
|
465 |
$value = $_value;
|
@@ -473,7 +473,7 @@ class Smart_Custom_Fields {
|
|
473 |
);
|
474 |
}
|
475 |
|
476 |
-
$form_field = SCF::
|
477 |
printf(
|
478 |
'<tr><th>%s</th><td>%s%s</td></tr>',
|
479 |
esc_html( $field_label ),
|
3 |
* Plugin name: Smart Custom Fields
|
4 |
* Plugin URI: https://github.com/inc2734/smart-custom-fields/
|
5 |
* Description: Smart Custom Fields is a simple plugin that management custom fields.
|
6 |
+
* Version: 1.1.3
|
7 |
* Author: Takashi Kitajima
|
8 |
* Author URI: http://2inc.org
|
9 |
* Created: October 9, 2014
|
10 |
+
* Modified: February 10, 2015
|
11 |
* Text Domain: smart-custom-fields
|
12 |
* Domain Path: /languages/
|
13 |
* License: GPLv2
|
220 |
foreach ( $settings as $setting ) {
|
221 |
foreach ( $setting as $group ) {
|
222 |
$is_repeat = ( isset( $group['repeat'] ) && $group['repeat'] === true ) ? true : false;
|
223 |
+
foreach ( $group['fields'] as $field_name => $field ) {
|
224 |
+
delete_post_meta( $post_id, $field_name );
|
225 |
|
226 |
if ( $field['allow-multiple-data'] ) {
|
227 |
+
$multiple_data_fields[] = $field_name;
|
228 |
}
|
229 |
|
230 |
if ( $is_repeat && $field['allow-multiple-data'] ) {
|
231 |
+
$repeat_multiple_data_fields = $_POST[SCF_Config::NAME][$field_name];
|
232 |
foreach ( $repeat_multiple_data_fields as $values ) {
|
233 |
if ( is_array( $values ) ) {
|
234 |
+
$repeat_multiple_data[$field_name][] = count( $values );
|
235 |
} else {
|
236 |
+
$repeat_multiple_data[$field_name][] = 0;
|
237 |
}
|
238 |
}
|
239 |
}
|
327 |
// ループだけどループがないとき(新規登録時とか)は1つだけ入れる
|
328 |
if ( isset( $group['repeat'] ) && $group['repeat'] === true ) {
|
329 |
$loop_count = 1;
|
330 |
+
foreach ( $group['fields'] as $field_name => $field ) {
|
331 |
+
if ( isset( $post_custom[$field_name] ) && is_array( $post_custom[$field_name] ) ) {
|
332 |
+
$post_meta = $post_custom[$field_name];
|
333 |
$post_meta_count = count( $post_meta );
|
334 |
// 同名のカスタムフィールドが複数のとき(チェックボックス or ループ)
|
335 |
if ( $post_meta_count > 1 ) {
|
336 |
// チェックボックスの場合
|
337 |
+
if ( is_array( $repeat_multiple_data ) && array_key_exists( $field_name, $repeat_multiple_data ) ) {
|
338 |
+
$repeat_multiple_data_count = count( $repeat_multiple_data[$field_name] );
|
339 |
if ( $loop_count < $repeat_multiple_data_count )
|
340 |
$loop_count = $repeat_multiple_data_count;
|
341 |
}
|
436 |
$btn_repeat
|
437 |
);
|
438 |
|
439 |
+
foreach ( $fields as $field_name => $field ) {
|
440 |
$field_label = $field['label'];
|
441 |
if ( !$field_label ) {
|
442 |
+
$field_label = $field_name;
|
443 |
}
|
444 |
|
445 |
// 複数値許可フィールドのとき
|
447 |
if ( $field['allow-multiple-data'] ) {
|
448 |
$value = array();
|
449 |
if ( !SCF::is_empty( $field['default'] ) && ( $post_status === 'auto-draft' || is_null( $index ) ) ) {
|
450 |
+
$value = SCF::choices_eol_to_array( $field['default'] );
|
451 |
}
|
452 |
+
$_value = $this->get_multiple_data_field_value( $post_id, $field_name, $index );
|
453 |
}
|
454 |
// 複数不値許可フィールドのとき
|
455 |
else {
|
459 |
$value = $field['default'];
|
460 |
}
|
461 |
}
|
462 |
+
$_value = $this->get_single_data_field_value( $post_id, $field_name, $index );
|
463 |
}
|
464 |
if ( !is_null( $_value ) ) {
|
465 |
$value = $_value;
|
473 |
);
|
474 |
}
|
475 |
|
476 |
+
$form_field = SCF::get_form_field_instance( $field['type'] )->get_field( $field, $index, $value );
|
477 |
printf(
|
478 |
'<tr><th>%s</th><td>%s%s</td></tr>',
|
479 |
esc_html( $field_label ),
|