Smart Custom Fields - Version 1.1.0

Version Description

  • Add date picker field.
Download this release

Release Info

Developer inc2734
Plugin Icon wp plugin Smart Custom Fields
Version 1.1.0
Comparing to
See all releases

Code changes from version 1.1.3 to 1.1.0

classes/class.field-base.php CHANGED
@@ -1,10 +1,10 @@
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,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::add_form_field_instance( $this );
58
  }
59
 
60
  /**
@@ -178,4 +178,13 @@ abstract class Smart_Custom_Fields_Field_Base {
178
  public function allow_multiple_data() {
179
  return $this->allow_multiple_data;
180
  }
 
 
 
 
 
 
 
 
 
181
  }
1
  <?php
2
  /**
3
  * Smart_Custom_Fields_Field_Base
4
+ * Version : 1.0.2
5
  * Author : Takashi Kitajima
6
  * Created : October 7, 2014
7
+ * Modified : October 21, 2014
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_field_instance( $this );
58
  }
59
 
60
  /**
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
  }
classes/class.revisions.php CHANGED
@@ -1,10 +1,10 @@
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,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_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,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_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
  }
@@ -176,16 +176,14 @@ class Smart_Custom_Fields_Revisions {
176
  }
177
 
178
  /**
179
- * _wp_post_revision_field_debug_preview
180
- * @param $value
181
- * @param $column
182
- * @param array $post
 
183
  * @return string
184
  */
185
- public function _wp_post_revision_field_debug_preview( $value = '', $column = null, $post ) {
186
- if ( is_null( $column ) ) {
187
- $column = SCF_Config::PREFIX . 'debug-preview';
188
- }
189
  $output = '';
190
  $values = SCF::gets( $post->ID );
191
  foreach ( $values as $key => $value ) {
@@ -213,10 +211,14 @@ class Smart_Custom_Fields_Revisions {
213
  }
214
 
215
  /**
216
- * wp_save_post_revision_check_for_changes
 
 
 
 
217
  * @return bool false ならリビジョンとして保存される。
218
  */
219
- public function wp_save_post_revision_check_for_changes( $check_for_changes = true, $last_revision, $post ) {
220
  $post_meta = array();
221
  $p = get_post_custom( $post->ID );
222
  foreach ( $p as $key => $value ) {
@@ -226,8 +228,12 @@ class Smart_Custom_Fields_Revisions {
226
  }
227
  }
228
 
229
- if ( isset( $_POST[SCF_Config::NAME] ) && serialize( $post_meta ) != serialize( $_POST[SCF_Config::NAME] ) ) {
230
- return false;
 
 
 
 
231
  }
232
  return true;
233
  }
1
  <?php
2
  /**
3
  * Smart_Custom_Fields_Revisions
4
+ * Version : 1.0.1
5
  * Author : Takashi Kitajima
6
  * Created : September 23, 2014
7
+ * Modified : October 10, 2014
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 ) {
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 ) {
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
  }
176
  }
177
 
178
  /**
179
+ * _wp_post_revision_fields で追加した debug-preview フィールドに関連するリビジョン画面を表示
180
+ *
181
+ * @param string $value
182
+ * @param string $column
183
+ * @param WP_Post $post
184
  * @return string
185
  */
186
+ public function _wp_post_revision_field_debug_preview( $value, $column, $post ) {
 
 
 
187
  $output = '';
188
  $values = SCF::gets( $post->ID );
189
  foreach ( $values as $key => $value ) {
211
  }
212
 
213
  /**
214
+ * 現在の投稿のメタデータと送信されたメタデータが異なっていればリビジョンを保存する
215
+ *
216
+ * @param bool $check_for_changes
217
+ * @param WP_Post $last_revision
218
+ * @param WP_Post $post
219
  * @return bool false ならリビジョンとして保存される。
220
  */
221
+ public function wp_save_post_revision_check_for_changes( $check_for_changes, $last_revision, $post ) {
222
  $post_meta = array();
223
  $p = get_post_custom( $post->ID );
224
  foreach ( $p as $key => $value ) {
228
  }
229
  }
230
 
231
+ if ( isset( $_POST[SCF_Config::NAME] ) ) {
232
+ $serialized_post_meta = serialize( $post_meta );
233
+ $serialized_post_data = serialize( $_POST[SCF_Config::NAME] );
234
+ if ( $serialized_post_meta != $serialized_post_data ) {
235
+ return false;
236
+ }
237
  }
238
  return true;
239
  }
classes/class.scf.php CHANGED
@@ -1,17 +1,17 @@
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,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::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,12 +107,15 @@ 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::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,28 +164,28 @@ class SCF {
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,7 +197,7 @@ class SCF {
194
  if ( get_post_status( $value ) !== 'publish' )
195
  continue;
196
  }
197
- $post_meta[$_post_meta_key][$field_name] = $value;
198
  }
199
  }
200
  }
@@ -203,13 +206,13 @@ class SCF {
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,7 +252,6 @@ class SCF {
249
 
250
  /**
251
  * get_settings_posts
252
- * その投稿タイプで有効になっている SCF を取得
253
  * @param int $post_type
254
  * @param array $settings
255
  */
@@ -324,9 +326,7 @@ class SCF {
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,11 +381,10 @@ class SCF {
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,51 +392,13 @@ class SCF {
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
  }
1
  <?php
2
  /**
3
  * SCF
4
+ * Version : 1.0.2
5
  * Author : Takashi Kitajima
6
  * Created : September 23, 2014
7
+ * Modified : January 6, 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_sub_field( $post_id, $group['group-name'], $group['fields'] );
68
  }
69
  // グループ名と一致しない場合は一致するフィールドを返す
70
  else {
71
+ foreach ( $group['fields'] as $field ) {
72
+ $return_post_meta[$field['name']] = $post_meta = self::get_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_sub_field( $post_id, $name, $group['fields'] );
111
  }
112
  // グループ名と一致しない場合は一致するフィールドを返す
113
  else {
114
+ foreach ( $group['fields'] as $field ) {
115
+ if ( $field['name'] !== $name ) {
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
  }
165
 
166
  /**
167
+ * get_sub_field
168
  * @param int $post_id
169
  * @param string $group_name
170
  * @param array $fields
171
  * @return mixed $post_meta
172
  */
173
+ protected static function get_sub_field( $post_id, $group_name, $fields ) {
174
  $post_meta = array();
175
+ foreach ( $fields as $field ) {
176
+ $_post_meta = get_post_meta( $post_id, $field['name'] );
177
  // チェックボックスの場合
178
  $repeat_multiple_data = self::get_repeat_multiple_data( $post_id );
179
+ if ( is_array( $repeat_multiple_data ) && array_key_exists( $field['name'], $repeat_multiple_data ) ) {
180
  $start = 0;
181
+ foreach ( $repeat_multiple_data[$field['name']] as $repeat_multiple_key => $repeat_multiple_value ) {
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][$field['name']] = $value;
189
  }
190
  }
191
  // チェックボックス以外
197
  if ( get_post_status( $value ) !== 'publish' )
198
  continue;
199
  }
200
+ $post_meta[$_post_meta_key][$field['name']] = $value;
201
  }
202
  }
203
  }
206
  }
207
 
208
  /**
209
+ * get_field
210
  * @param int $post_id
211
  * @param array $field
212
+ * @param bool $is_repeat
213
  * @return mixed $post_meta
214
  */
215
+ protected static function get_field( $post_id, $field, $is_repeat, $name = null ) {
216
  if ( $field['allow-multiple-data'] || $is_repeat ) {
217
  $post_meta = get_post_meta( $post_id, $field['name'] );
218
  } else {
252
 
253
  /**
254
  * get_settings_posts
 
255
  * @param int $post_type
256
  * @param array $settings
257
  */
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]['allow-multiple-data'] = self::$fields[$field['type']]->allow_multiple_data();
 
 
330
  }
331
  }
332
  }
381
  }
382
 
383
  /**
384
+ * add_field_instance
 
385
  * @param Smart_Custom_Fields_Field_Base $instance
386
  */
387
+ public static function add_field_instance( Smart_Custom_Fields_Field_Base $instance ) {
388
  $instance_name = $instance->get_name();
389
  if ( !empty( $instance_name ) ) {
390
  self::$fields[$instance_name] = $instance;
392
  }
393
 
394
  /**
395
+ * get_field_instance
396
+ * @param string $field_name フォームアイテムの name
 
397
  * @param Smart_Custom_Fields_Field_Base
398
  */
399
+ public static function get_field_instance( $field_name ) {
400
  if ( !empty( self::$fields[$field_name] ) ) {
401
  return self::$fields[$field_name];
402
  }
403
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
404
  }
classes/class.settings.php CHANGED
@@ -1,10 +1,10 @@
1
  <?php
2
  /**
3
  * Smart_Custom_Fields_Settings
4
- * Version : 1.0.2
5
  * Author : Takashi Kitajima
6
  * Created : September 23, 2014
7
- * Modified : January 22, 2015
8
  * License : GPLv2
9
  * License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
  */
@@ -128,9 +128,8 @@ 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"><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>
135
  <input type="checkbox"
136
  name="<?php echo esc_attr( SCF_Config::NAME . '[' . $group_key . '][repeat]' ); ?>"
@@ -161,14 +160,9 @@ class Smart_Custom_Fields_Settings {
161
  $field_label = $this->get( 'label', $field );
162
  if ( !$field_label ) {
163
  $field_label = $this->get( 'name', $field );
164
- if ( !$field_label ) {
165
- $field_label = "&nbsp;";
166
- }
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>
174
  <th><?php esc_html_e( 'Name', 'smart-custom-fields' ); ?><span class="<?php echo esc_attr( SCF_Config::PREFIX . 'require' ); ?>">*</span></th>
1
  <?php
2
  /**
3
  * Smart_Custom_Fields_Settings
4
+ * Version : 1.0.1
5
  * Author : Takashi Kitajima
6
  * Created : September 23, 2014
7
+ * Modified : October 10, 2014
8
  * License : GPLv2
9
  * License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
  */
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"><b>x</b></div>
132
  <div class="<?php echo esc_attr( SCF_Config::PREFIX . 'group-repeat' ); ?>">
 
133
  <label>
134
  <input type="checkbox"
135
  name="<?php echo esc_attr( SCF_Config::NAME . '[' . $group_key . '][repeat]' ); ?>"
160
  $field_label = $this->get( 'label', $field );
161
  if ( !$field_label ) {
162
  $field_label = $this->get( 'name', $field );
 
 
 
163
  }
164
  ?>
165
+ <div class="btn-remove-field"><span><?php echo esc_html( $field_label ); ?></span><b>x</b></div>
 
 
166
  <table class="<?php $this->add_hide_class( !$this->get( 'name', $field ) ); ?>">
167
  <tr>
168
  <th><?php esc_html_e( 'Name', 'smart-custom-fields' ); ?><span class="<?php echo esc_attr( SCF_Config::PREFIX . 'require' ); ?>">*</span></th>
classes/fields/class.field-check.php CHANGED
@@ -1,10 +1,10 @@
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,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 = SCF::choices_eol_to_array( $field['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.1
5
  * Author : Takashi Kitajima
6
  * Created : October 7, 2014
7
+ * Modified : October 10, 2014
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 = $this->get_choices( $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.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,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 = SCF::choices_eol_to_array( $field['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.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
  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 = $this->get_choices( $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.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,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 = SCF::choices_eol_to_array( $field['choices'] );
35
 
36
  $form_field = '';
37
  foreach ( $choices as $choice ) {
1
  <?php
2
  /**
3
  * Smart_Custom_Fields_Field_Select
4
+ * Version : 1.0.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
  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 = $this->get_choices( $field['choices'] );
35
 
36
  $form_field = '';
37
  foreach ( $choices as $choice ) {
css/settings.css CHANGED
@@ -1,9 +1,9 @@
1
  /**
2
  * settings.css
3
- * Version : 1.0.1
4
  * Author : Takashi Kitajima
5
  * Created : September 23, 2014
6
- * Modified : January 22, 2015
7
  * License : GPLv2
8
  * License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
  */
@@ -48,15 +48,9 @@
48
  .smart-cf-group .btn-remove-group {
49
  cursor: pointer;
50
  position: absolute;
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
@@ -69,12 +63,9 @@
69
  * .smart-cf-group-repeat
70
  */
71
  .smart-cf-group .smart-cf-group-repeat {
 
72
  margin: 0 0 5px;
73
  }
74
- .smart-cf-group .smart-cf-group-repeat label {
75
- position: relative;
76
- top: -2px;
77
- }
78
 
79
  /**
80
  * .smart-cf-group-names
@@ -97,13 +88,6 @@
97
  margin-top: 2px 0;
98
  }
99
 
100
- /** ==================================================
101
- * .smart-cf-fields
102
- */
103
- .smart-cf-group .smart-cf-fields {
104
- margin-top: 7px;
105
- }
106
-
107
  /** ==================================================
108
  * .smart-cf-field
109
  */
@@ -112,8 +96,6 @@
112
  border: #ddd solid 1px;
113
  margin: 5px 0 0;
114
  padding: 10px;
115
- overflow: hidden;
116
- *zoom: 1;
117
  }
118
  .smart-cf-group .smart-cf-field:first-child {
119
  margin-top: 0;
@@ -138,37 +120,17 @@
138
  }
139
 
140
  /**
141
- * .smart-cf-icon-handle
142
- */
143
- .smart-cf-group .smart-cf-field .smart-cf-icon-handle {
144
- float: left;
145
- margin-top: 4px;
146
- margin-right: 8px;
147
- }
148
-
149
- /**
150
- * .field-label
151
  */
152
- .smart-cf-group .smart-cf-field .field-label {
153
- cursor: pointer;
154
  position: relative;
155
  overflow: hidden;
156
  *zoom: 1;
157
  }
158
-
159
- /**
160
- * .btn-remove-field
161
- */
162
- .smart-cf-group .smart-cf-field .btn-remove-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
@@ -193,17 +155,3 @@
193
  .smart-cf-group .smart-cf-field table.hide {
194
  display: none;
195
  }
196
-
197
- /** ==================================================
198
- * classes
199
- */
200
- .smart-cf-icon-handle {
201
- background: url( ../images/handle.png ) no-repeat;
202
- cursor: move;
203
- display: inline-block;
204
- margin-right: 10px;
205
- height: 10px;
206
- width: 10px;
207
- overflow: hidden;
208
- position: relative;
209
- }
1
  /**
2
  * settings.css
3
+ * Version : 1.0.0
4
  * Author : Takashi Kitajima
5
  * Created : September 23, 2014
6
+ * Modified :
7
  * License : GPLv2
8
  * License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
  */
48
  .smart-cf-group .btn-remove-group {
49
  cursor: pointer;
50
  position: absolute;
51
+ top: 12px;
52
  right: 10px;
53
  }
 
 
 
 
 
 
54
 
55
  /**
56
  * .btn-add-field
63
  * .smart-cf-group-repeat
64
  */
65
  .smart-cf-group .smart-cf-group-repeat {
66
+ cursor: move;
67
  margin: 0 0 5px;
68
  }
 
 
 
 
69
 
70
  /**
71
  * .smart-cf-group-names
88
  margin-top: 2px 0;
89
  }
90
 
 
 
 
 
 
 
 
91
  /** ==================================================
92
  * .smart-cf-field
93
  */
96
  border: #ddd solid 1px;
97
  margin: 5px 0 0;
98
  padding: 10px;
 
 
99
  }
100
  .smart-cf-group .smart-cf-field:first-child {
101
  margin-top: 0;
120
  }
121
 
122
  /**
123
+ * .btn-remove-field
 
 
 
 
 
 
 
 
 
124
  */
125
+ .smart-cf-group .smart-cf-field .btn-remove-field {
126
+ cursor: move;
127
  position: relative;
128
  overflow: hidden;
129
  *zoom: 1;
130
  }
131
+ .smart-cf-group .smart-cf-field .btn-remove-field b {
 
 
 
 
 
132
  float: right;
133
  }
 
 
 
 
 
 
134
 
135
  /** ==================================================
136
  * #smart-cf-meta-box-condition
155
  .smart-cf-group .smart-cf-field table.hide {
156
  display: none;
157
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
js/settings.js CHANGED
@@ -1,9 +1,9 @@
1
  /**
2
  * settings.js
3
- * Version : 1.0.1
4
  * Author : Takashi Kitajima
5
  * Created : September 23, 2014
6
- * Modified : January 22, 2015
7
  * License : GPLv2
8
  * License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
  */
@@ -13,7 +13,7 @@ jQuery( function( $ ) {
13
  var btn_add_group = wrapper.find( '.btn-add-group' );
14
  var btn_remove_group = wrapper.find( '.btn-remove-group b' );
15
  var btn_add_field = wrapper.find( '.btn-add-field' );
16
- var btn_remove_field = wrapper.find( '.btn-remove-field' );
17
  var group_class = '.smart-cf-group';
18
  var field_class = '.smart-cf-field';
19
  var duplicate_alert_class = '.smart-cf-duplicate-alert';
@@ -56,21 +56,21 @@ jQuery( function( $ ) {
56
  */
57
  $( '.smart-cf-groups' ).sortable( {
58
  cursor: 'move',
59
- handle: '.smart-cf-icon-handle'
60
  } );
61
  $( '.smart-cf-fields' ).sortable( {
62
  cursor: 'move',
63
- handle: '.smart-cf-icon-handle'
64
  } );
65
 
66
  /**
67
  * フィールドの開閉
68
  */
69
- $( '.field-label' ).click( function() {
70
- var field_label = $( this );
71
  var table = $( this ).parents( field_class ).find( 'table' );
72
  if ( table.hasClass( 'hide' ) ) {
73
- field_label.html( "&nbsp;" );
74
  table.fadeIn( 'fast', function() {
75
  $( this ).removeClass( 'hide' );
76
  } );
@@ -81,11 +81,7 @@ jQuery( function( $ ) {
81
  }
82
  table.fadeOut( 'fast', function() {
83
  $( this ).addClass( 'hide' );
84
- if ( label ) {
85
- field_label.text( label );
86
- } else {
87
- field_label.html( "&nbsp;" );
88
- }
89
  } );
90
  }
91
  } );
1
  /**
2
  * settings.js
3
+ * Version : 1.0.0
4
  * Author : Takashi Kitajima
5
  * Created : September 23, 2014
6
+ * Modified :
7
  * License : GPLv2
8
  * License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
  */
13
  var btn_add_group = wrapper.find( '.btn-add-group' );
14
  var btn_remove_group = wrapper.find( '.btn-remove-group b' );
15
  var btn_add_field = wrapper.find( '.btn-add-field' );
16
+ var btn_remove_field = wrapper.find( '.btn-remove-field b' );
17
  var group_class = '.smart-cf-group';
18
  var field_class = '.smart-cf-field';
19
  var duplicate_alert_class = '.smart-cf-duplicate-alert';
56
  */
57
  $( '.smart-cf-groups' ).sortable( {
58
  cursor: 'move',
59
+ handle: '.smart-cf-group-repeat'
60
  } );
61
  $( '.smart-cf-fields' ).sortable( {
62
  cursor: 'move',
63
+ handle: '.btn-remove-field'
64
  } );
65
 
66
  /**
67
  * フィールドの開閉
68
  */
69
+ $( '.btn-remove-field' ).click( function() {
70
+ var btn_remove_field_slide = $( this );
71
  var table = $( this ).parents( field_class ).find( 'table' );
72
  if ( table.hasClass( 'hide' ) ) {
73
+ btn_remove_field_slide.find( 'span' ).text( '' );
74
  table.fadeIn( 'fast', function() {
75
  $( this ).removeClass( 'hide' );
76
  } );
81
  }
82
  table.fadeOut( 'fast', function() {
83
  $( this ).addClass( 'hide' );
84
+ btn_remove_field_slide.find( 'span' ).text( label );
 
 
 
 
85
  } );
86
  }
87
  } );
readme.txt CHANGED
@@ -1,10 +1,10 @@
1
  === Smart Custom Fields ===
2
- Contributors: inc2734, toro_unit
3
  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.3
8
  License: GPLv2
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -62,19 +62,6 @@ https://github.com/inc2734/smart-custom-fields/
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
-
75
- = 1.1.1 =
76
- * UX Improvement of settings page.
77
-
78
  = 1.1.0 =
79
  * Add date picker field.
80
 
1
  === Smart Custom Fields ===
2
+ Contributors: inc2734
3
  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.0
8
  License: GPLv2
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
62
 
63
  == Changelog ==
64
 
 
 
 
 
 
 
 
 
 
 
 
 
 
65
  = 1.1.0 =
66
  * Add date picker field.
67
 
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.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
@@ -63,9 +63,7 @@ class Smart_Custom_Fields {
63
  new $classname();
64
  }
65
  }
66
-
67
- do_action( SCF_Config::PREFIX . 'fields-loaded' );
68
-
69
  add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
70
  add_action( 'add_meta_boxes', array( $this, 'add_meta_boxes' ), 10, 2 );
71
  add_action( 'save_post', array( $this, 'save_post' ) );
@@ -220,20 +218,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_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,15 +325,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_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,10 +434,10 @@ class Smart_Custom_Fields {
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,9 +445,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::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,7 +457,7 @@ class Smart_Custom_Fields {
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,7 +471,7 @@ class Smart_Custom_Fields {
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 ),
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.0
7
  * Author: Takashi Kitajima
8
  * Author URI: http://2inc.org
9
  * Created: October 9, 2014
10
+ * Modified: January 18, 2015
11
  * Text Domain: smart-custom-fields
12
  * Domain Path: /languages/
13
  * License: GPLv2
63
  new $classname();
64
  }
65
  }
66
+
 
 
67
  add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
68
  add_action( 'add_meta_boxes', array( $this, 'add_meta_boxes' ), 10, 2 );
69
  add_action( 'save_post', array( $this, 'save_post' ) );
218
  foreach ( $settings as $setting ) {
219
  foreach ( $setting as $group ) {
220
  $is_repeat = ( isset( $group['repeat'] ) && $group['repeat'] === true ) ? true : false;
221
+ foreach ( $group['fields'] as $field ) {
222
+ delete_post_meta( $post_id, $field['name'] );
223
 
224
  if ( $field['allow-multiple-data'] ) {
225
+ $multiple_data_fields[] = $field['name'];
226
  }
227
 
228
  if ( $is_repeat && $field['allow-multiple-data'] ) {
229
+ $repeat_multiple_data_fields = $_POST[SCF_Config::NAME][$field['name']];
230
  foreach ( $repeat_multiple_data_fields as $values ) {
231
  if ( is_array( $values ) ) {
232
+ $repeat_multiple_data[$field['name']][] = count( $values );
233
  } else {
234
+ $repeat_multiple_data[$field['name']][] = 0;
235
  }
236
  }
237
  }
325
  // ループだけどループがないとき(新規登録時とか)は1つだけ入れる
326
  if ( isset( $group['repeat'] ) && $group['repeat'] === true ) {
327
  $loop_count = 1;
328
+ foreach ( $group['fields'] as $field ) {
329
+ if ( isset( $post_custom[$field['name']] ) && is_array( $post_custom[$field['name']] ) ) {
330
+ $post_meta = $post_custom[$field['name']];
331
  $post_meta_count = count( $post_meta );
332
  // 同名のカスタムフィールドが複数のとき(チェックボックス or ループ)
333
  if ( $post_meta_count > 1 ) {
334
  // チェックボックスの場合
335
+ if ( is_array( $repeat_multiple_data ) && array_key_exists( $field['name'], $repeat_multiple_data ) ) {
336
+ $repeat_multiple_data_count = count( $repeat_multiple_data[$field['name']] );
337
  if ( $loop_count < $repeat_multiple_data_count )
338
  $loop_count = $repeat_multiple_data_count;
339
  }
434
  $btn_repeat
435
  );
436
 
437
+ foreach ( $fields as $field ) {
438
  $field_label = $field['label'];
439
  if ( !$field_label ) {
440
+ $field_label = $field['name'];
441
  }
442
 
443
  // 複数値許可フィールドのとき
445
  if ( $field['allow-multiple-data'] ) {
446
  $value = array();
447
  if ( !SCF::is_empty( $field['default'] ) && ( $post_status === 'auto-draft' || is_null( $index ) ) ) {
448
+ $value = SCF::get_field_instance( $field['type'] )->get_choices( $field['default'] );
449
  }
450
+ $_value = $this->get_multiple_data_field_value( $post_id, $field['name'], $index );
451
  }
452
  // 複数不値許可フィールドのとき
453
  else {
457
  $value = $field['default'];
458
  }
459
  }
460
+ $_value = $this->get_single_data_field_value( $post_id, $field['name'], $index );
461
  }
462
  if ( !is_null( $_value ) ) {
463
  $value = $_value;
471
  );
472
  }
473
 
474
+ $form_field = SCF::get_field_instance( $field['type'] )->get_field( $field, $index, $value );
475
  printf(
476
  '<tr><th>%s</th><td>%s%s</td></tr>',
477
  esc_html( $field_label ),