Smart Custom Fields - Version 1.2.0

Version Description

  • refactoring. A lot of changes in all.
  • Renewd the Smart_Custom_Fields_Field_Base.
  • Add filter hook smart-cf-register-fields. If You use this hook, you can define custom fields by the code.
  • Add action hook smart-cf-before-editor-enqueue-scripts
  • Add action hook smart-cf-after-editor-enqueue-scripts
  • Add action hook smart-cf-before-settings-enqueue-scripts
  • Add action hook smart-cf-after-settings-enqueue-scripts
Download this release

Release Info

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

Code changes from version 1.1.0 to 1.2.0

classes/class.field-base.php DELETED
@@ -1,190 +0,0 @@
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
- */
11
- abstract class Smart_Custom_Fields_Field_Base {
12
-
13
- /**
14
- * $name
15
- */
16
- protected $name;
17
-
18
- /**
19
- * $label
20
- */
21
- protected $label;
22
-
23
- /**
24
- * $allow_multiple_data
25
- */
26
- protected $allow_multiple_data = false;
27
-
28
- /**
29
- * $field
30
- */
31
- protected $field = array();
32
-
33
- /**
34
- * __construct
35
- */
36
- public function __construct() {
37
- $settings = $this->init();
38
- if ( !empty( $settings['name'] ) ) {
39
- $this->name = $settings['name'];
40
- }
41
- if ( !empty( $settings['label'] ) ) {
42
- $this->label = $settings['label'];
43
- }
44
- if ( !$this->name || !$this->label ) {
45
- exit;
46
- }
47
- if ( empty( $settings['optgroup'] ) ) {
48
- $settings['optgroup'] = 'basic-fields';
49
- }
50
- if ( isset( $settings['allow-multiple-data'] ) && $settings['allow-multiple-data'] === true ) {
51
- $this->allow_multiple_data = true;
52
- }
53
- add_filter( SCF_Config::PREFIX . 'field-select-' . $settings['optgroup'], array( $this, 'field_select' ) );
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
- /**
61
- * init
62
- * @return array ( name, label, optgroup, allow-multiple-data )
63
- */
64
- abstract protected function init();
65
-
66
- /**
67
- * after_loaded
68
- */
69
- protected function after_loaded() {
70
- }
71
-
72
- /**
73
- * get_field
74
- * @param array $field フィールドの情報
75
- * @param int $index インデックス番号
76
- * @param mixed $value 保存されている値(check のときだけ配列)
77
- * @return string html
78
- */
79
- abstract public function get_field( $field, $index, $value );
80
-
81
- /**
82
- * field_select
83
- * @param array $options その optgroup に属するフィールドのリスト
84
- * @return array $options
85
- */
86
- public function field_select( $options ) {
87
- $options[$this->name] = $this->label;
88
- return $options;
89
- }
90
-
91
- /**
92
- * display_field_options
93
- * @param int $group_key
94
- * @param int $field_key
95
- */
96
- abstract protected function display_field_options( $group_key, $field_key );
97
- public function _display_field_options( $group_key, $field_key, $field ) {
98
- $this->field = $field;
99
- ?>
100
- <tr class="<?php echo esc_attr( SCF_Config::PREFIX . 'field-options' ); ?> <?php echo esc_attr( SCF_Config::PREFIX . 'field-options-' . $this->name ); ?> hide">
101
- <td colspan="2">
102
- <table>
103
- <?php $this->display_field_options( $group_key, $field_key ); ?>
104
- </table>
105
- </td>
106
- </tr>
107
- <?php
108
- }
109
-
110
- /**
111
- * get_name_attribute
112
- * @param string $name 定義されたフィールドの name
113
- * @param string $index 添字
114
- * @return string
115
- */
116
- protected function get_name_attribute( $name, $index ) {
117
- return SCF_Config::NAME . '[' . $name . '][_' . $index . ']';
118
- }
119
-
120
- /**
121
- * get_disable_attribute
122
- * @param string $index 添字
123
- * @return bool $disabled
124
- */
125
- protected function get_disable_attribute( $index ) {
126
- $disabled = false;
127
- if ( is_null( $index ) ) {
128
- $disabled = true;
129
- }
130
- return $disabled;
131
- }
132
-
133
- /**
134
- * get_field_name
135
- * フィールド設定画面で使用する name 属性を返す
136
- */
137
- protected function get_field_name( $group_key, $field_key, $name ) {
138
- return sprintf(
139
- '%s[%d][fields][%d][%s]',
140
- SCF_Config::NAME,
141
- $group_key,
142
- $field_key,
143
- $name
144
- );
145
- }
146
-
147
- /**
148
- * get_field_value
149
- * フィールド設定画面で使用する value を返す
150
- */
151
- protected function get_field_value( $name ) {
152
- return $this->get( $name, $this->field );
153
- }
154
-
155
- /**
156
- * get
157
- * @param string $key 取得したいデータのキー
158
- * @param array $data データ配列
159
- * @return mixed
160
- */
161
- protected function get( $key, array $data ) {
162
- if ( isset( $data[$key] ) ) {
163
- return $data[$key];
164
- }
165
- }
166
-
167
- /**
168
- * get_name
169
- * @return string
170
- */
171
- public function get_name() {
172
- return $this->name;
173
- }
174
-
175
- /**
176
- * get_allow_multiple_data
177
- */
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.scf.php CHANGED
@@ -1,48 +1,53 @@
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
 
18
  /**
19
  * データ取得処理は重いので、一度取得したデータは cache に保存する。
20
  * キーに post_id を設定すること。
 
21
  */
22
  protected static $cache = array();
23
 
24
  /**
25
  * データ取得処理は重いので、一度取得した設定データは settings_posts_cache に保存する。
26
  * キーに post_type を設定すること。
 
27
  */
28
  protected static $settings_posts_cache = array();
29
 
30
  /**
31
  * データ取得処理は重いので、一度取得した設定データは cache に保存する。
32
  * キーに post_type を設定すること。
 
33
  */
34
  protected static $settings_cache = array();
35
 
36
  /**
37
  * データ取得処理は重いので、一度取得した設定データは cache に保存する。
38
  * キーに post_id を設定すること。
 
39
  */
40
  protected static $repeat_multiple_data_cache = array();
41
 
42
  /**
43
- * gets
44
  * その投稿の全てのメタデータを良い感じに取得
45
- * @param $post_id
 
46
  * @return array
47
  */
48
  public static function gets( $post_id = null ) {
@@ -51,35 +56,34 @@ class SCF {
51
  }
52
  $post_id = self::get_real_post_id( $post_id );
53
 
54
- $repeat_multiple_data = self::get_repeat_multiple_data( $post_id );
55
-
56
  // 設定画面で未設定のメタデータは投稿が保持していても出力しないようにしないといけないので
57
  // 設定データを取得して出力して良いか判別する
58
- $post_type = get_post_type( $post_id );
59
- $settings = self::get_settings( $post_type );
60
-
61
- $return_post_meta = array();
62
- foreach ( $settings as $setting ) {
63
- foreach ( $setting as $group ) {
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
  }
76
  }
77
- return $return_post_meta;
78
  }
79
 
80
  /**
81
- * get
82
  * その投稿の任意のメタデータを良い感じに取得
 
83
  * @param string $name グループ名もしくはフィールド名
84
  * @param int $post_id
85
  * @return mixed
@@ -88,36 +92,32 @@ class SCF {
88
  if ( is_null( $post_id ) ) {
89
  $post_id = get_the_ID();
90
  }
91
-
92
  $post_id = self::get_real_post_id( $post_id );
93
 
94
  if ( self::get_cache( $post_id, $name ) ) {
95
  return self::get_cache( $post_id, $name );
96
  }
97
 
98
- $repeat_multiple_data = self::get_repeat_multiple_data( $post_id );
99
-
100
  // 設定画面で未設定のメタデータは投稿が保持していても出力しないようにしないといけないので
101
  // 設定データを取得して出力して良いか判別する
102
- $post_type = get_post_type( $post_id );
103
- $settings = self::get_settings( $post_type );
104
-
105
- foreach ( $settings as $setting ) {
106
- foreach ( $setting as $group ) {
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
  }
122
  }
123
  }
@@ -125,6 +125,27 @@ class SCF {
125
  }
126
  }
127
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
128
  protected static function get_real_post_id( $post_id ) {
129
  if ( is_preview() ) {
130
  $preview_post = wp_get_post_autosave( $post_id );
@@ -136,7 +157,8 @@ class SCF {
136
  }
137
 
138
  /**
139
- * save_cache
 
140
  * @param int $post_id
141
  * @param string $name
142
  * @param mixed $data
@@ -146,7 +168,8 @@ class SCF {
146
  }
147
 
148
  /**
149
- * get_cache
 
150
  * @param int $post_id
151
  * @param string $name
152
  * @return mixed
@@ -164,61 +187,78 @@ class SCF {
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
  // チェックボックス以外
192
  else {
 
193
  foreach ( $_post_meta as $_post_meta_key => $value ) {
194
- if ( in_array( $field['type'], array( 'wysiwyg' ) ) ) {
 
195
  $value = apply_filters( 'the_content', $value );
196
- } elseif ( $field['type'] === 'relation' ) {
197
- if ( get_post_status( $value ) !== 'publish' )
 
 
198
  continue;
 
199
  }
200
- $post_meta[$_post_meta_key][$field['name']] = $value;
201
  }
202
  }
203
  }
204
- self::save_cache( $post_id, $group_name, $post_meta );
205
  return $post_meta;
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 {
219
- $post_meta = get_post_meta( $post_id, $field['name'], true );
220
  }
221
- if ( in_array( $field['type'], array( 'wysiwyg' ) ) ) {
 
 
222
  if ( is_array( $post_meta ) ) {
223
  $_post_meta = array();
224
  foreach ( $post_meta as $key => $value ) {
@@ -228,21 +268,24 @@ class SCF {
228
  } else {
229
  $post_meta = apply_filters( 'the_content', $post_meta );
230
  }
231
- } elseif ( $field['type'] === 'relation' ) {
232
  $_post_meta = array();
233
- foreach ( $post_meta as $post_id ) {
234
- if ( get_post_status( $post_id ) !== 'publish' )
235
- continue;
236
- $_post_meta[] = $post_id;
 
 
237
  }
238
  $post_meta = $_post_meta;
239
  }
240
- self::save_cache( $post_id, $field['name'], $post_meta );
241
  return $post_meta;
242
  }
243
 
244
  /**
245
- * save_settings_posts_cache
 
246
  * @param int $post_type
247
  * @param array $posts
248
  */
@@ -251,7 +294,8 @@ class SCF {
251
  }
252
 
253
  /**
254
- * get_settings_posts
 
255
  * @param int $post_type
256
  * @param array $settings
257
  */
@@ -264,6 +308,8 @@ class SCF {
264
  $_posts = get_posts( array(
265
  'post_type' => SCF_Config::NAME,
266
  'posts_per_page' => -1,
 
 
267
  'meta_query' => array(
268
  array(
269
  'key' => SCF_Config::PREFIX . 'condition',
@@ -289,13 +335,16 @@ class SCF {
289
  }
290
  $posts[] = $_post;
291
  }
 
 
292
  }
293
  self::save_settings_posts_cache( $post_type, $posts );
294
  return $posts;
295
  }
296
 
297
  /**
298
- * save_settings_cache
 
299
  * @param int $post_type
300
  * @param array $settings
301
  */
@@ -304,39 +353,28 @@ class SCF {
304
  }
305
 
306
  /**
307
- * get_settings
 
308
  * @param int $post_type
309
  * @param array $settings
310
  */
311
  public static function get_settings( $post_type ) {
312
- $settings = array();
313
  if ( isset( self::$settings_cache[$post_type] ) ) {
314
  return self::$settings_cache[$post_type];
315
  }
316
- if ( empty( $settings ) ) {
317
- $cf_posts = self::get_settings_posts( $post_type );
318
- foreach ( $cf_posts as $_post ) {
319
- $setting = array();
320
- $_setting = get_post_meta( $_post->ID, SCF_Config::PREFIX . 'setting', true );
321
- if ( is_array( $_setting ) ) {
322
- $setting = $_setting;
323
- }
324
- $settings[SCF_Config::PREFIX . 'custom-field-' . $_post->ID] = $setting;
325
- }
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
- }
333
  }
 
334
  self::save_settings_cache( $post_type, $settings );
335
  return $settings;
336
  }
337
 
338
  /**
339
- * save_repeat_multiple_data_cache
 
340
  * @param int $post_id
341
  * @param mixed $repeat_multiple_data
342
  */
@@ -345,7 +383,8 @@ class SCF {
345
  }
346
 
347
  /**
348
- * get_repeat_multiple_data
 
349
  * @param int $post_id
350
  * @return mixed
351
  */
@@ -365,8 +404,8 @@ class SCF {
365
  }
366
 
367
  /**
368
- * is_empty
369
  * null もしくは空値の場合は true
 
370
  * @param mixed $value
371
  * @return bool
372
  */
@@ -381,24 +420,63 @@ class SCF {
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;
391
  }
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
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  <?php
2
  /**
3
  * SCF
4
+ * Version : 1.1.0
5
  * Author : Takashi Kitajima
6
  * Created : September 23, 2014
7
+ * Modified : February 27, 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
+ * @var array
16
  */
17
  protected static $fields = array();
18
 
19
  /**
20
  * データ取得処理は重いので、一度取得したデータは cache に保存する。
21
  * キーに post_id を設定すること。
22
+ * @var array
23
  */
24
  protected static $cache = array();
25
 
26
  /**
27
  * データ取得処理は重いので、一度取得した設定データは settings_posts_cache に保存する。
28
  * キーに post_type を設定すること。
29
+ * @var array
30
  */
31
  protected static $settings_posts_cache = array();
32
 
33
  /**
34
  * データ取得処理は重いので、一度取得した設定データは cache に保存する。
35
  * キーに post_type を設定すること。
36
+ * @var array
37
  */
38
  protected static $settings_cache = array();
39
 
40
  /**
41
  * データ取得処理は重いので、一度取得した設定データは cache に保存する。
42
  * キーに post_id を設定すること。
43
+ * @var array
44
  */
45
  protected static $repeat_multiple_data_cache = array();
46
 
47
  /**
 
48
  * その投稿の全てのメタデータを良い感じに取得
49
+ *
50
+ * @param int $post_id
51
  * @return array
52
  */
53
  public static function gets( $post_id = null ) {
56
  }
57
  $post_id = self::get_real_post_id( $post_id );
58
 
 
 
59
  // 設定画面で未設定のメタデータは投稿が保持していても出力しないようにしないといけないので
60
  // 設定データを取得して出力して良いか判別する
61
+ $post_type = self::get_public_post_type( $post_id );
62
+ $settings = self::get_settings( $post_type );
63
+ $post_meta = array();
64
+ foreach ( $settings as $Setting ) {
65
+ $groups = $Setting->get_groups();
66
+ foreach ( $groups as $Group ) {
67
+ $is_repeatable = $Group->is_repeatable();
68
+ $group_name = $Group->get_name();
69
+ if ( $is_repeatable && $group_name ) {
70
+ $post_meta[$group_name] = self::get_values_by_group( $post_id, $Group );
71
  }
 
72
  else {
73
+ $fields = $Group->get_fields();
74
+ foreach ( $fields as $Field ) {
75
+ $field_name = $Field->get( 'name' );
76
+ $post_meta[$field_name] = self::get_value_by_field( $post_id, $Field, $is_repeatable );
77
  }
78
  }
79
  }
80
  }
81
+ return $post_meta;
82
  }
83
 
84
  /**
 
85
  * その投稿の任意のメタデータを良い感じに取得
86
+ *
87
  * @param string $name グループ名もしくはフィールド名
88
  * @param int $post_id
89
  * @return mixed
92
  if ( is_null( $post_id ) ) {
93
  $post_id = get_the_ID();
94
  }
 
95
  $post_id = self::get_real_post_id( $post_id );
96
 
97
  if ( self::get_cache( $post_id, $name ) ) {
98
  return self::get_cache( $post_id, $name );
99
  }
100
 
 
 
101
  // 設定画面で未設定のメタデータは投稿が保持していても出力しないようにしないといけないので
102
  // 設定データを取得して出力して良いか判別する
103
+ $post_type = self::get_public_post_type( $post_id );
104
+ $settings = self::get_settings( $post_type );
105
+ foreach ( $settings as $Setting ) {
106
+ $groups = $Setting->get_groups();
107
+ foreach ( $groups as $Group ) {
108
  // グループ名と一致する場合はそのグループ内のフィールドを配列で返す
109
+ $is_repeatable = $Group->is_repeatable();
110
+ $group_name = $Group->get_name();
111
+ if ( $is_repeatable && $group_name && $group_name === $name ) {
112
+ return self::get_values_by_group( $post_id, $Group );
113
  }
114
  // グループ名と一致しない場合は一致するフィールドを返す
115
  else {
116
+ $fields = $Group->get_fields();
117
+ foreach ( $fields as $Field ) {
118
+ $field_name = $Field->get( 'name' );
119
+ if ( $field_name === $name ) {
120
+ return self::get_value_by_field( $post_id, $Field, $is_repeatable );
 
 
121
  }
122
  }
123
  }
125
  }
126
  }
127
 
128
+ /**
129
+ * Post ID がリビジョンのものでも良い感じに投稿タイプを取得
130
+ *
131
+ * @param int $post_id
132
+ * @return string
133
+ */
134
+ protected static function get_public_post_type( $post_id ) {
135
+ if ( $public_post_id = wp_is_post_revision( $post_id ) ) {
136
+ $post_type = get_post_type( $public_post_id );
137
+ } else {
138
+ $post_type = get_post_type( $post_id );
139
+ }
140
+ return $post_type;
141
+ }
142
+
143
+ /**
144
+ * プレビューのときはそのプレビューの Post ID を返す
145
+ *
146
+ * @param int $post_id
147
+ * @return int
148
+ */
149
  protected static function get_real_post_id( $post_id ) {
150
  if ( is_preview() ) {
151
  $preview_post = wp_get_post_autosave( $post_id );
157
  }
158
 
159
  /**
160
+ * キャシュに保存
161
+ *
162
  * @param int $post_id
163
  * @param string $name
164
  * @param mixed $data
168
  }
169
 
170
  /**
171
+ * キャッシュを取得
172
+ *
173
  * @param int $post_id
174
  * @param string $name
175
  * @return mixed
187
  }
188
 
189
  /**
190
+ * そのグループのメタデータを取得
191
+ *
192
  * @param int $post_id
193
+ * @param Smart_Custom_Fields_Group $Group
194
+ * @return mixed
 
195
  */
196
+ protected static function get_values_by_group( $post_id, $Group ) {
197
  $post_meta = array();
198
+ $fields = $Group->get_fields();
199
+ foreach ( $fields as $Field ) {
200
+ $field_name = $Field->get( 'name' );
201
+ if ( !$field_name ) {
202
+ continue;
203
+ }
204
+ $_post_meta = get_post_meta( $post_id, $field_name );
205
  // チェックボックスの場合
206
  $repeat_multiple_data = self::get_repeat_multiple_data( $post_id );
207
+ if ( is_array( $repeat_multiple_data ) && array_key_exists( $field_name, $repeat_multiple_data ) ) {
208
  $start = 0;
209
+ foreach ( $repeat_multiple_data[$field_name] as $repeat_multiple_key => $repeat_multiple_value ) {
210
  if ( $repeat_multiple_value === 0 ) {
211
  $value = array();
212
  } else {
213
+ $value = array_slice( $_post_meta, $start, $repeat_multiple_value );
214
  $start += $repeat_multiple_value;
215
  }
216
+ $post_meta[$repeat_multiple_key][$field_name] = $value;
217
  }
218
  }
219
  // チェックボックス以外
220
  else {
221
+ $field_type = $Field->get_attribute( 'type' );
222
  foreach ( $_post_meta as $_post_meta_key => $value ) {
223
+ // wysiwyg の場合はフィルタを通す
224
+ if ( $field_type === 'wysiwyg' ) {
225
  $value = apply_filters( 'the_content', $value );
226
+ }
227
+ // relation のときは $value = Post ID。公開済みでない場合は取得しない
228
+ elseif ( $field_type === 'relation' ) {
229
+ if ( get_post_status( $value ) !== 'publish' ) {
230
  continue;
231
+ }
232
  }
233
+ $post_meta[$_post_meta_key][$field_name] = $value;
234
  }
235
  }
236
  }
237
+ self::save_cache( $post_id, $Group->get_name(), $post_meta );
238
  return $post_meta;
239
  }
240
 
241
  /**
242
+ * そのフィールドのメタデータを取得
243
+ *
244
  * @param int $post_id
245
  * @param array $field
246
+ * @param bool $is_repeatable このフィールドが所属するグループが repeat かどうか
247
  * @return mixed $post_meta
248
  */
249
+ protected static function get_value_by_field( $post_id, $Field, $is_repeatable ) {
250
+ $field_name = $Field->get( 'name' );
251
+ if ( !$field_name ) {
252
+ return;
253
+ }
254
+ if ( $Field->get_attribute( 'allow-multiple-data' ) || $is_repeatable ) {
255
+ $post_meta = get_post_meta( $post_id, $field_name );
256
  } else {
257
+ $post_meta = get_post_meta( $post_id, $field_name, true );
258
  }
259
+
260
+ $field_type = $Field->get_attribute( 'type' );
261
+ if ( in_array( $field_type, array( 'wysiwyg' ) ) ) {
262
  if ( is_array( $post_meta ) ) {
263
  $_post_meta = array();
264
  foreach ( $post_meta as $key => $value ) {
268
  } else {
269
  $post_meta = apply_filters( 'the_content', $post_meta );
270
  }
271
+ } elseif ( $field_type === 'relation' ) {
272
  $_post_meta = array();
273
+ if ( is_array( $post_meta ) ) {
274
+ foreach ( $post_meta as $post_id ) {
275
+ if ( get_post_status( $post_id ) !== 'publish' )
276
+ continue;
277
+ $_post_meta[] = $post_id;
278
+ }
279
  }
280
  $post_meta = $_post_meta;
281
  }
282
+ self::save_cache( $post_id, $field_name, $post_meta );
283
  return $post_meta;
284
  }
285
 
286
  /**
287
+ * その投稿タイプで有効になっている SCF をキャッシュに保存
288
+ *
289
  * @param int $post_type
290
  * @param array $posts
291
  */
294
  }
295
 
296
  /**
297
+ * その投稿タイプで有効になっている SCF を取得
298
+ *
299
  * @param int $post_type
300
  * @param array $settings
301
  */
308
  $_posts = get_posts( array(
309
  'post_type' => SCF_Config::NAME,
310
  'posts_per_page' => -1,
311
+ 'order' => 'ASC',
312
+ 'order_by' => 'menu_order',
313
  'meta_query' => array(
314
  array(
315
  'key' => SCF_Config::PREFIX . 'condition',
335
  }
336
  $posts[] = $_post;
337
  }
338
+ } else {
339
+ $posts = $_posts;
340
  }
341
  self::save_settings_posts_cache( $post_type, $posts );
342
  return $posts;
343
  }
344
 
345
  /**
346
+ * Setting オブジェクト をキャッシュに保存
347
+ *
348
  * @param int $post_type
349
  * @param array $settings
350
  */
353
  }
354
 
355
  /**
356
+ * Setting オブジェクトの配列を取得
357
+ *
358
  * @param int $post_type
359
  * @param array $settings
360
  */
361
  public static function get_settings( $post_type ) {
 
362
  if ( isset( self::$settings_cache[$post_type] ) ) {
363
  return self::$settings_cache[$post_type];
364
  }
365
+ $settings = array();
366
+ $cf_posts = self::get_settings_posts( $post_type );
367
+ foreach ( $cf_posts as $post ) {
368
+ $settings[] = SCF::add_setting( $post->ID, $post->post_title );
 
 
 
 
 
 
 
 
 
 
 
 
 
369
  }
370
+ $settings = apply_filters( SCF_Config::PREFIX . 'register-fields', $settings, $post_type );
371
  self::save_settings_cache( $post_type, $settings );
372
  return $settings;
373
  }
374
 
375
  /**
376
+ * 繰り返しに設定された複数許可フィールドデータの区切り識別用データをキャッシュに保存
377
+ *
378
  * @param int $post_id
379
  * @param mixed $repeat_multiple_data
380
  */
383
  }
384
 
385
  /**
386
+ * 繰り返しに設定された複数許可フィールドデータの区切り識別用データを取得
387
+ *
388
  * @param int $post_id
389
  * @return mixed
390
  */
404
  }
405
 
406
  /**
 
407
  * null もしくは空値の場合は true
408
+ *
409
  * @param mixed $value
410
  * @return bool
411
  */
420
  }
421
 
422
  /**
423
+ * 使用可能なフォームフィールドオブジェクトを追加
424
+ *
425
  * @param Smart_Custom_Fields_Field_Base $instance
426
  */
427
+ public static function add_form_field_instance( Smart_Custom_Fields_Field_Base $instance ) {
428
+ $type = $instance->get_attribute( 'type' );
429
+ if ( !empty( $type ) ) {
430
+ self::$fields[$type] = $instance;
431
  }
432
  }
433
 
434
  /**
435
+ * 使用可能なフォームフィールドオブジェクトを取得
436
+ *
437
+ * @param string $type フォームフィールドの type
438
  * @param Smart_Custom_Fields_Field_Base
439
  */
440
+ public static function get_form_field_instance( $type ) {
441
+ if ( !empty( self::$fields[$type] ) ) {
442
+ return clone self::$fields[$type];
443
  }
444
  }
445
+
446
+ /**
447
+ * 全ての使用可能なフォームフィールドオブジェクトを取得
448
+ *
449
+ * @return array
450
+ */
451
+ public static function get_form_field_instances() {
452
+ $fields = array();
453
+ foreach ( self::$fields as $type => $instance ) {
454
+ $fields[$type] = self::get_form_field_instance( $type );
455
+ }
456
+ return $fields;
457
+ }
458
+
459
+ /**
460
+ * 改行区切りの $choices を配列に変換
461
+ *
462
+ * @param string $choices
463
+ * @return array
464
+ */
465
+ public static function choices_eol_to_array( $choices ) {
466
+ if ( !is_array( $choices ) ) {
467
+ $choices = str_replace( array( "\r\n", "\r", "\n" ), "\n", $choices );
468
+ return explode( "\n", $choices );
469
+ }
470
+ return $choices;
471
+ }
472
+
473
+ /**
474
+ * Setting を生成して返す
475
+ *
476
+ * @param string $id
477
+ * @param string $title
478
+ */
479
+ public static function add_setting( $id, $title ) {
480
+ return new Smart_Custom_Fields_Setting( $id, $title );
481
+ }
482
+ }
classes/controller/class.editor.php ADDED
@@ -0,0 +1,415 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Smart_Custom_Fields_Controller_Editor
4
+ * Version : 1.0.0
5
+ * Author : Takashi Kitajima
6
+ * Created : September 23, 2014
7
+ * Modified : February 27, 2015
8
+ * License : GPLv2
9
+ * License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
+ */
11
+ class Smart_Custom_Fields_Controller_Editor {
12
+
13
+ /**
14
+ * post_custom 格納用。何度も関数呼び出ししなくて良いように保存
15
+ * @var array
16
+ */
17
+ protected $post_custom = array();
18
+
19
+ /**
20
+ * 各フォーム部品のオブジェクトを格納する配列
21
+ * @var array
22
+ */
23
+ protected $fields = array();
24
+
25
+ /**
26
+ * __construct
27
+ */
28
+ public function __construct() {
29
+ add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
30
+ add_action( 'add_meta_boxes' , array( $this, 'add_meta_boxes' ), 10, 2 );
31
+ add_action( 'save_post' , array( $this, 'save_post' ) );
32
+ }
33
+
34
+ /**
35
+ * 投稿画面用の css、js、翻訳ファイルのロード
36
+ *
37
+ * @param string $hook
38
+ */
39
+ public function admin_enqueue_scripts( $hook ) {
40
+ do_action( SCF_Config::PREFIX . 'before-editor-enqueue-scripts' );
41
+ wp_enqueue_style(
42
+ SCF_Config::PREFIX . 'editor',
43
+ plugins_url( SCF_Config::NAME ) . '/css/editor.css'
44
+ );
45
+ wp_enqueue_media();
46
+ wp_enqueue_script(
47
+ SCF_Config::PREFIX . 'editor',
48
+ plugins_url( SCF_Config::NAME ) . '/js/editor.js',
49
+ array( 'jquery' ),
50
+ null,
51
+ true
52
+ );
53
+ wp_localize_script( SCF_Config::PREFIX . 'editor', 'smart_cf_uploader', array(
54
+ 'image_uploader_title' => esc_html__( 'Image setting', 'smart-custom-fields' ),
55
+ 'file_uploader_title' => esc_html__( 'File setting', 'smart-custom-fields' ),
56
+ ) );
57
+ do_action( SCF_Config::PREFIX . 'after-editor-enqueue-scripts' );
58
+ }
59
+
60
+ /**
61
+ * 投稿画面にカスタムフィールドを表示
62
+ *
63
+ * @param string $post_type
64
+ * @param WP_Post $post
65
+ */
66
+ public function add_meta_boxes( $post_type, $post ) {
67
+ $_post = $post;
68
+ $settings = SCF::get_settings( $post_type );
69
+ foreach ( $settings as $Setting ) {
70
+ add_meta_box(
71
+ SCF_Config::PREFIX . 'custom-field-' . $Setting->get_id(),
72
+ $Setting->get_title(),
73
+ array( $this, 'display_meta_box' ),
74
+ $post_type,
75
+ 'normal',
76
+ 'default',
77
+ $Setting->get_groups()
78
+ );
79
+ }
80
+ }
81
+
82
+ /**
83
+ * 投稿画面にカスタムフィールドを表示
84
+ *
85
+ * @param object $post
86
+ * @param array $callback_args カスタムフィールドの設定情報
87
+ */
88
+ public function display_meta_box( $post, $callback_args ) {
89
+ $groups = $callback_args['args'];
90
+ $tables = $this->get_tables( $post->ID, $groups );
91
+
92
+ printf( '<div class="%s">', esc_attr( SCF_Config::PREFIX . 'meta-box' ) );
93
+ $index = 0;
94
+ foreach ( $tables as $group_key => $Group ) {
95
+ $is_repeatable = $Group->is_repeatable();
96
+ if ( $is_repeatable && $index === 0 ) {
97
+ printf(
98
+ '<div class="%s">',
99
+ esc_attr( SCF_Config::PREFIX . 'meta-box-repeat-tables' )
100
+ );
101
+ $this->display_tr( $post->ID, $is_repeatable, $Group->get_fields() );
102
+ }
103
+ $this->display_tr( $post->ID, $is_repeatable, $Group->get_fields(), $index );
104
+
105
+ // ループの場合は添字をカウントアップ
106
+ // ループを抜けたらカウントをもとに戻す
107
+ if ( $is_repeatable &&
108
+ isset( $tables[$group_key + 1 ] ) &&
109
+ $tables[$group_key + 1 ]->get_name() === $Group->get_name() ) {
110
+ $index ++;
111
+ } else {
112
+ $index = 0;
113
+ }
114
+ if ( $is_repeatable && $index === 0 ) {
115
+ printf( '</div>' );
116
+ }
117
+ }
118
+ printf( '</div>' );
119
+ wp_nonce_field( SCF_Config::NAME . '-fields', SCF_Config::PREFIX . 'fields-nonce' );
120
+ }
121
+
122
+ /**
123
+ * 投稿画面のカスタムフィールドからのメタデータを保存
124
+ *
125
+ * @param int $post_id
126
+ */
127
+ public function save_post( $post_id ) {
128
+ if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
129
+ return;
130
+ }
131
+ if ( wp_is_post_autosave( $post_id ) || wp_is_post_revision( $post_id ) ){
132
+ return;
133
+ }
134
+ if ( !isset( $_POST[SCF_Config::NAME] ) ) {
135
+ return;
136
+ }
137
+
138
+ check_admin_referer(
139
+ SCF_Config::NAME . '-fields',
140
+ SCF_Config::PREFIX . 'fields-nonce'
141
+ );
142
+
143
+ // 繰り返しフィールドのチェックボックスは、普通のチェックボックスと混ざって
144
+ // 判別できなくなるのでわかるように保存しておく
145
+ $repeat_multiple_data = array();
146
+
147
+ // チェックボックスが未入力のときは "" がくるので、それは保存しないように判別
148
+ $multiple_data_fields = array();
149
+
150
+ $post_type = get_post_type();
151
+ $settings = SCF::get_settings( $post_type );
152
+ foreach ( $settings as $Setting ) {
153
+ $groups = $Setting->get_groups();
154
+ foreach ( $groups as $Group ) {
155
+ $fields = $Group->get_fields();
156
+ foreach ( $fields as $Field ) {
157
+ $field_name = $Field->get( 'name' );
158
+ delete_post_meta( $post_id, $field_name );
159
+ if ( $Field->get_attribute( 'allow-multiple-data' ) ) {
160
+ $multiple_data_fields[] = $field_name;
161
+ }
162
+
163
+ if ( $Group->is_repeatable() && $Field->get_attribute( 'allow-multiple-data' ) ) {
164
+ $repeat_multiple_data_fields = $_POST[SCF_Config::NAME][$field_name];
165
+ foreach ( $repeat_multiple_data_fields as $values ) {
166
+ if ( is_array( $values ) ) {
167
+ $repeat_multiple_data[$field_name][] = count( $values );
168
+ } else {
169
+ $repeat_multiple_data[$field_name][] = 0;
170
+ }
171
+ }
172
+ }
173
+ }
174
+ }
175
+ }
176
+
177
+ delete_post_meta( $post_id, SCF_Config::PREFIX . 'repeat-multiple-data' );
178
+ if ( $repeat_multiple_data ) {
179
+ update_post_meta( $post_id, SCF_Config::PREFIX . 'repeat-multiple-data', $repeat_multiple_data );
180
+ }
181
+
182
+ foreach ( $_POST[SCF_Config::NAME] as $name => $values ) {
183
+ foreach ( $values as $value ) {
184
+ if ( in_array( $name, $multiple_data_fields ) && $value === '' ) {
185
+ continue;
186
+ }
187
+ if ( !is_array( $value ) ) {
188
+ $this->add_post_meta( $post_id, $name, $value );
189
+ } else {
190
+ foreach ( $value as $val ) {
191
+ $this->add_post_meta( $post_id, $name, $val );
192
+ }
193
+ }
194
+ }
195
+ }
196
+ }
197
+
198
+ /**
199
+ * メタデータを保存
200
+ *
201
+ * @param int $post_id
202
+ * @param string $name
203
+ * @param mixed $value
204
+ */
205
+ protected function add_post_meta( $post_id, $name, $value ) {
206
+ do_action( SCF_Config::PREFIX . '-before-save-post', $post_id, $name, $value );
207
+ $is_valid = apply_filters( SCF_Config::PREFIX . '-validate-save-post', true, $post_id, $name, $value );
208
+ if ( $is_valid ) {
209
+ add_post_meta( $post_id, $name, $value );
210
+ }
211
+ do_action( SCF_Config::PREFIX . '-after-save-post', $post_id, $name, $value );
212
+ }
213
+
214
+ /**
215
+ * メタデータの取得
216
+ *
217
+ * @param int $post_id
218
+ * @return array
219
+ */
220
+ protected function get_post_custom( $post_id ) {
221
+ $post_custom = $this->post_custom;
222
+ if ( empty( $post_custom ) ) {
223
+ $post_custom = get_post_custom( $post_id );
224
+ if ( empty( $post_custom ) ) {
225
+ return array();
226
+ }
227
+ $this->post_custom = $post_custom;
228
+ }
229
+ return $this->post_custom;
230
+ }
231
+
232
+ /**
233
+ * カスタムフィールドを出力するための配列を生成
234
+ *
235
+ * @param array $groups カスタムフィールド設定ページで保存した設定
236
+ * @return array $tables カスタムフィールド表示用のテーブルを出力するための配列
237
+ */
238
+ protected function get_tables( $post_id, $groups ) {
239
+ $post_custom = $this->get_post_custom( $post_id );
240
+ $repeat_multiple_data = SCF::get_repeat_multiple_data( $post_id );
241
+ $tables = array();
242
+ foreach ( $groups as $Group ) {
243
+ // ループのときは、ループの分だけグループを追加する
244
+ // ループだけどループがないとき(新規登録時とか)は1つだけ入れる
245
+ if ( $Group->is_repeatable() === true ) {
246
+ $loop_count = 1;
247
+ $fields = $Group->get_fields();
248
+ foreach ( $fields as $Field ) {
249
+ $field_name = $Field->get( 'name' );
250
+ if ( isset( $post_custom[$field_name] ) && is_array( $post_custom[$field_name] ) ) {
251
+ $post_meta = $post_custom[$field_name];
252
+ $post_meta_count = count( $post_meta );
253
+ // 同名のカスタムフィールドが複数のとき(チェックボックス or ループ)
254
+ if ( $post_meta_count > 1 ) {
255
+ // チェックボックスの場合
256
+ if ( is_array( $repeat_multiple_data ) && array_key_exists( $field_name, $repeat_multiple_data ) ) {
257
+ $repeat_multiple_data_count = count( $repeat_multiple_data[$field_name] );
258
+ if ( $loop_count < $repeat_multiple_data_count )
259
+ $loop_count = $repeat_multiple_data_count;
260
+ }
261
+ // チェックボックス以外
262
+ else {
263
+ if ( $loop_count < $post_meta_count )
264
+ $loop_count = $post_meta_count;
265
+ }
266
+ }
267
+ }
268
+ }
269
+ if ( $loop_count >= 1 ) {
270
+ for ( $i = $loop_count; $i > 0; $i -- ) {
271
+ $tables[] = $Group;
272
+ }
273
+ continue;
274
+ }
275
+ }
276
+ $tables[] = $Group;
277
+ }
278
+ return $tables;
279
+ }
280
+
281
+ /**
282
+ * 複数許可フィールドのメタデータを取得
283
+ *
284
+ * @param int $post_id
285
+ * @param string $field_name
286
+ * @param int $index
287
+ * @return array or null
288
+ */
289
+ protected function get_multiple_data_field_value( $post_id, $field_name, $index ) {
290
+ $post_custom = $this->get_post_custom( $post_id );
291
+ $repeat_multiple_data = SCF::get_repeat_multiple_data( $post_id );
292
+ $value = null;
293
+ if ( isset( $post_custom[$field_name] ) && is_array( $post_custom[$field_name] ) ) {
294
+ $value = $post_custom[$field_name];
295
+ // ループのとき
296
+ if ( is_array( $repeat_multiple_data ) && array_key_exists( $field_name, $repeat_multiple_data ) ) {
297
+ $now_num = 0;
298
+ if ( isset( $repeat_multiple_data[$field_name][$index] ) ) {
299
+ $now_num = $repeat_multiple_data[$field_name][$index];
300
+ }
301
+
302
+ // 自分($index)より前の個数の合計が指す index が start
303
+ $_temp = array_slice( $repeat_multiple_data[$field_name], 0, $index );
304
+ $sum = array_sum( $_temp );
305
+ $start = $sum;
306
+
307
+ $value = null;
308
+ if ( $now_num ) {
309
+ $value = array_slice( $post_custom[$field_name], $start, $now_num );
310
+ }
311
+ }
312
+ }
313
+ return $value;
314
+ }
315
+
316
+ /**
317
+ * 非複数許可フィールドのメタデータを取得
318
+ *
319
+ * @param int $post_id
320
+ * @param string $field_name
321
+ * @param int $index
322
+ * @return string or null
323
+ */
324
+ protected function get_single_data_field_value( $post_id, $field_name, $index ) {
325
+ $post_custom = $this->get_post_custom( $post_id );
326
+ $value = null;
327
+ if ( isset( $post_custom[$field_name][$index] ) ) {
328
+ $value = $post_custom[$field_name][$index];
329
+ }
330
+ return $value;
331
+ }
332
+
333
+ /**
334
+ * カスタムフィールド表示 table で使用する各 tr を出力
335
+ *
336
+ * @param int $post_id
337
+ * @param bool $is_repeat
338
+ * @param array $fields
339
+ * @param int, null $index
340
+ */
341
+ protected function display_tr( $post_id, $is_repeat, $fields, $index = null ) {
342
+ $btn_repeat = '';
343
+ if ( $is_repeat ) {
344
+ $btn_repeat = sprintf(
345
+ '<span class="%s"></span>',
346
+ esc_attr( SCF_Config::PREFIX . 'icon-handle dashicons dashicons-menu' )
347
+ );
348
+ $btn_repeat .= '<span class="btn-add-repeat-group dashicons dashicons-plus-alt '.SCF_Config::PREFIX.'repeat-btn"></span>';
349
+ $btn_repeat .= ' <span class="btn-remove-repeat-group dashicons dashicons-dismiss '.SCF_Config::PREFIX.'repeat-btn"></span>';
350
+ }
351
+
352
+ $style = '';
353
+ if ( is_null( $index ) ) {
354
+ $style = 'style="display: none;"';
355
+ }
356
+
357
+ printf(
358
+ '<div class="%s" %s>%s<table>',
359
+ esc_attr( SCF_Config::PREFIX . 'meta-box-table' ),
360
+ $style,
361
+ $btn_repeat
362
+ );
363
+
364
+ foreach ( $fields as $Field ) {
365
+ $type = $Field->get_attribute( 'type' );
366
+ $display_name = $Field->get_attribute( 'display-name' );
367
+ $default = $Field->get( 'default' );
368
+ $field_name = $Field->get( 'name' );
369
+ $field_label = $Field->get( 'label' );
370
+ if ( !$field_label ) {
371
+ $field_label = $field_name;
372
+ }
373
+
374
+ // 複数値許可フィールドのとき
375
+ $post_status = get_post_status( $post_id );
376
+ if ( $Field->get_attribute( 'allow-multiple-data' ) ) {
377
+ $value = array();
378
+ if ( !SCF::is_empty( $default ) && ( $post_status === 'auto-draft' || is_null( $index ) ) ) {
379
+ $value = SCF::choices_eol_to_array( $default );
380
+ }
381
+ $_value = $this->get_multiple_data_field_value( $post_id, $field_name, $index );
382
+ }
383
+ // 複数不値許可フィールドのとき
384
+ else {
385
+ $value = '';
386
+ if ( $post_status === 'auto-draft' || is_null( $index ) ) {
387
+ if ( !SCF::is_empty( $default ) ) {
388
+ $value = $default;
389
+ }
390
+ }
391
+ $_value = $this->get_single_data_field_value( $post_id, $field_name, $index );
392
+ }
393
+ if ( !is_null( $_value ) ) {
394
+ $value = $_value;
395
+ }
396
+
397
+ $notes = $Field->get( 'notes' );
398
+ if ( !empty( $notes ) ) {
399
+ $notes = sprintf(
400
+ '<p class="description">%s</p>',
401
+ esc_html( $notes )
402
+ );
403
+ }
404
+
405
+ $form_field = $Field->get_field( $index, $value );
406
+ printf(
407
+ '<tr><th>%s</th><td>%s%s</td></tr>',
408
+ esc_html( $field_label ),
409
+ $form_field,
410
+ $notes
411
+ );
412
+ }
413
+ echo '</table></div>';
414
+ }
415
+ }
classes/{class.settings.php → controller/class.settings.php} RENAMED
@@ -1,14 +1,20 @@
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
  */
11
- class Smart_Custom_Fields_Settings {
 
 
 
 
 
 
12
 
13
  /**
14
  * __construct
@@ -16,54 +22,52 @@ class Smart_Custom_Fields_Settings {
16
  public function __construct() {
17
  add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
18
  add_action( 'save_post', array( $this, 'save_post' ) );
19
- add_action( 'init', array( $this, 'register_post_type' ) );
20
  add_action( 'add_meta_boxes', array( $this, 'add_meta_boxes' ) );
21
- }
22
 
23
- /**
24
- * admin_enqueue_scripts
25
- */
26
- public function admin_enqueue_scripts() {
27
- if ( get_post_type() === SCF_Config::NAME ) {
28
- wp_enqueue_style(
29
- SCF_Config::PREFIX . 'settings',
30
- plugin_dir_url( __FILE__ ) . '../css/settings.css'
31
- );
32
- wp_enqueue_script(
33
- SCF_Config::PREFIX . 'settings',
34
- plugin_dir_url( __FILE__ ) . '../js/settings.js',
35
- array( 'jquery' ),
36
- null,
37
- true
38
- );
39
- wp_localize_script( SCF_Config::PREFIX . 'settings', 'smart_cf_settings', array(
40
- 'duplicate_alert' => esc_html__( 'Same name exists!', 'smart-custom-fields' ),
41
- ) );
42
- wp_enqueue_script( 'jquery-ui-sortable' );
43
- }
44
  }
45
 
46
  /**
47
- * register_post_type
48
  */
49
- public function register_post_type() {
50
- register_post_type(
51
- SCF_Config::NAME,
52
- array(
53
- 'label' => 'Smart Custom Fields',
54
- 'labels' => array(
55
- ),
56
- 'public' => false,
57
- 'show_ui' => true,
58
- 'capability_type' => 'page',
59
- 'supports' => array( 'title' ),
60
- 'menu_position' => 80,
61
- )
62
  );
 
 
 
 
 
63
  }
64
 
65
  /**
66
- * add_meta_boxes
67
  * 投稿画面にカスタムフィールドを表示
68
  */
69
  public function add_meta_boxes() {
@@ -83,20 +87,9 @@ class Smart_Custom_Fields_Settings {
83
  }
84
 
85
  /**
86
- * get
87
- * @param string $key 取得したいデータのキー
88
- * @param array $data データ配列
89
- * @return mixed
90
- */
91
- private function get( $key, array $data ) {
92
- if ( isset( $data[$key] ) ) {
93
- return $data[$key];
94
- }
95
- }
96
-
97
- /**
98
- * add_hide_class
99
- * @param string $key 値があれば hide を表示
100
  */
101
  private function add_hide_class( $key ) {
102
  if ( !$key ) {
@@ -105,113 +98,48 @@ class Smart_Custom_Fields_Settings {
105
  }
106
 
107
  /**
108
- * display_meta_box
109
  */
110
  public function display_meta_box() {
111
- $default = array(
112
- array(
113
- 'group-name' => '',
114
- 'fields' => array(),
115
- ),
116
- );
117
- $settings = get_post_meta( get_the_ID(), SCF_Config::PREFIX . 'setting', true );
118
- $settings = wp_parse_args( $settings, $default );
119
  ?>
120
  <div class="<?php echo esc_attr( SCF_Config::PREFIX . 'fields-wrapper' ); ?>">
121
  <div class="<?php echo esc_attr( SCF_Config::PREFIX . 'groups' ); ?>">
122
- <?php foreach ( $settings as $group_key => $group ) : ?>
123
  <?php
124
- $group_name = '';
125
- if ( !is_numeric( $group['group-name'] ) ) {
126
- $group_name = $group['group-name'];
127
- }
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]' ); ?>"
136
- value="true"
137
- <?php checked( $this->get( 'repeat', $group ), true ); ?>
138
- />
139
- <?php esc_html_e( 'Repeat', 'smart-custom-fields' ); ?>
140
- </label>
141
- </div>
142
- <table class="<?php echo esc_attr( SCF_Config::PREFIX . 'group-names' ); ?> <?php $this->add_hide_class( $this->get( 'repeat', $group ) ); ?>">
143
- <tr>
144
- <th><?php esc_html_e( 'Group name', 'smart-custom-fields' ); ?><span class="<?php echo esc_attr( SCF_Config::PREFIX . 'require' ); ?>">*</span></th>
145
- <td>
146
- <input type="text"
147
- name="<?php echo esc_attr( SCF_Config::NAME . '[' . $group_key . '][group-name]' ); ?>"
148
- size="30"
149
- class="<?php echo esc_attr( SCF_Config::PREFIX . 'group-name' ); ?>"
150
- value="<?php echo esc_attr( $group_name ); ?>"
151
- />
152
- </td>
153
- </tr>
154
- </table>
155
 
156
  <div class="<?php echo esc_attr( SCF_Config::PREFIX . 'fields' ); ?>">
157
- <?php foreach ( $group['fields'] as $field_key => $field ) : ?>
158
  <div class="<?php echo esc_attr( SCF_Config::PREFIX . 'field' ); ?> <?php $this->add_hide_class( $field_key ); ?>">
159
  <?php
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>
169
- <td>
170
- <input type="text"
171
- name="<?php echo esc_attr( SCF_Config::NAME . '[' . $group_key . '][fields][' . $field_key . '][name]' ); ?>"
172
- size="30"
173
- class="<?php echo esc_attr( SCF_Config::PREFIX . 'field-name' ); ?>"
174
- value="<?php echo esc_attr( $this->get( 'name', $field ) ); ?>"
175
- />
176
- </td>
177
- </tr>
178
- <tr>
179
- <th><?php esc_html_e( 'Label', 'smart-custom-fields' ); ?></th>
180
- <td>
181
- <input type="text"
182
- name="<?php echo esc_attr( SCF_Config::NAME . '[' . $group_key . '][fields][' . $field_key . '][label]' ); ?>"
183
- size="30"
184
- class="<?php echo esc_attr( SCF_Config::PREFIX . 'field-label' ); ?>"
185
- value="<?php echo esc_attr( $this->get( 'label', $field ) ); ?>"
186
- />
187
- </td>
188
- </tr>
189
  <tr>
190
  <th><?php esc_html_e( 'Type', 'smart-custom-fields' ); ?><span class="<?php echo esc_attr( SCF_Config::PREFIX . 'require' ); ?>">*</span></th>
191
  <td>
192
  <select
193
- name="<?php echo esc_attr( SCF_Config::NAME . '[' . $group_key . '][fields][' . $field_key . '][type]' ); ?>"
194
  class="<?php echo esc_attr( SCF_Config::PREFIX . 'field-select' ); ?>" />
195
  <?php
196
- $optgroups = array(
197
- 'basic-fields' => array(
198
- 'label' => esc_attr__( 'Basic fields', 'smart-custom-fields' ),
199
- 'options' => array(),
200
- ),
201
- 'select-fields' => array(
202
- 'label' => esc_attr__( 'Select fields', 'smart-custom-fields' ),
203
- 'options' => array(),
204
- ),
205
- 'content-fields' => array(
206
- 'label' => esc_attr__( 'Content fields', 'smart-custom-fields' ),
207
- 'options' => array(),
208
- ),
209
- 'other-fields' => array(
210
- 'label' => esc_attr__( 'Other fields', 'smart-custom-fields' ),
211
- 'options' => array(),
212
- ),
213
- );
214
- foreach ( $optgroups as $optgroup_name => $optgroup_values ) {
215
  $optgroup_fields = array();
216
  $optgroup_values['options'] = apply_filters(
217
  SCF_Config::PREFIX . 'field-select-' . $optgroup_name,
@@ -221,7 +149,7 @@ class Smart_Custom_Fields_Settings {
221
  $optgroup_fields[] = sprintf(
222
  '<option value="%s" %s>%s</option>',
223
  esc_attr( $option_key ),
224
- selected( $this->get( 'type', $field ), $option_key, false ),
225
  esc_html( $option )
226
  );
227
  }
@@ -235,12 +163,12 @@ class Smart_Custom_Fields_Settings {
235
  </select>
236
  </td>
237
  </tr>
238
- <?php do_action( SCF_Config::PREFIX . 'field-options', $group_key, $field_key, $field ); ?>
239
  </table>
240
  </div>
241
  <?php endforeach; ?>
242
  </div>
243
- <div class="button btn-add-field <?php $this->add_hide_class( $this->get( 'repeat', $group ) ); ?>"><?php esc_html_e( 'Add Sub field', 'smart-custom-fields' ); ?></div>
244
  </div>
245
  <?php endforeach; ?>
246
  </div>
@@ -251,7 +179,6 @@ class Smart_Custom_Fields_Settings {
251
  }
252
 
253
  /**
254
- * display_meta_box_condition
255
  * メタボックスの表示条件を設定するメタボックスを表示
256
  */
257
  public function display_meta_box_condition() {
@@ -289,39 +216,47 @@ class Smart_Custom_Fields_Settings {
289
  }
290
 
291
  /**
292
- * save_post
 
 
293
  */
294
  public function save_post( $post_id ) {
295
- if ( !isset( $_POST[SCF_Config::PREFIX . 'settings-nonce'] ) ) {
296
- return;
297
- }
298
- if ( !wp_verify_nonce( $_POST[SCF_Config::PREFIX . 'settings-nonce'], SCF_Config::NAME . '-settings' ) ) {
299
- return;
300
- }
301
  if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
302
  return;
303
  }
304
- if ( get_post_type() !== SCF_Config::NAME ) {
305
- return;
306
- }
307
  if ( !isset( $_POST[SCF_Config::NAME] ) ) {
308
  return;
309
  }
 
 
 
 
310
 
311
  $data = array();
312
  foreach ( $_POST[SCF_Config::NAME] as $group_key => $group_value ) {
 
 
 
 
313
  if ( !empty( $group_value['fields'] ) && count( $group_value['fields'] ) > 1 ) {
314
  $fields = array();
315
- foreach ( $group_value['fields'] as $field_value ) {
 
 
 
 
316
  if ( !empty( $field_value['name'] ) ) {
317
  $fields[] = $field_value;
318
  }
319
  }
320
- if ( !$fields )
321
  continue;
 
322
 
323
  if ( !empty( $group_value['repeat'] ) && $group_value['repeat'] === 'true' ) {
324
  $group_value['repeat'] = true;
 
 
325
  }
326
 
327
  // repeat が true でないときは name を空に
@@ -348,4 +283,4 @@ class Smart_Custom_Fields_Settings {
348
  update_post_meta( $post_id, SCF_Config::PREFIX . 'condition-post-ids', $_POST[SCF_Config::PREFIX . 'condition-post-ids'] );
349
  }
350
  }
351
- }
1
  <?php
2
  /**
3
+ * Smart_Custom_Fields_Controller_Settings
4
+ * Version : 1.1.0
5
  * Author : Takashi Kitajima
6
  * Created : September 23, 2014
7
+ * Modified : February 27, 2015
8
  * License : GPLv2
9
  * License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
  */
11
+ class Smart_Custom_Fields_Controller_Settings {
12
+
13
+ /**
14
+ * フィールド選択のセレクトボックスの選択肢用
15
+ * @var array
16
+ */
17
+ private $optgroups = array();
18
 
19
  /**
20
  * __construct
22
  public function __construct() {
23
  add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
24
  add_action( 'save_post', array( $this, 'save_post' ) );
 
25
  add_action( 'add_meta_boxes', array( $this, 'add_meta_boxes' ) );
 
26
 
27
+ $this->optgroups = array(
28
+ 'basic-fields' => array(
29
+ 'label' => esc_attr__( 'Basic fields', 'smart-custom-fields' ),
30
+ 'options' => array(),
31
+ ),
32
+ 'select-fields' => array(
33
+ 'label' => esc_attr__( 'Select fields', 'smart-custom-fields' ),
34
+ 'options' => array(),
35
+ ),
36
+ 'content-fields' => array(
37
+ 'label' => esc_attr__( 'Content fields', 'smart-custom-fields' ),
38
+ 'options' => array(),
39
+ ),
40
+ 'other-fields' => array(
41
+ 'label' => esc_attr__( 'Other fields', 'smart-custom-fields' ),
42
+ 'options' => array(),
43
+ ),
44
+ );
 
 
 
45
  }
46
 
47
  /**
48
+ * CSS、JSの読み込み
49
  */
50
+ public function admin_enqueue_scripts() {
51
+ do_action( SCF_Config::PREFIX . 'before-settings-enqueue-scripts' );
52
+ wp_enqueue_style(
53
+ SCF_Config::PREFIX . 'settings',
54
+ plugins_url( SCF_Config::NAME ) . '/css/settings.css'
55
+ );
56
+ wp_enqueue_script(
57
+ SCF_Config::PREFIX . 'settings',
58
+ plugins_url( SCF_Config::NAME ) . '/js/settings.js',
59
+ array( 'jquery' ),
60
+ null,
61
+ true
 
62
  );
63
+ wp_localize_script( SCF_Config::PREFIX . 'settings', 'smart_cf_settings', array(
64
+ 'duplicate_alert' => esc_html__( 'Same name exists!', 'smart-custom-fields' ),
65
+ ) );
66
+ wp_enqueue_script( 'jquery-ui-sortable' );
67
+ do_action( SCF_Config::PREFIX . 'after-settings-enqueue-scripts' );
68
  }
69
 
70
  /**
 
71
  * 投稿画面にカスタムフィールドを表示
72
  */
73
  public function add_meta_boxes() {
87
  }
88
 
89
  /**
90
+ * $key が空でなければ hide を表示
91
+ *
92
+ * @param string $key
 
 
 
 
 
 
 
 
 
 
 
93
  */
94
  private function add_hide_class( $key ) {
95
  if ( !$key ) {
98
  }
99
 
100
  /**
101
+ * 投稿画面にカスタムフィールドを表示
102
  */
103
  public function display_meta_box() {
104
+ $Setting = SCF::add_setting( get_the_ID(), get_the_title() );
105
+ $Setting->add_group_unshift();
106
+ $groups = $Setting->get_groups();
 
 
 
 
 
107
  ?>
108
  <div class="<?php echo esc_attr( SCF_Config::PREFIX . 'fields-wrapper' ); ?>">
109
  <div class="<?php echo esc_attr( SCF_Config::PREFIX . 'groups' ); ?>">
110
+ <?php foreach ( $groups as $group_key => $Group ) : ?>
111
  <?php
112
+ $fields = $Group->get_fields();
113
+ array_unshift( $fields, SCF::get_form_field_instance( 'text' ) );
 
 
 
114
  ?>
115
  <div class="<?php echo esc_attr( SCF_Config::PREFIX . 'group' ); ?> <?php $this->add_hide_class( $group_key ); ?>">
116
+ <div class="btn-remove-group"><span class="dashicons dashicons-no-alt"></span></div>
117
+ <?php $Group->display_options( $group_key ); ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
118
 
119
  <div class="<?php echo esc_attr( SCF_Config::PREFIX . 'fields' ); ?>">
120
+ <?php foreach ( $fields as $field_key => $Field ) : ?>
121
  <div class="<?php echo esc_attr( SCF_Config::PREFIX . 'field' ); ?> <?php $this->add_hide_class( $field_key ); ?>">
122
  <?php
123
+ $field_label = $Field->get( 'label' );
124
  if ( !$field_label ) {
125
+ $field_label = $Field->get( 'name' );
126
+ if ( !$field_label ) {
127
+ $field_label = "&nbsp;";
128
+ }
129
  }
130
  ?>
131
+ <div class="<?php echo esc_attr( SCF_Config::PREFIX . 'icon-handle' ); ?>"></div>
132
+ <b class="btn-remove-field"><span class="dashicons dashicons-no-alt"></span></b>
133
+ <div class="field-label"><?php echo esc_html( $field_label ); ?></div>
134
+ <table class="<?php $this->add_hide_class( !$Field->get( 'name' ) ); ?>">
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
135
  <tr>
136
  <th><?php esc_html_e( 'Type', 'smart-custom-fields' ); ?><span class="<?php echo esc_attr( SCF_Config::PREFIX . 'require' ); ?>">*</span></th>
137
  <td>
138
  <select
139
+ name="<?php echo esc_attr( $Field->get_field_name_in_setting( $group_key, $field_key, 'type' ) ); ?>"
140
  class="<?php echo esc_attr( SCF_Config::PREFIX . 'field-select' ); ?>" />
141
  <?php
142
+ foreach ( $this->optgroups as $optgroup_name => $optgroup_values ) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
143
  $optgroup_fields = array();
144
  $optgroup_values['options'] = apply_filters(
145
  SCF_Config::PREFIX . 'field-select-' . $optgroup_name,
149
  $optgroup_fields[] = sprintf(
150
  '<option value="%s" %s>%s</option>',
151
  esc_attr( $option_key ),
152
+ selected( $Field->get_attribute( 'type' ), $option_key, false ),
153
  esc_html( $option )
154
  );
155
  }
163
  </select>
164
  </td>
165
  </tr>
166
+ <?php $Field->display_options( $group_key, $field_key ); ?>
167
  </table>
168
  </div>
169
  <?php endforeach; ?>
170
  </div>
171
+ <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>
172
  </div>
173
  <?php endforeach; ?>
174
  </div>
179
  }
180
 
181
  /**
 
182
  * メタボックスの表示条件を設定するメタボックスを表示
183
  */
184
  public function display_meta_box_condition() {
216
  }
217
 
218
  /**
219
+ * 設定を保存
220
+ *
221
+ * @param int $post_id
222
  */
223
  public function save_post( $post_id ) {
 
 
 
 
 
 
224
  if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
225
  return;
226
  }
 
 
 
227
  if ( !isset( $_POST[SCF_Config::NAME] ) ) {
228
  return;
229
  }
230
+ check_admin_referer(
231
+ SCF_Config::NAME . '-settings',
232
+ SCF_Config::PREFIX . 'settings-nonce'
233
+ );
234
 
235
  $data = array();
236
  foreach ( $_POST[SCF_Config::NAME] as $group_key => $group_value ) {
237
+ // $group_key = 0 は隠しフィールドなので保存不要
238
+ if ( $group_key === 0 ) {
239
+ continue;
240
+ }
241
  if ( !empty( $group_value['fields'] ) && count( $group_value['fields'] ) > 1 ) {
242
  $fields = array();
243
+ foreach ( $group_value['fields'] as $field_key => $field_value ) {
244
+ // $field_key = 0 は隠しフィールドなので保存不要
245
+ if ( $field_key === 0 ) {
246
+ continue;
247
+ }
248
  if ( !empty( $field_value['name'] ) ) {
249
  $fields[] = $field_value;
250
  }
251
  }
252
+ if ( !$fields ) {
253
  continue;
254
+ }
255
 
256
  if ( !empty( $group_value['repeat'] ) && $group_value['repeat'] === 'true' ) {
257
  $group_value['repeat'] = true;
258
+ } else {
259
+ $group_value['repeat'] = false;
260
  }
261
 
262
  // repeat が true でないときは name を空に
283
  update_post_meta( $post_id, SCF_Config::PREFIX . 'condition-post-ids', $_POST[SCF_Config::PREFIX . 'condition-post-ids'] );
284
  }
285
  }
286
+ }
classes/fields/class.field-check.php CHANGED
@@ -1,38 +1,53 @@
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
  */
11
  class Smart_Custom_Fields_Field_Check extends Smart_Custom_Fields_Field_Base {
12
 
13
  /**
14
- * init
15
- * @return array ( name, label, optgroup, allow-multiple-data )
 
16
  */
17
  protected function init() {
18
  return array(
19
- 'name' => 'check',
20
- 'label' => __( 'Check', 'smart-custom-fields' ),
21
- 'optgroup' => 'select-fields',
22
  'allow-multiple-data' => true,
23
  );
24
  }
25
 
26
  /**
27
- * get_field
28
- * @param array $field フィールドの情報
 
 
 
 
 
 
 
 
 
 
 
 
 
29
  * @param int $index インデックス番号
30
  * @param mixed $value 保存されている値(check のときだけ配列)
 
31
  */
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 />',
@@ -55,7 +70,8 @@ class Smart_Custom_Fields_Field_Check extends Smart_Custom_Fields_Field_Base {
55
  }
56
 
57
  /**
58
- * display_field_options
 
59
  * @param int $group_key
60
  * @param int $field_key
61
  */
@@ -65,30 +81,30 @@ class Smart_Custom_Fields_Field_Check extends Smart_Custom_Fields_Field_Base {
65
  <th><?php esc_html_e( 'Choices', 'smart-custom-fields' ); ?></th>
66
  <td>
67
  <textarea
68
- name="<?php echo esc_attr( $this->get_field_name( $group_key, $field_key, 'choices' ) ); ?>"
69
  class="widefat"
70
- rows="5" /><?php echo esc_textarea( "\n" . $this->get_field_value( 'choices' ) ); ?></textarea>
71
  </td>
72
  </tr>
73
  <tr>
74
  <th><?php esc_html_e( 'Default', 'smart-custom-fields' ); ?></th>
75
  <td>
76
  <textarea
77
- name="<?php echo esc_attr( $this->get_field_name( $group_key, $field_key, 'default' ) ); ?>"
78
  class="widefat"
79
- rows="5" /><?php echo esc_textarea( "\n" . $this->get_field_value( 'default' ) ); ?></textarea>
80
  </td>
81
  </tr>
82
  <tr>
83
  <th><?php esc_html_e( 'Notes', 'smart-custom-fields' ); ?></th>
84
  <td>
85
  <input type="text"
86
- name="<?php echo esc_attr( $this->get_field_name( $group_key, $field_key, 'notes' ) ); ?>"
87
  class="widefat"
88
- value="<?php echo esc_attr( $this->get_field_value( 'notes' ) ); ?>"
89
  />
90
  </td>
91
  </tr>
92
  <?php
93
  }
94
- }
1
  <?php
2
  /**
3
  * Smart_Custom_Fields_Field_Check
4
+ * Version : 1.1.0
5
  * Author : Takashi Kitajima
6
  * Created : October 7, 2014
7
+ * Modified : February 27, 2015
8
  * License : GPLv2
9
  * License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
  */
11
  class Smart_Custom_Fields_Field_Check extends Smart_Custom_Fields_Field_Base {
12
 
13
  /**
14
+ * 必須項目の設定
15
+ *
16
+ * @return array
17
  */
18
  protected function init() {
19
  return array(
20
+ 'type' => 'check',
21
+ 'display-name' => __( 'Check', 'smart-custom-fields' ),
22
+ 'optgroup' => 'select-fields',
23
  'allow-multiple-data' => true,
24
  );
25
  }
26
 
27
  /**
28
+ * 設定項目の設定
29
+ *
30
+ * @return array
31
+ */
32
+ protected function options() {
33
+ return array(
34
+ 'choices' => '',
35
+ 'default' => '',
36
+ 'notes' => '',
37
+ );
38
+ }
39
+
40
+ /**
41
+ * 投稿画面にフィールドを表示
42
+ *
43
  * @param int $index インデックス番号
44
  * @param mixed $value 保存されている値(check のときだけ配列)
45
+ * @return string html
46
  */
47
+ public function get_field( $index, $value ) {
48
+ $name = $this->get_field_name_in_editor( $index );
49
  $disabled = $this->get_disable_attribute( $index );
50
+ $choices = SCF::choices_eol_to_array( $this->get( 'choices' ) );
51
 
52
  $form_field = sprintf(
53
  '<input type="hidden" name="%s" value="" %s />',
70
  }
71
 
72
  /**
73
+ * 設定画面にフィールドを表示(オリジナル項目)
74
+ *
75
  * @param int $group_key
76
  * @param int $field_key
77
  */
81
  <th><?php esc_html_e( 'Choices', 'smart-custom-fields' ); ?></th>
82
  <td>
83
  <textarea
84
+ name="<?php echo esc_attr( $this->get_field_name_in_setting( $group_key, $field_key, 'choices' ) ); ?>"
85
  class="widefat"
86
+ rows="5" /><?php echo esc_textarea( "\n" . $this->get( 'choices' ) ); ?></textarea>
87
  </td>
88
  </tr>
89
  <tr>
90
  <th><?php esc_html_e( 'Default', 'smart-custom-fields' ); ?></th>
91
  <td>
92
  <textarea
93
+ name="<?php echo esc_attr( $this->get_field_name_in_setting( $group_key, $field_key, 'default' ) ); ?>"
94
  class="widefat"
95
+ rows="5" /><?php echo esc_textarea( "\n" . $this->get( 'default' ) ); ?></textarea>
96
  </td>
97
  </tr>
98
  <tr>
99
  <th><?php esc_html_e( 'Notes', 'smart-custom-fields' ); ?></th>
100
  <td>
101
  <input type="text"
102
+ name="<?php echo esc_attr( $this->get_field_name_in_setting( $group_key, $field_key, 'notes' ) ); ?>"
103
  class="widefat"
104
+ value="<?php echo esc_attr( $this->get( 'notes' ) ); ?>"
105
  />
106
  </td>
107
  </tr>
108
  <?php
109
  }
110
+ }
classes/fields/class.field-colorpicker.php CHANGED
@@ -1,53 +1,85 @@
1
  <?php
2
  /**
3
  * Smart_Custom_Fields_Field_Colorpicker
4
- * Version : 1.0.0
5
  * Author : Takashi Kitajima
6
  * Created : October 21, 2014
7
- * Modified :
8
  * License : GPLv2
9
  * License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
  */
11
  class Smart_Custom_Fields_Field_Colorpicker extends Smart_Custom_Fields_Field_Base {
12
 
13
  /**
14
- * init
15
- * @return array ( name, label, optgroup )
 
16
  */
17
  protected function init() {
18
- add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
 
 
 
 
 
 
 
19
  return array(
20
- 'name' => 'colorpicker',
21
- 'label' => __( 'Color picker', 'smart-custom-fields' ),
22
- 'optgroup' => 'other-fields',
23
  );
24
  }
25
 
26
  /**
27
- * admin_enqueue_scripts
28
- * @param string $hook
 
29
  */
30
- public function admin_enqueue_scripts( $hook ) {
31
- if ( in_array( $hook, array( 'post-new.php', 'post.php' ) ) ) {
32
- wp_enqueue_style( 'wp-color-picker' );
33
- wp_enqueue_script(
34
- SCF_Config::PREFIX . 'colorpicker',
35
- plugins_url( '../../js/editor-colorpicker.js', __FILE__ ),
36
- array( 'jquery', 'wp-color-picker' ),
37
- false,
38
- true
39
- );
40
- }
41
  }
42
 
43
  /**
44
- * get_field
45
- * @param array $field フィールドの情報
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
46
  * @param int $index インデックス番号
47
  * @param mixed $value 保存されている値(check のときだけ配列)
 
48
  */
49
- public function get_field( $field, $index, $value ) {
50
- $name = $this->get_name_attribute( $field['name'], $index );
51
  $disabled = $this->get_disable_attribute( $index );
52
  return sprintf(
53
  '<input type="text" name="%s" value="%s" class="%s" %s />',
@@ -59,7 +91,8 @@ class Smart_Custom_Fields_Field_Colorpicker extends Smart_Custom_Fields_Field_Ba
59
  }
60
 
61
  /**
62
- * display_field_options
 
63
  * @param int $group_key
64
  * @param int $field_key
65
  */
@@ -69,18 +102,18 @@ class Smart_Custom_Fields_Field_Colorpicker extends Smart_Custom_Fields_Field_Ba
69
  <th><?php esc_html_e( 'Default', 'smart-custom-fields' ); ?></th>
70
  <td>
71
  <input type="text"
72
- name="<?php echo esc_attr( $this->get_field_name( $group_key, $field_key, 'default' ) ); ?>"
73
- class="widefat"
74
- value="<?php echo esc_attr( $this->get_field_value( 'default' ) ); ?>" />
75
  </td>
76
  </tr>
77
  <tr>
78
  <th><?php esc_html_e( 'Notes', 'smart-custom-fields' ); ?></th>
79
  <td>
80
  <input type="text"
81
- name="<?php echo esc_attr( $this->get_field_name( $group_key, $field_key, 'notes' ) ); ?>"
82
  class="widefat"
83
- value="<?php echo esc_attr( $this->get_field_value( 'notes' ) ); ?>"
84
  />
85
  </td>
86
  </tr>
1
  <?php
2
  /**
3
  * Smart_Custom_Fields_Field_Colorpicker
4
+ * Version : 1.1.0
5
  * Author : Takashi Kitajima
6
  * Created : October 21, 2014
7
+ * Modified : February 27, 2015
8
  * License : GPLv2
9
  * License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
  */
11
  class Smart_Custom_Fields_Field_Colorpicker extends Smart_Custom_Fields_Field_Base {
12
 
13
  /**
14
+ * 必須項目の設定
15
+ *
16
+ * @return array
17
  */
18
  protected function init() {
19
+ add_action(
20
+ SCF_Config::PREFIX . 'before-editor-enqueue-scripts',
21
+ array( $this, 'editor_enqueue_scripts' )
22
+ );
23
+ add_action(
24
+ SCF_Config::PREFIX . 'before-settings-enqueue-scripts',
25
+ array( $this, 'settings_enqueue_scripts' )
26
+ );
27
  return array(
28
+ 'type' => 'colorpicker',
29
+ 'display-name' => __( 'Color picker', 'smart-custom-fields' ),
30
+ 'optgroup' => 'other-fields',
31
  );
32
  }
33
 
34
  /**
35
+ * 設定項目の設定
36
+ *
37
+ * @return array
38
  */
39
+ protected function options() {
40
+ return array(
41
+ 'default' => '',
42
+ 'notes' => '',
43
+ );
 
 
 
 
 
 
44
  }
45
 
46
  /**
47
+ * CSS、JSの読み込み
48
+ */
49
+ public function editor_enqueue_scripts() {
50
+ wp_enqueue_style( 'wp-color-picker' );
51
+ wp_enqueue_script(
52
+ SCF_Config::PREFIX . 'editor-colorpicker',
53
+ plugins_url( '../../js/editor-colorpicker.js', __FILE__ ),
54
+ array( 'jquery', 'wp-color-picker' ),
55
+ false,
56
+ true
57
+ );
58
+ }
59
+
60
+ /**
61
+ * CSS、JSの読み込み
62
+ */
63
+ public function settings_enqueue_scripts() {
64
+ wp_enqueue_style( 'wp-color-picker' );
65
+ wp_enqueue_script(
66
+ SCF_Config::PREFIX . 'settings-colorpicker',
67
+ plugins_url( '../../js/settings-colorpicker.js', __FILE__ ),
68
+ array( 'jquery', 'wp-color-picker' ),
69
+ false,
70
+ true
71
+ );
72
+ }
73
+
74
+ /**
75
+ * 投稿画面にフィールドを表示
76
+ *
77
  * @param int $index インデックス番号
78
  * @param mixed $value 保存されている値(check のときだけ配列)
79
+ * @return string html
80
  */
81
+ public function get_field( $index, $value ) {
82
+ $name = $this->get_field_name_in_editor( $index );
83
  $disabled = $this->get_disable_attribute( $index );
84
  return sprintf(
85
  '<input type="text" name="%s" value="%s" class="%s" %s />',
91
  }
92
 
93
  /**
94
+ * 設定画面にフィールドを表示(オリジナル項目)
95
+ *
96
  * @param int $group_key
97
  * @param int $field_key
98
  */
102
  <th><?php esc_html_e( 'Default', 'smart-custom-fields' ); ?></th>
103
  <td>
104
  <input type="text"
105
+ name="<?php echo esc_attr( $this->get_field_name_in_setting( $group_key, $field_key, 'default' ) ); ?>"
106
+ class="widefat default-option"
107
+ value="<?php echo esc_attr( $this->get( 'default' ) ); ?>" />
108
  </td>
109
  </tr>
110
  <tr>
111
  <th><?php esc_html_e( 'Notes', 'smart-custom-fields' ); ?></th>
112
  <td>
113
  <input type="text"
114
+ name="<?php echo esc_attr( $this->get_field_name_in_setting( $group_key, $field_key, 'notes' ) ); ?>"
115
  class="widefat"
116
+ value="<?php echo esc_attr( $this->get( 'notes' ) ); ?>"
117
  />
118
  </td>
119
  </tr>
classes/fields/class.field-datepicker.php CHANGED
@@ -1,100 +1,106 @@
1
  <?php
2
  /**
3
  * Smart_Custom_Fields_Field_Datepicker
4
- * Version : 1.0.0
5
  * Author : Takashi Kitajima
6
  * Created : January 17, 2015
7
- * Modified :
8
  * License : GPLv2
9
  * License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
  */
11
  class Smart_Custom_Fields_Field_Datepicker extends Smart_Custom_Fields_Field_Base {
12
 
13
  /**
14
- * init
15
- * @return array ( name, label, optgroup )
 
16
  */
17
  protected function init() {
18
- add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
 
 
 
 
 
 
 
19
  return array(
20
- 'name' => 'datepicker',
21
- 'label' => __( 'Date picker', 'smart-custom-fields' ),
22
- 'optgroup' => 'other-fields',
23
  );
24
  }
25
 
26
  /**
27
- * admin_enqueue_scripts
28
- * @param string $hook
 
29
  */
30
- public function admin_enqueue_scripts( $hook ) {
 
 
 
 
 
 
 
 
 
 
 
 
 
31
  global $wp_scripts;
32
- if ( in_array( $hook, array( 'post-new.php', 'post.php' ) ) ) {
33
- $ui = $wp_scripts->query( 'jquery-ui-core' );
34
- wp_enqueue_style(
35
- 'jquery.ui',
36
- '//ajax.googleapis.com/ajax/libs/jqueryui/' . $ui->ver . '/themes/smoothness/jquery-ui.min.css',
37
- array(),
38
- $ui->ver
39
- );
40
- wp_enqueue_script( 'jquery-ui-datepicker' );
41
- wp_enqueue_script(
42
- SCF_Config::PREFIX . 'datepicker',
43
- plugins_url( '../../js/editor-datepicker.js', __FILE__ ),
44
- array( 'jquery', 'jquery-ui-datepicker' ),
45
- false,
46
- true
47
- );
48
- }
49
  }
50
 
51
  /**
52
- * get_field
53
- * @param array $field フィールドの情報
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
54
  * @param int $index インデックス番号
55
  * @param mixed $value 保存されている値(check のときだけ配列)
 
56
  */
57
- public function get_field( $field, $index, $value ) {
58
- $name = $this->get_name_attribute( $field['name'], $index );
59
  $disabled = $this->get_disable_attribute( $index );
60
-
61
- $js = array(
62
- 'showMonthAfterYear' => true,
63
- 'changeYear' => true,
64
- 'changeMonth' => true,
65
- );
66
- // 日本語の場合は日本語表記に変更
67
- if ( get_locale() === 'ja' ) {
68
- $js = array_merge( $js, array(
69
- 'yearSuffix' => '年',
70
- 'dateFormat' => 'yy-mm-dd',
71
- 'dayNames' => array(
72
- '日曜日', '月曜日', '火曜日', '水曜日', '木曜日', '金曜日', '土曜日',
73
- ),
74
- 'dayNamesMin' => array(
75
- '日', '月', '火', '水', '木', '金', '土',
76
- ),
77
- 'dayNamesShort' => array(
78
- '日曜', '月曜', '火曜', '水曜', '木曜', '金曜', '土曜',
79
- ),
80
- 'monthNames' => array(
81
- '1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月',
82
- ),
83
- 'monthNamesShort' => array(
84
- '1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月',
85
- )
86
- ) );
87
- }
88
- if ( !empty( $field['date_format'] ) ) {
89
- $js['dateFormat'] = $field['date_format'];
90
- }
91
- if ( !empty( $field['max_date'] ) ) {
92
- $js['maxDate'] = $field['max_date'];
93
- }
94
- if ( !empty( $field['min_date'] ) ) {
95
- $js['minDate'] = $field['min_date'];
96
- }
97
- $data_js = json_encode( $js );
98
 
99
  return sprintf(
100
  '<input type="text" name="%s" value="%s" class="%s" %s data-js=\'%s\' />',
@@ -107,7 +113,8 @@ class Smart_Custom_Fields_Field_Datepicker extends Smart_Custom_Fields_Field_Bas
107
  }
108
 
109
  /**
110
- * display_field_options
 
111
  * @param int $group_key
112
  * @param int $field_key
113
  */
@@ -117,18 +124,19 @@ class Smart_Custom_Fields_Field_Datepicker extends Smart_Custom_Fields_Field_Bas
117
  <th><?php esc_html_e( 'Default', 'smart-custom-fields' ); ?></th>
118
  <td>
119
  <input type="text"
120
- name="<?php echo esc_attr( $this->get_field_name( $group_key, $field_key, 'default' ) ); ?>"
121
- class="widefat"
122
- value="<?php echo esc_attr( $this->get_field_value( 'default' ) ); ?>" />
 
123
  </td>
124
  </tr>
125
  <tr>
126
  <th><?php esc_html_e( 'Date Format', 'smart-custom-fields' ); ?></th>
127
  <td>
128
  <input type="text"
129
- name="<?php echo esc_attr( $this->get_field_name( $group_key, $field_key, 'date_format' ) ); ?>"
130
  class="widefat"
131
- value="<?php echo esc_attr( $this->get_field_value( 'date_format' ) ); ?>"
132
  /><br />
133
  <span class="<?php echo esc_attr( SCF_Config::PREFIX ); ?>notes">
134
  <?php esc_html_e( 'e.g dd/mm/yy', 'smart-custom-fields' ); ?>
@@ -144,9 +152,9 @@ class Smart_Custom_Fields_Field_Datepicker extends Smart_Custom_Fields_Field_Bas
144
  <th><?php esc_html_e( 'Max Date', 'smart-custom-fields' ); ?></th>
145
  <td>
146
  <input type="text"
147
- name="<?php echo esc_attr( $this->get_field_name( $group_key, $field_key, 'max_date' ) ); ?>"
148
  class="widefat"
149
- value="<?php echo esc_attr( $this->get_field_value( 'max_date' ) ); ?>"
150
  /><br />
151
  <span class="<?php echo esc_attr( SCF_Config::PREFIX ); ?>notes">
152
  <?php esc_html_e( 'e.g +1m +1w', 'smart-custom-fields' ); ?>
@@ -162,9 +170,9 @@ class Smart_Custom_Fields_Field_Datepicker extends Smart_Custom_Fields_Field_Bas
162
  <th><?php esc_html_e( 'Min Date', 'smart-custom-fields' ); ?></th>
163
  <td>
164
  <input type="text"
165
- name="<?php echo esc_attr( $this->get_field_name( $group_key, $field_key, 'min_date' ) ); ?>"
166
  class="widefat"
167
- value="<?php echo esc_attr( $this->get_field_value( 'min_date' ) ); ?>"
168
  /><br />
169
  <span class="<?php echo esc_attr( SCF_Config::PREFIX ); ?>notes">
170
  <?php esc_html_e( 'e.g +1m +1w', 'smart-custom-fields' ); ?>
@@ -180,12 +188,57 @@ class Smart_Custom_Fields_Field_Datepicker extends Smart_Custom_Fields_Field_Bas
180
  <th><?php esc_html_e( 'Notes', 'smart-custom-fields' ); ?></th>
181
  <td>
182
  <input type="text"
183
- name="<?php echo esc_attr( $this->get_field_name( $group_key, $field_key, 'notes' ) ); ?>"
184
  class="widefat"
185
- value="<?php echo esc_attr( $this->get_field_value( 'notes' ) ); ?>"
186
  />
187
  </td>
188
  </tr>
189
  <?php
190
  }
191
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  <?php
2
  /**
3
  * Smart_Custom_Fields_Field_Datepicker
4
+ * Version : 1.1.0
5
  * Author : Takashi Kitajima
6
  * Created : January 17, 2015
7
+ * Modified : February 27, 2015
8
  * License : GPLv2
9
  * License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
  */
11
  class Smart_Custom_Fields_Field_Datepicker extends Smart_Custom_Fields_Field_Base {
12
 
13
  /**
14
+ * 必須項目の設定
15
+ *
16
+ * @return array
17
  */
18
  protected function init() {
19
+ add_action(
20
+ SCF_Config::PREFIX . 'before-editor-enqueue-scripts',
21
+ array( $this, 'editor_enqueue_scripts' )
22
+ );
23
+ add_action(
24
+ SCF_Config::PREFIX . 'before-settings-enqueue-scripts',
25
+ array( $this, 'settings_enqueue_scripts' )
26
+ );
27
  return array(
28
+ 'type' => 'datepicker',
29
+ 'display-name' => __( 'Date picker', 'smart-custom-fields' ),
30
+ 'optgroup' => 'other-fields',
31
  );
32
  }
33
 
34
  /**
35
+ * 設定項目の設定
36
+ *
37
+ * @return array
38
  */
39
+ protected function options() {
40
+ return array(
41
+ 'date_format' => '',
42
+ 'max_date' => '',
43
+ 'min_date' => '',
44
+ 'default' => '',
45
+ 'notes' => '',
46
+ );
47
+ }
48
+
49
+ /**
50
+ * CSS、JSの読み込み
51
+ */
52
+ public function editor_enqueue_scripts() {
53
  global $wp_scripts;
54
+ $ui = $wp_scripts->query( 'jquery-ui-core' );
55
+ wp_enqueue_style(
56
+ 'jquery.ui',
57
+ '//ajax.googleapis.com/ajax/libs/jqueryui/' . $ui->ver . '/themes/smoothness/jquery-ui.min.css',
58
+ array(),
59
+ $ui->ver
60
+ );
61
+ wp_enqueue_script( 'jquery-ui-datepicker' );
62
+ wp_enqueue_script(
63
+ SCF_Config::PREFIX . 'editor-datepicker',
64
+ plugins_url( '../../js/editor-datepicker.js', __FILE__ ),
65
+ array( 'jquery', 'jquery-ui-datepicker' ),
66
+ false,
67
+ true
68
+ );
 
 
69
  }
70
 
71
  /**
72
+ * CSS、JSの読み込み
73
+ */
74
+ public function settings_enqueue_scripts() {
75
+ global $wp_scripts;
76
+ $ui = $wp_scripts->query( 'jquery-ui-core' );
77
+ wp_enqueue_style(
78
+ 'jquery.ui',
79
+ '//ajax.googleapis.com/ajax/libs/jqueryui/' . $ui->ver . '/themes/smoothness/jquery-ui.min.css',
80
+ array(),
81
+ $ui->ver
82
+ );
83
+ wp_enqueue_script( 'jquery-ui-datepicker' );
84
+ wp_enqueue_script(
85
+ SCF_Config::PREFIX . 'settings-datepicker',
86
+ plugins_url( '../../js/settings-datepicker.js', __FILE__ ),
87
+ array( 'jquery', 'jquery-ui-datepicker' ),
88
+ false,
89
+ true
90
+ );
91
+ }
92
+
93
+ /**
94
+ * 投稿画面にフィールドを表示
95
+ *
96
  * @param int $index インデックス番号
97
  * @param mixed $value 保存されている値(check のときだけ配列)
98
+ * @return string html
99
  */
100
+ public function get_field( $index, $value ) {
101
+ $name = $this->get_field_name_in_editor( $index );
102
  $disabled = $this->get_disable_attribute( $index );
103
+ $data_js = $this->get_data_js();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
104
 
105
  return sprintf(
106
  '<input type="text" name="%s" value="%s" class="%s" %s data-js=\'%s\' />',
113
  }
114
 
115
  /**
116
+ * 設定画面にフィールドを表示(オリジナル項目)
117
+ *
118
  * @param int $group_key
119
  * @param int $field_key
120
  */
124
  <th><?php esc_html_e( 'Default', 'smart-custom-fields' ); ?></th>
125
  <td>
126
  <input type="text"
127
+ name="<?php echo esc_attr( $this->get_field_name_in_setting( $group_key, $field_key, 'default' ) ); ?>"
128
+ class="widefat default-option"
129
+ value="<?php echo esc_attr( $this->get( 'default' ) ); ?>"
130
+ data-js='<?php echo $this->get_data_js(); ?>' />
131
  </td>
132
  </tr>
133
  <tr>
134
  <th><?php esc_html_e( 'Date Format', 'smart-custom-fields' ); ?></th>
135
  <td>
136
  <input type="text"
137
+ name="<?php echo esc_attr( $this->get_field_name_in_setting( $group_key, $field_key, 'date_format' ) ); ?>"
138
  class="widefat"
139
+ value="<?php echo esc_attr( $this->get( 'date_format' ) ); ?>"
140
  /><br />
141
  <span class="<?php echo esc_attr( SCF_Config::PREFIX ); ?>notes">
142
  <?php esc_html_e( 'e.g dd/mm/yy', 'smart-custom-fields' ); ?>
152
  <th><?php esc_html_e( 'Max Date', 'smart-custom-fields' ); ?></th>
153
  <td>
154
  <input type="text"
155
+ name="<?php echo esc_attr( $this->get_field_name_in_setting( $group_key, $field_key, 'max_date' ) ); ?>"
156
  class="widefat"
157
+ value="<?php echo esc_attr( $this->get( 'max_date' ) ); ?>"
158
  /><br />
159
  <span class="<?php echo esc_attr( SCF_Config::PREFIX ); ?>notes">
160
  <?php esc_html_e( 'e.g +1m +1w', 'smart-custom-fields' ); ?>
170
  <th><?php esc_html_e( 'Min Date', 'smart-custom-fields' ); ?></th>
171
  <td>
172
  <input type="text"
173
+ name="<?php echo esc_attr( $this->get_field_name_in_setting( $group_key, $field_key, 'min_date' ) ); ?>"
174
  class="widefat"
175
+ value="<?php echo esc_attr( $this->get( 'min_date' ) ); ?>"
176
  /><br />
177
  <span class="<?php echo esc_attr( SCF_Config::PREFIX ); ?>notes">
178
  <?php esc_html_e( 'e.g +1m +1w', 'smart-custom-fields' ); ?>
188
  <th><?php esc_html_e( 'Notes', 'smart-custom-fields' ); ?></th>
189
  <td>
190
  <input type="text"
191
+ name="<?php echo esc_attr( $this->get_field_name_in_setting( $group_key, $field_key, 'notes' ) ); ?>"
192
  class="widefat"
193
+ value="<?php echo esc_attr( $this->get( 'notes' ) ); ?>"
194
  />
195
  </td>
196
  </tr>
197
  <?php
198
  }
199
+
200
+ /**
201
+ * 管理画面で設定された datepicker のオプションを json_encode して返す
202
+ *
203
+ * @return string json_encode された設定
204
+ */
205
+ protected function get_data_js() {
206
+ $js = array(
207
+ 'showMonthAfterYear' => true,
208
+ 'changeYear' => true,
209
+ 'changeMonth' => true,
210
+ );
211
+ // 日本語の場合は日本語表記に変更
212
+ if ( get_locale() === 'ja' ) {
213
+ $js = array_merge( $js, array(
214
+ 'yearSuffix' => '年',
215
+ 'dateFormat' => 'yy-mm-dd',
216
+ 'dayNames' => array(
217
+ '日曜日', '月曜日', '火曜日', '水曜日', '木曜日', '金曜日', '土曜日',
218
+ ),
219
+ 'dayNamesMin' => array(
220
+ '日', '月', '火', '水', '木', '金', '土',
221
+ ),
222
+ 'dayNamesShort' => array(
223
+ '日曜', '月曜', '火曜', '水曜', '木曜', '金曜', '土曜',
224
+ ),
225
+ 'monthNames' => array(
226
+ '1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月',
227
+ ),
228
+ 'monthNamesShort' => array(
229
+ '1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月',
230
+ )
231
+ ) );
232
+ }
233
+ if ( $this->get( 'date_format' ) ) {
234
+ $js['dateFormat'] = $this->get( 'date_format' );
235
+ }
236
+ if ( $this->get( 'max_date' ) ) {
237
+ $js['maxDate'] = $this->get( 'max_date' );
238
+ }
239
+ if ( $this->get( 'min_date' ) ) {
240
+ $js['minDate'] = $this->get( 'min_date' );
241
+ }
242
+ return json_encode( $js );
243
+ }
244
+ }
classes/fields/class.field-file.php CHANGED
@@ -1,35 +1,48 @@
1
  <?php
2
  /**
3
  * Smart_Custom_Fields_Field_File
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
  */
11
  class Smart_Custom_Fields_Field_File extends Smart_Custom_Fields_Field_Base {
12
 
13
  /**
14
- * init
15
- * @return array ( name, label, optgroup )
 
16
  */
17
  protected function init() {
18
  return array(
19
- 'name' => 'file',
20
- 'label' => __( 'File', 'smart-custom-fields' ),
21
- 'optgroup' => 'content-fields',
22
  );
23
  }
24
 
25
  /**
26
- * get_field
27
- * @param array $field フィールドの情報
 
 
 
 
 
 
 
 
 
 
 
28
  * @param int $index インデックス番号
29
  * @param mixed $value 保存されている値(check のときだけ配列)
 
30
  */
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
 
35
  $btn_remove = sprintf(
@@ -68,7 +81,8 @@ class Smart_Custom_Fields_Field_File extends Smart_Custom_Fields_Field_Base {
68
  }
69
 
70
  /**
71
- * display_field_options
 
72
  * @param int $group_key
73
  * @param int $field_key
74
  */
@@ -78,12 +92,12 @@ class Smart_Custom_Fields_Field_File extends Smart_Custom_Fields_Field_Base {
78
  <th><?php esc_html_e( 'Notes', 'smart-custom-fields' ); ?></th>
79
  <td>
80
  <input type="text"
81
- name="<?php echo esc_attr( $this->get_field_name( $group_key, $field_key, 'notes' ) ); ?>"
82
  class="widefat"
83
- value="<?php echo esc_attr( $this->get_field_value( 'notes' ) ); ?>"
84
  />
85
  </td>
86
  </tr>
87
  <?php
88
  }
89
- }
1
  <?php
2
  /**
3
  * Smart_Custom_Fields_Field_File
4
+ * Version : 1.1.0
5
  * Author : Takashi Kitajima
6
  * Created : October 7, 2014
7
+ * Modified : February 27, 2015
8
  * License : GPLv2
9
  * License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
  */
11
  class Smart_Custom_Fields_Field_File extends Smart_Custom_Fields_Field_Base {
12
 
13
  /**
14
+ * 必須項目の設定
15
+ *
16
+ * @return array
17
  */
18
  protected function init() {
19
  return array(
20
+ 'type' => 'file',
21
+ 'display-name' => __( 'File', 'smart-custom-fields' ),
22
+ 'optgroup' => 'content-fields',
23
  );
24
  }
25
 
26
  /**
27
+ * 設定項目の設定
28
+ *
29
+ * @return array
30
+ */
31
+ protected function options() {
32
+ return array(
33
+ 'notes' => '',
34
+ );
35
+ }
36
+
37
+ /**
38
+ * 投稿画面にフィールドを表示
39
+ *
40
  * @param int $index インデックス番号
41
  * @param mixed $value 保存されている値(check のときだけ配列)
42
+ * @return string html
43
  */
44
+ public function get_field( $index, $value ) {
45
+ $name = $this->get_field_name_in_editor( $index );
46
  $disabled = $this->get_disable_attribute( $index );
47
 
48
  $btn_remove = sprintf(
81
  }
82
 
83
  /**
84
+ * 設定画面にフィールドを表示(オリジナル項目)
85
+ *
86
  * @param int $group_key
87
  * @param int $field_key
88
  */
92
  <th><?php esc_html_e( 'Notes', 'smart-custom-fields' ); ?></th>
93
  <td>
94
  <input type="text"
95
+ name="<?php echo esc_attr( $this->get_field_name_in_setting( $group_key, $field_key, 'notes' ) ); ?>"
96
  class="widefat"
97
+ value="<?php echo esc_attr( $this->get( 'notes' ) ); ?>"
98
  />
99
  </td>
100
  </tr>
101
  <?php
102
  }
103
+ }
classes/fields/class.field-image.php CHANGED
@@ -1,35 +1,48 @@
1
  <?php
2
  /**
3
  * Smart_Custom_Fields_Field_Image
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
  */
11
  class Smart_Custom_Fields_Field_Image extends Smart_Custom_Fields_Field_Base {
12
 
13
  /**
14
- * init
15
- * @return array ( name, label, optgroup )
 
16
  */
17
  protected function init() {
18
  return array(
19
- 'name' => 'image',
20
- 'label' => __( 'Image', 'smart-custom-fields' ),
21
- 'optgroup' => 'content-fields',
22
  );
23
  }
24
 
25
  /**
26
- * get_field
27
- * @param array $field フィールドの情報
 
 
 
 
 
 
 
 
 
 
 
28
  * @param int $index インデックス番号
29
  * @param mixed $value 保存されている値(check のときだけ配列)
 
30
  */
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
 
35
  $btn_remove = sprintf(
@@ -67,7 +80,8 @@ class Smart_Custom_Fields_Field_Image extends Smart_Custom_Fields_Field_Base {
67
  }
68
 
69
  /**
70
- * display_field_options
 
71
  * @param int $group_key
72
  * @param int $field_key
73
  */
@@ -77,12 +91,12 @@ class Smart_Custom_Fields_Field_Image extends Smart_Custom_Fields_Field_Base {
77
  <th><?php esc_html_e( 'Notes', 'smart-custom-fields' ); ?></th>
78
  <td>
79
  <input type="text"
80
- name="<?php echo esc_attr( $this->get_field_name( $group_key, $field_key, 'notes' ) ); ?>"
81
  class="widefat"
82
- value="<?php echo esc_attr( $this->get_field_value( 'notes' ) ); ?>"
83
  />
84
  </td>
85
  </tr>
86
  <?php
87
  }
88
- }
1
  <?php
2
  /**
3
  * Smart_Custom_Fields_Field_Image
4
+ * Version : 1.1.0
5
  * Author : Takashi Kitajima
6
  * Created : October 7, 2014
7
+ * Modified : February 27, 2015
8
  * License : GPLv2
9
  * License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
  */
11
  class Smart_Custom_Fields_Field_Image extends Smart_Custom_Fields_Field_Base {
12
 
13
  /**
14
+ * 必須項目の設定
15
+ *
16
+ * @return array
17
  */
18
  protected function init() {
19
  return array(
20
+ 'type' => 'image',
21
+ 'display-name' => __( 'Image', 'smart-custom-fields' ),
22
+ 'optgroup' => 'content-fields',
23
  );
24
  }
25
 
26
  /**
27
+ * 設定項目の設定
28
+ *
29
+ * @return array
30
+ */
31
+ protected function options() {
32
+ return array(
33
+ 'notes' => '',
34
+ );
35
+ }
36
+
37
+ /**
38
+ * 投稿画面にフィールドを表示
39
+ *
40
  * @param int $index インデックス番号
41
  * @param mixed $value 保存されている値(check のときだけ配列)
42
+ * @return string html
43
  */
44
+ public function get_field( $index, $value ) {
45
+ $name = $this->get_field_name_in_editor( $index );
46
  $disabled = $this->get_disable_attribute( $index );
47
 
48
  $btn_remove = sprintf(
80
  }
81
 
82
  /**
83
+ * 設定画面にフィールドを表示(オリジナル項目)
84
+ *
85
  * @param int $group_key
86
  * @param int $field_key
87
  */
91
  <th><?php esc_html_e( 'Notes', 'smart-custom-fields' ); ?></th>
92
  <td>
93
  <input type="text"
94
+ name="<?php echo esc_attr( $this->get_field_name_in_setting( $group_key, $field_key, 'notes' ) ); ?>"
95
  class="widefat"
96
+ value="<?php echo esc_attr( $this->get( 'notes' ) ); ?>"
97
  />
98
  </td>
99
  </tr>
100
  <?php
101
  }
102
+ }
classes/fields/class.field-radio.php CHANGED
@@ -1,37 +1,52 @@
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
  */
11
  class Smart_Custom_Fields_Field_Radio extends Smart_Custom_Fields_Field_Base {
12
 
13
  /**
14
- * init
15
- * @return array ( name, label, optgroup )
 
16
  */
17
  protected function init() {
18
  return array(
19
- 'name' => 'radio',
20
- 'label' => __( 'Radio', 'smart-custom-fields' ),
21
- 'optgroup' => 'select-fields',
22
  );
23
  }
24
 
25
  /**
26
- * get_field
27
- * @param array $field フィールドの情報
 
 
 
 
 
 
 
 
 
 
 
 
 
28
  * @param int $index インデックス番号
29
  * @param mixed $value 保存されている値(check のときだけ配列)
 
30
  */
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 />',
@@ -53,7 +68,8 @@ class Smart_Custom_Fields_Field_Radio extends Smart_Custom_Fields_Field_Base {
53
  }
54
 
55
  /**
56
- * display_field_options
 
57
  * @param int $group_key
58
  * @param int $field_key
59
  */
@@ -63,30 +79,30 @@ class Smart_Custom_Fields_Field_Radio extends Smart_Custom_Fields_Field_Base {
63
  <th><?php esc_html_e( 'Choices', 'smart-custom-fields' ); ?></th>
64
  <td>
65
  <textarea
66
- name="<?php echo esc_attr( $this->get_field_name( $group_key, $field_key, 'choices' ) ); ?>"
67
  class="widefat"
68
- rows="5" /><?php echo esc_textarea( "\n" . $this->get_field_value( 'choices' ) ); ?></textarea>
69
  </td>
70
  </tr>
71
  <tr>
72
  <th><?php esc_html_e( 'Default', 'smart-custom-fields' ); ?></th>
73
  <td>
74
  <input type="text"
75
- name="<?php echo esc_attr( $this->get_field_name( $group_key, $field_key, 'default' ) ); ?>"
76
  class="widefat"
77
- value="<?php echo esc_attr( $this->get_field_value( 'default' ) ); ?>" />
78
  </td>
79
  </tr>
80
  <tr>
81
  <th><?php esc_html_e( 'Notes', 'smart-custom-fields' ); ?></th>
82
  <td>
83
  <input type="text"
84
- name="<?php echo esc_attr( $this->get_field_name( $group_key, $field_key, 'notes' ) ); ?>"
85
  class="widefat"
86
- value="<?php echo esc_attr( $this->get_field_value( 'notes' ) ); ?>"
87
  />
88
  </td>
89
  </tr>
90
  <?php
91
  }
92
- }
1
  <?php
2
  /**
3
  * Smart_Custom_Fields_Field_Radio
4
+ * Version : 1.1.0
5
  * Author : Takashi Kitajima
6
  * Created : October 7, 2014
7
+ * Modified : February 27, 2015
8
  * License : GPLv2
9
  * License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
  */
11
  class Smart_Custom_Fields_Field_Radio extends Smart_Custom_Fields_Field_Base {
12
 
13
  /**
14
+ * 必須項目の設定
15
+ *
16
+ * @return array
17
  */
18
  protected function init() {
19
  return array(
20
+ 'type' => 'radio',
21
+ 'display-name' => __( 'Radio', 'smart-custom-fields' ),
22
+ 'optgroup' => 'select-fields',
23
  );
24
  }
25
 
26
  /**
27
+ * 設定項目の設定
28
+ *
29
+ * @return array
30
+ */
31
+ protected function options() {
32
+ return array(
33
+ 'choices' => '',
34
+ 'default' => '',
35
+ 'notes' => '',
36
+ );
37
+ }
38
+
39
+ /**
40
+ * 投稿画面にフィールドを表示
41
+ *
42
  * @param int $index インデックス番号
43
  * @param mixed $value 保存されている値(check のときだけ配列)
44
+ * @return string html
45
  */
46
+ public function get_field( $index, $value ) {
47
+ $name = $this->get_field_name_in_editor( $index );
48
  $disabled = $this->get_disable_attribute( $index );
49
+ $choices = SCF::choices_eol_to_array( $this->get( 'choices' ) );
50
 
51
  $form_field = sprintf(
52
  '<input type="hidden" name="%s" value="" %s />',
68
  }
69
 
70
  /**
71
+ * 設定画面にフィールドを表示(オリジナル項目)
72
+ *
73
  * @param int $group_key
74
  * @param int $field_key
75
  */
79
  <th><?php esc_html_e( 'Choices', 'smart-custom-fields' ); ?></th>
80
  <td>
81
  <textarea
82
+ name="<?php echo esc_attr( $this->get_field_name_in_setting( $group_key, $field_key, 'choices' ) ); ?>"
83
  class="widefat"
84
+ rows="5" /><?php echo esc_textarea( "\n" . $this->get( 'choices' ) ); ?></textarea>
85
  </td>
86
  </tr>
87
  <tr>
88
  <th><?php esc_html_e( 'Default', 'smart-custom-fields' ); ?></th>
89
  <td>
90
  <input type="text"
91
+ name="<?php echo esc_attr( $this->get_field_name_in_setting( $group_key, $field_key, 'default' ) ); ?>"
92
  class="widefat"
93
+ value="<?php echo esc_attr( $this->get( 'default' ) ); ?>" />
94
  </td>
95
  </tr>
96
  <tr>
97
  <th><?php esc_html_e( 'Notes', 'smart-custom-fields' ); ?></th>
98
  <td>
99
  <input type="text"
100
+ name="<?php echo esc_attr( $this->get_field_name_in_setting( $group_key, $field_key, 'notes' ) ); ?>"
101
  class="widefat"
102
+ value="<?php echo esc_attr( $this->get( 'notes' ) ); ?>"
103
  />
104
  </td>
105
  </tr>
106
  <?php
107
  }
108
+ }
classes/fields/class.field-relation.php CHANGED
@@ -1,39 +1,53 @@
1
  <?php
2
  /**
3
  * Smart_Custom_Fields_Field_Relation
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
  */
11
  class Smart_Custom_Fields_Field_Relation extends Smart_Custom_Fields_Field_Base {
12
 
13
  /**
14
- * init
15
- * @return array ( name, label, optgroup, allow-multiple-data )
 
16
  */
17
  protected function init() {
18
  add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
19
  add_action( 'wp_ajax_smart-cf-relational-posts-search', array( $this, 'relational_posts_search' ) );
20
  return array(
21
- 'name' => 'relation',
22
- 'label' => __( 'Relation', 'smart-custom-fields' ),
23
- 'optgroup' => 'other-fields',
24
  'allow-multiple-data' => true,
25
  );
26
  }
27
 
28
  /**
29
- * admin_enqueue_scripts
 
 
 
 
 
 
 
 
 
 
 
 
 
30
  * @param string $hook
31
  */
32
  public function admin_enqueue_scripts( $hook ) {
33
  if ( in_array( $hook, array( 'post-new.php', 'post.php' ) ) ) {
34
  wp_enqueue_script(
35
  SCF_Config::PREFIX . 'editor-relation',
36
- plugin_dir_url( __FILE__ ) . '../../js/editor-relation.js',
37
  array( 'jquery' ),
38
  null,
39
  true
@@ -47,7 +61,7 @@ class Smart_Custom_Fields_Field_Relation extends Smart_Custom_Fields_Field_Base
47
  }
48
 
49
  /**
50
- * relational_posts_search
51
  */
52
  public function relational_posts_search() {
53
  check_ajax_referer( SCF_Config::NAME . '-relation', 'nonce' );
@@ -70,15 +84,16 @@ class Smart_Custom_Fields_Field_Relation extends Smart_Custom_Fields_Field_Base
70
  }
71
 
72
  /**
73
- * get_field
74
- * @param array $field フィールドの情報
75
  * @param int $index インデックス番号
76
  * @param mixed $value 保存されている値(check のときだけ配列)
 
77
  */
78
- public function get_field( $field, $index, $value ) {
79
- $name = $this->get_name_attribute( $field['name'], $index );
80
- $disabled = $this->get_disable_attribute( $index );
81
- $post_type = $this->get( 'post-type', $field );
82
  if ( !$post_type ) {
83
  $post_type = array( 'post' );
84
  }
@@ -86,9 +101,9 @@ class Smart_Custom_Fields_Field_Relation extends Smart_Custom_Fields_Field_Base
86
 
87
  // 選択肢
88
  $choices_posts = get_posts( array(
89
- 'post_type' => $post_type,
90
- 'order' => 'ASC',
91
- 'orderby' => 'ID',
92
  'posts_per_page' => $posts_per_page,
93
  ) );
94
  $choices_li = array();
@@ -160,7 +175,8 @@ class Smart_Custom_Fields_Field_Relation extends Smart_Custom_Fields_Field_Base
160
  }
161
 
162
  /**
163
- * display_field_options
 
164
  * @param int $group_key
165
  * @param int $field_key
166
  */
@@ -178,10 +194,10 @@ class Smart_Custom_Fields_Field_Relation extends Smart_Custom_Fields_Field_Base
178
  ?>
179
  <?php foreach ( $post_types as $post_type => $post_type_object ) : ?>
180
  <?php
181
- $save_post_type = $this->get( 'post-type', $this->field );
182
- $checked = ( is_array( $save_post_type ) && in_array( $post_type, $save_post_type ) ) ? 'checked="checked"' : ''; ?>
183
  <input type="checkbox"
184
- name="<?php echo esc_attr( $this->get_field_name( $group_key, $field_key, 'post-type' ) ); ?>[]"
185
  value="<?php echo esc_attr( $post_type ); ?>"
186
  <?php echo $checked; ?> /><?php echo esc_html( $post_type_object->labels->singular_name ); ?>
187
  <?php endforeach; ?>
@@ -191,12 +207,12 @@ class Smart_Custom_Fields_Field_Relation extends Smart_Custom_Fields_Field_Base
191
  <th><?php esc_html_e( 'Notes', 'smart-custom-fields' ); ?></th>
192
  <td>
193
  <input type="text"
194
- name="<?php echo esc_attr( $this->get_field_name( $group_key, $field_key, 'notes' ) ); ?>"
195
  class="widefat"
196
- value="<?php echo esc_attr( $this->get_field_value( 'notes' ) ); ?>"
197
  />
198
  </td>
199
  </tr>
200
  <?php
201
  }
202
- }
1
  <?php
2
  /**
3
  * Smart_Custom_Fields_Field_Relation
4
+ * Version : 1.1.0
5
  * Author : Takashi Kitajima
6
  * Created : October 7, 2014
7
+ * Modified : February 27, 2015
8
  * License : GPLv2
9
  * License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
  */
11
  class Smart_Custom_Fields_Field_Relation extends Smart_Custom_Fields_Field_Base {
12
 
13
  /**
14
+ * 必須項目の設定
15
+ *
16
+ * @return array
17
  */
18
  protected function init() {
19
  add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
20
  add_action( 'wp_ajax_smart-cf-relational-posts-search', array( $this, 'relational_posts_search' ) );
21
  return array(
22
+ 'type' => 'relation',
23
+ 'display-name' => __( 'Relation', 'smart-custom-fields' ),
24
+ 'optgroup' => 'other-fields',
25
  'allow-multiple-data' => true,
26
  );
27
  }
28
 
29
  /**
30
+ * 設定項目の設定
31
+ *
32
+ * @return array
33
+ */
34
+ protected function options() {
35
+ return array(
36
+ 'post-type' => '',
37
+ 'notes' => '',
38
+ );
39
+ }
40
+
41
+ /**
42
+ * JS の読み込み
43
+ *
44
  * @param string $hook
45
  */
46
  public function admin_enqueue_scripts( $hook ) {
47
  if ( in_array( $hook, array( 'post-new.php', 'post.php' ) ) ) {
48
  wp_enqueue_script(
49
  SCF_Config::PREFIX . 'editor-relation',
50
+ plugins_url( SCF_Config::NAME ) . '/js/editor-relation.js',
51
  array( 'jquery' ),
52
  null,
53
  true
61
  }
62
 
63
  /**
64
+ * 投稿読み込みボタンをクリックされたときに投稿を読み込む実処理
65
  */
66
  public function relational_posts_search() {
67
  check_ajax_referer( SCF_Config::NAME . '-relation', 'nonce' );
84
  }
85
 
86
  /**
87
+ * 投稿画面にフィールドを表示
88
+ *
89
  * @param int $index インデックス番号
90
  * @param mixed $value 保存されている値(check のときだけ配列)
91
+ * @return string html
92
  */
93
+ public function get_field( $index, $value ) {
94
+ $name = $this->get_field_name_in_editor( $index );
95
+ $disabled = $this->get_disable_attribute( $index );
96
+ $post_type = $this->get( 'post-type' );
97
  if ( !$post_type ) {
98
  $post_type = array( 'post' );
99
  }
101
 
102
  // 選択肢
103
  $choices_posts = get_posts( array(
104
+ 'post_type' => $post_type,
105
+ 'order' => 'ASC',
106
+ 'orderby' => 'ID',
107
  'posts_per_page' => $posts_per_page,
108
  ) );
109
  $choices_li = array();
175
  }
176
 
177
  /**
178
+ * 設定画面にフィールドを表示(オリジナル項目)
179
+ *
180
  * @param int $group_key
181
  * @param int $field_key
182
  */
194
  ?>
195
  <?php foreach ( $post_types as $post_type => $post_type_object ) : ?>
196
  <?php
197
+ $save_post_types = $this->get( 'post-type' );
198
+ $checked = ( is_array( $save_post_types ) && in_array( $post_type, $save_post_types ) ) ? 'checked="checked"' : ''; ?>
199
  <input type="checkbox"
200
+ name="<?php echo esc_attr( $this->get_field_name_in_setting( $group_key, $field_key, 'post-type' ) ); ?>[]"
201
  value="<?php echo esc_attr( $post_type ); ?>"
202
  <?php echo $checked; ?> /><?php echo esc_html( $post_type_object->labels->singular_name ); ?>
203
  <?php endforeach; ?>
207
  <th><?php esc_html_e( 'Notes', 'smart-custom-fields' ); ?></th>
208
  <td>
209
  <input type="text"
210
+ name="<?php echo esc_attr( $this->get_field_name_in_setting( $group_key, $field_key, 'notes' ) ); ?>"
211
  class="widefat"
212
+ value="<?php echo esc_attr( $this->get( 'notes' ) ); ?>"
213
  />
214
  </td>
215
  </tr>
216
  <?php
217
  }
218
+ }
classes/fields/class.field-select.php CHANGED
@@ -1,37 +1,52 @@
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
  */
11
  class Smart_Custom_Fields_Field_Select extends Smart_Custom_Fields_Field_Base {
12
 
13
  /**
14
- * init
15
- * @return array ( name, label, optgroup )
 
16
  */
17
  protected function init() {
18
  return array(
19
- 'name' => 'select',
20
- 'label' => __( 'Select', 'smart-custom-fields' ),
21
- 'optgroup' => 'select-fields',
22
  );
23
  }
24
 
25
  /**
26
- * get_field
27
- * @param array $field フィールドの情報
 
 
 
 
 
 
 
 
 
 
 
 
 
28
  * @param int $index インデックス番号
29
  * @param mixed $value 保存されている値(check のときだけ配列)
 
30
  */
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 ) {
@@ -50,7 +65,8 @@ class Smart_Custom_Fields_Field_Select extends Smart_Custom_Fields_Field_Base {
50
  }
51
 
52
  /**
53
- * display_field_options
 
54
  * @param int $group_key
55
  * @param int $field_key
56
  */
@@ -60,30 +76,30 @@ class Smart_Custom_Fields_Field_Select extends Smart_Custom_Fields_Field_Base {
60
  <th><?php esc_html_e( 'Choices', 'smart-custom-fields' ); ?></th>
61
  <td>
62
  <textarea
63
- name="<?php echo esc_attr( $this->get_field_name( $group_key, $field_key, 'choices' ) ); ?>"
64
  class="widefat"
65
- rows="5" /><?php echo esc_textarea( "\n" . $this->get_field_value( 'choices' ) ); ?></textarea>
66
  </td>
67
  </tr>
68
  <tr>
69
  <th><?php esc_html_e( 'Default', 'smart-custom-fields' ); ?></th>
70
  <td>
71
  <input type="text"
72
- name="<?php echo esc_attr( $this->get_field_name( $group_key, $field_key, 'default' ) ); ?>"
73
  class="widefat"
74
- value="<?php echo esc_attr( $this->get_field_value( 'default' ) ); ?>" />
75
  </td>
76
  </tr>
77
  <tr>
78
  <th><?php esc_html_e( 'Notes', 'smart-custom-fields' ); ?></th>
79
  <td>
80
  <input type="text"
81
- name="<?php echo esc_attr( $this->get_field_name( $group_key, $field_key, 'notes' ) ); ?>"
82
  class="widefat"
83
- value="<?php echo esc_attr( $this->get_field_value( 'notes' ) ); ?>"
84
  />
85
  </td>
86
  </tr>
87
  <?php
88
  }
89
- }
1
  <?php
2
  /**
3
  * Smart_Custom_Fields_Field_Select
4
+ * Version : 1.1.0
5
  * Author : Takashi Kitajima
6
  * Created : October 7, 2014
7
+ * Modified : February 27, 2015
8
  * License : GPLv2
9
  * License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
  */
11
  class Smart_Custom_Fields_Field_Select extends Smart_Custom_Fields_Field_Base {
12
 
13
  /**
14
+ * 必須項目の設定
15
+ *
16
+ * @return array
17
  */
18
  protected function init() {
19
  return array(
20
+ 'type' => 'select',
21
+ 'display-name' => __( 'Select', 'smart-custom-fields' ),
22
+ 'optgroup' => 'select-fields',
23
  );
24
  }
25
 
26
  /**
27
+ * 設定項目の設定
28
+ *
29
+ * @return array
30
+ */
31
+ protected function options() {
32
+ return array(
33
+ 'choices' => '',
34
+ 'default' => '',
35
+ 'notes' => '',
36
+ );
37
+ }
38
+
39
+ /**
40
+ * 投稿画面にフィールドを表示
41
+ *
42
  * @param int $index インデックス番号
43
  * @param mixed $value 保存されている値(check のときだけ配列)
44
+ * @return string html
45
  */
46
+ public function get_field( $index, $value ) {
47
+ $name = $this->get_field_name_in_editor( $index );
48
  $disabled = $this->get_disable_attribute( $index );
49
+ $choices = SCF::choices_eol_to_array( $this->get( 'choices' ) );
50
 
51
  $form_field = '';
52
  foreach ( $choices as $choice ) {
65
  }
66
 
67
  /**
68
+ * 設定画面にフィールドを表示(オリジナル項目)
69
+ *
70
  * @param int $group_key
71
  * @param int $field_key
72
  */
76
  <th><?php esc_html_e( 'Choices', 'smart-custom-fields' ); ?></th>
77
  <td>
78
  <textarea
79
+ name="<?php echo esc_attr( $this->get_field_name_in_setting( $group_key, $field_key, 'choices' ) ); ?>"
80
  class="widefat"
81
+ rows="5" /><?php echo esc_textarea( "\n" . $this->get( 'choices' ) ); ?></textarea>
82
  </td>
83
  </tr>
84
  <tr>
85
  <th><?php esc_html_e( 'Default', 'smart-custom-fields' ); ?></th>
86
  <td>
87
  <input type="text"
88
+ name="<?php echo esc_attr( $this->get_field_name_in_setting( $group_key, $field_key, 'default' ) ); ?>"
89
  class="widefat"
90
+ value="<?php echo esc_attr( $this->get( 'default' ) ); ?>" />
91
  </td>
92
  </tr>
93
  <tr>
94
  <th><?php esc_html_e( 'Notes', 'smart-custom-fields' ); ?></th>
95
  <td>
96
  <input type="text"
97
+ name="<?php echo esc_attr( $this->get_field_name_in_setting( $group_key, $field_key, 'notes' ) ); ?>"
98
  class="widefat"
99
+ value="<?php echo esc_attr( $this->get( 'notes' ) ); ?>"
100
  />
101
  </td>
102
  </tr>
103
  <?php
104
  }
105
+ }
classes/fields/class.field-text.php CHANGED
@@ -1,35 +1,49 @@
1
  <?php
2
  /**
3
  * Smart_Custom_Fields_Field_Text
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
  */
11
  class Smart_Custom_Fields_Field_Text extends Smart_Custom_Fields_Field_Base {
12
 
13
  /**
14
- * init
15
- * @return array ( name, label, optgroup )
 
16
  */
17
  protected function init() {
18
  return array(
19
- 'name' => 'text',
20
- 'label' => __( 'Text', 'smart-custom-fields' ),
21
- 'optgroup' => 'basic-fields',
22
  );
23
  }
24
 
25
  /**
26
- * get_field
27
- * @param array $field フィールドの情報
 
 
 
 
 
 
 
 
 
 
 
 
28
  * @param int $index インデックス番号
29
  * @param mixed $value 保存されている値(check のときだけ配列)
 
30
  */
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
  return sprintf(
35
  '<input type="text" name="%s" value="%s" class="widefat" %s />',
@@ -40,7 +54,8 @@ class Smart_Custom_Fields_Field_Text extends Smart_Custom_Fields_Field_Base {
40
  }
41
 
42
  /**
43
- * display_field_options
 
44
  * @param int $group_key
45
  * @param int $field_key
46
  */
@@ -50,21 +65,21 @@ class Smart_Custom_Fields_Field_Text extends Smart_Custom_Fields_Field_Base {
50
  <th><?php esc_html_e( 'Default', 'smart-custom-fields' ); ?></th>
51
  <td>
52
  <input type="text"
53
- name="<?php echo esc_attr( $this->get_field_name( $group_key, $field_key, 'default' ) ); ?>"
54
  class="widefat"
55
- value="<?php echo esc_attr( $this->get_field_value( 'default' ) ); ?>" />
56
  </td>
57
  </tr>
58
  <tr>
59
  <th><?php esc_html_e( 'Notes', 'smart-custom-fields' ); ?></th>
60
  <td>
61
  <input type="text"
62
- name="<?php echo esc_attr( $this->get_field_name( $group_key, $field_key, 'notes' ) ); ?>"
63
  class="widefat"
64
- value="<?php echo esc_attr( $this->get_field_value( 'notes' ) ); ?>"
65
  />
66
  </td>
67
  </tr>
68
  <?php
69
  }
70
- }
1
  <?php
2
  /**
3
  * Smart_Custom_Fields_Field_Text
4
+ * Version : 1.1.0
5
  * Author : Takashi Kitajima
6
  * Created : October 7, 2014
7
+ * Modified : February 27, 2015
8
  * License : GPLv2
9
  * License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
  */
11
  class Smart_Custom_Fields_Field_Text extends Smart_Custom_Fields_Field_Base {
12
 
13
  /**
14
+ * 必須項目の設定
15
+ *
16
+ * @return array
17
  */
18
  protected function init() {
19
  return array(
20
+ 'type' => 'text',
21
+ 'display-name' => __( 'Text', 'smart-custom-fields' ),
22
+ 'optgroup' => 'basic-fields',
23
  );
24
  }
25
 
26
  /**
27
+ * 設定項目の設定
28
+ *
29
+ * @return array
30
+ */
31
+ protected function options() {
32
+ return array(
33
+ 'default' => '',
34
+ 'notes' => '',
35
+ );
36
+ }
37
+
38
+ /**
39
+ * 投稿画面にフィールドを表示
40
+ *
41
  * @param int $index インデックス番号
42
  * @param mixed $value 保存されている値(check のときだけ配列)
43
+ * @return string html
44
  */
45
+ public function get_field( $index, $value ) {
46
+ $name = $this->get_field_name_in_editor( $index );
47
  $disabled = $this->get_disable_attribute( $index );
48
  return sprintf(
49
  '<input type="text" name="%s" value="%s" class="widefat" %s />',
54
  }
55
 
56
  /**
57
+ * 設定画面にフィールドを表示(オリジナル項目)
58
+ *
59
  * @param int $group_key
60
  * @param int $field_key
61
  */
65
  <th><?php esc_html_e( 'Default', 'smart-custom-fields' ); ?></th>
66
  <td>
67
  <input type="text"
68
+ name="<?php echo esc_attr( $this->get_field_name_in_setting( $group_key, $field_key, 'default' ) ); ?>"
69
  class="widefat"
70
+ value="<?php echo esc_attr( $this->get( 'default' ) ); ?>" />
71
  </td>
72
  </tr>
73
  <tr>
74
  <th><?php esc_html_e( 'Notes', 'smart-custom-fields' ); ?></th>
75
  <td>
76
  <input type="text"
77
+ name="<?php echo esc_attr( $this->get_field_name_in_setting( $group_key, $field_key, 'notes' ) ); ?>"
78
  class="widefat"
79
+ value="<?php echo esc_attr( $this->get( 'notes' ) ); ?>"
80
  />
81
  </td>
82
  </tr>
83
  <?php
84
  }
85
+ }
classes/fields/class.field-textarea.php CHANGED
@@ -1,35 +1,49 @@
1
  <?php
2
  /**
3
  * Smart_Custom_Fields_Field_Textarea
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
  */
11
  class Smart_Custom_Fields_Field_Textarea extends Smart_Custom_Fields_Field_Base {
12
 
13
  /**
14
- * init
15
- * @return array ( name, label, optgroup )
 
16
  */
17
  protected function init() {
18
  return array(
19
- 'name' => 'textarea',
20
- 'label' => __( 'Textarea', 'smart-custom-fields' ),
21
- 'optgroup' => 'basic-fields',
22
  );
23
  }
24
 
25
  /**
26
- * get_field
27
- * @param array $field フィールドの情報
 
 
 
 
 
 
 
 
 
 
 
 
28
  * @param int $index インデックス番号
29
  * @param mixed $value 保存されている値(check のときだけ配列)
 
30
  */
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
  return sprintf(
35
  '<textarea name="%s" rows="5" class="widefat" %s>%s</textarea>',
@@ -40,7 +54,8 @@ class Smart_Custom_Fields_Field_Textarea extends Smart_Custom_Fields_Field_Base
40
  }
41
 
42
  /**
43
- * display_field_options
 
44
  * @param int $group_key
45
  * @param int $field_key
46
  */
@@ -50,21 +65,21 @@ class Smart_Custom_Fields_Field_Textarea extends Smart_Custom_Fields_Field_Base
50
  <th><?php esc_html_e( 'Default', 'smart-custom-fields' ); ?></th>
51
  <td>
52
  <textarea
53
- name="<?php echo esc_attr( $this->get_field_name( $group_key, $field_key, 'default' ) ); ?>"
54
  class="widefat"
55
- rows="5"><?php echo esc_textarea( "\n" . $this->get_field_value( 'default' ) ); ?></textarea>
56
  </td>
57
  </tr>
58
  <tr>
59
  <th><?php esc_html_e( 'Notes', 'smart-custom-fields' ); ?></th>
60
  <td>
61
  <input type="text"
62
- name="<?php echo esc_attr( $this->get_field_name( $group_key, $field_key, 'notes' ) ); ?>"
63
  class="widefat"
64
- value="<?php echo esc_attr( $this->get_field_value( 'notes' ) ); ?>"
65
  />
66
  </td>
67
  </tr>
68
  <?php
69
  }
70
- }
1
  <?php
2
  /**
3
  * Smart_Custom_Fields_Field_Textarea
4
+ * Version : 1.1.0
5
  * Author : Takashi Kitajima
6
  * Created : October 7, 2014
7
+ * Modified : February 27, 2015
8
  * License : GPLv2
9
  * License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
  */
11
  class Smart_Custom_Fields_Field_Textarea extends Smart_Custom_Fields_Field_Base {
12
 
13
  /**
14
+ * 必須項目の設定
15
+ *
16
+ * @return array
17
  */
18
  protected function init() {
19
  return array(
20
+ 'type' => 'textarea',
21
+ 'display-name' => __( 'Textarea', 'smart-custom-fields' ),
22
+ 'optgroup' => 'basic-fields',
23
  );
24
  }
25
 
26
  /**
27
+ * 設定項目の設定
28
+ *
29
+ * @return array
30
+ */
31
+ protected function options() {
32
+ return array(
33
+ 'default' => '',
34
+ 'notes' => '',
35
+ );
36
+ }
37
+
38
+ /**
39
+ * 投稿画面にフィールドを表示
40
+ *
41
  * @param int $index インデックス番号
42
  * @param mixed $value 保存されている値(check のときだけ配列)
43
+ * @return string html
44
  */
45
+ public function get_field( $index, $value ) {
46
+ $name = $this->get_field_name_in_editor( $index );
47
  $disabled = $this->get_disable_attribute( $index );
48
  return sprintf(
49
  '<textarea name="%s" rows="5" class="widefat" %s>%s</textarea>',
54
  }
55
 
56
  /**
57
+ * 設定画面にフィールドを表示(オリジナル項目)
58
+ *
59
  * @param int $group_key
60
  * @param int $field_key
61
  */
65
  <th><?php esc_html_e( 'Default', 'smart-custom-fields' ); ?></th>
66
  <td>
67
  <textarea
68
+ name="<?php echo esc_attr( $this->get_field_name_in_setting( $group_key, $field_key, 'default' ) ); ?>"
69
  class="widefat"
70
+ rows="5"><?php echo esc_textarea( "\n" . $this->get( 'default' ) ); ?></textarea>
71
  </td>
72
  </tr>
73
  <tr>
74
  <th><?php esc_html_e( 'Notes', 'smart-custom-fields' ); ?></th>
75
  <td>
76
  <input type="text"
77
+ name="<?php echo esc_attr( $this->get_field_name_in_setting( $group_key, $field_key, 'notes' ) ); ?>"
78
  class="widefat"
79
+ value="<?php echo esc_attr( $this->get( 'notes' ) ); ?>"
80
  />
81
  </td>
82
  </tr>
83
  <?php
84
  }
85
+ }
classes/fields/class.field-wysiwyg.php CHANGED
@@ -1,47 +1,63 @@
1
  <?php
2
  /**
3
  * Smart_Custom_Fields_Field_Wysiwyg
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
  */
11
  class Smart_Custom_Fields_Field_Wysiwyg extends Smart_Custom_Fields_Field_Base {
12
 
13
  /**
14
- * init
15
- * @return array ( name, label, optgroup )
 
16
  */
17
  protected function init() {
18
- add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
 
 
 
19
  return array(
20
- 'name' => 'wysiwyg',
21
- 'label' => __( 'Wysiwyg', 'smart-custom-fields' ),
22
- 'optgroup' => 'content-fields',
23
  );
24
  }
25
 
26
  /**
27
- * admin_enqueue_scripts
28
- * @param string $hook
 
29
  */
30
- public function admin_enqueue_scripts( $hook ) {
31
- if ( in_array( $hook, array( 'post-new.php', 'post.php' ) ) ) {
32
- add_action( 'after_wp_tiny_mce', array( $this, 'after_wp_tiny_mce' ) );
33
- }
 
34
  }
35
 
 
 
 
 
 
 
 
 
 
 
36
  public function after_wp_tiny_mce() {
37
  printf(
38
  '<script type="text/javascript" src="%s"></script>',
39
- plugin_dir_url( __FILE__ ) . '../../js/editor-wysiwyg.js'
40
  );
41
  }
42
 
43
  /**
44
- * after_loaded
45
  */
46
  protected function after_loaded() {
47
  add_action( 'admin_footer', array( $this, 'admin_footer' ) );
@@ -55,13 +71,14 @@ class Smart_Custom_Fields_Field_Wysiwyg extends Smart_Custom_Fields_Field_Base {
55
  }
56
 
57
  /**
58
- * get_field
59
- * @param array $field フィールドの情報
60
  * @param int $index インデックス番号
61
  * @param mixed $value 保存されている値(check のときだけ配列)
 
62
  */
63
- public function get_field( $field, $index, $value ) {
64
- $name = $this->get_name_attribute( $field['name'], $index );
65
  $disabled = $this->get_disable_attribute( $index );
66
  return sprintf(
67
  '<div class="wp-editor-wrap">
@@ -78,7 +95,8 @@ class Smart_Custom_Fields_Field_Wysiwyg extends Smart_Custom_Fields_Field_Base {
78
  }
79
 
80
  /**
81
- * display_field_options
 
82
  * @param int $group_key
83
  * @param int $field_key
84
  */
@@ -88,24 +106,30 @@ class Smart_Custom_Fields_Field_Wysiwyg extends Smart_Custom_Fields_Field_Base {
88
  <th><?php esc_html_e( 'Default', 'smart-custom-fields' ); ?></th>
89
  <td>
90
  <textarea
91
- name="<?php echo esc_attr( $this->get_field_name( $group_key, $field_key, 'default' ) ); ?>"
92
  class="widefat"
93
- rows="5"><?php echo esc_textarea( "\n" . $this->get_field_value( 'default' ) ); ?></textarea>
94
  </td>
95
  </tr>
96
  <tr>
97
  <th><?php esc_html_e( 'Notes', 'smart-custom-fields' ); ?></th>
98
  <td>
99
  <input type="text"
100
- name="<?php echo esc_attr( $this->get_field_name( $group_key, $field_key, 'notes' ) ); ?>"
101
  class="widefat"
102
- value="<?php echo esc_attr( $this->get_field_value( 'notes' ) ); ?>"
103
  />
104
  </td>
105
  </tr>
106
  <?php
107
  }
108
 
 
 
 
 
 
 
109
  protected function media_buttons( $editor_id = 'content' ) {
110
  $img = '<span class="wp-media-buttons-icon"></span> ';
111
  return sprintf( '<a href="#" class="button insert-media add_media" data-editor="%s" title="%s">%s</a>',
@@ -114,4 +138,4 @@ class Smart_Custom_Fields_Field_Wysiwyg extends Smart_Custom_Fields_Field_Base {
114
  $img . __( 'Add Media' )
115
  );
116
  }
117
- }
1
  <?php
2
  /**
3
  * Smart_Custom_Fields_Field_Wysiwyg
4
+ * Version : 1.1.0
5
  * Author : Takashi Kitajima
6
  * Created : October 7, 2014
7
+ * Modified : February 27, 2015
8
  * License : GPLv2
9
  * License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
  */
11
  class Smart_Custom_Fields_Field_Wysiwyg extends Smart_Custom_Fields_Field_Base {
12
 
13
  /**
14
+ * 必須項目の設定
15
+ *
16
+ * @return array
17
  */
18
  protected function init() {
19
+ add_action(
20
+ SCF_Config::PREFIX . 'before-editor-enqueue-scripts',
21
+ array( $this, 'editor_enqueue_scripts' )
22
+ );
23
  return array(
24
+ 'type' => 'wysiwyg',
25
+ 'display-name' => __( 'Wysiwyg', 'smart-custom-fields' ),
26
+ 'optgroup' => 'content-fields',
27
  );
28
  }
29
 
30
  /**
31
+ * 設定項目の設定
32
+ *
33
+ * @return array
34
  */
35
+ protected function options() {
36
+ return array(
37
+ 'default' => '',
38
+ 'notes' => '',
39
+ );
40
  }
41
 
42
+ /**
43
+ * TinyMCE 読み込み後にオリジナルの JS を読み込み
44
+ */
45
+ public function editor_enqueue_scripts() {
46
+ add_action( 'after_wp_tiny_mce', array( $this, 'after_wp_tiny_mce' ) );
47
+ }
48
+
49
+ /**
50
+ * JS の読み込み
51
+ */
52
  public function after_wp_tiny_mce() {
53
  printf(
54
  '<script type="text/javascript" src="%s"></script>',
55
+ plugins_url( SCF_Config::NAME ) . '/js/editor-wysiwyg.js'
56
  );
57
  }
58
 
59
  /**
60
+ * フィールド初期化直後に実行する処理
61
  */
62
  protected function after_loaded() {
63
  add_action( 'admin_footer', array( $this, 'admin_footer' ) );
71
  }
72
 
73
  /**
74
+ * 投稿画面にフィールドを表示
75
+ *
76
  * @param int $index インデックス番号
77
  * @param mixed $value 保存されている値(check のときだけ配列)
78
+ * @return string html
79
  */
80
+ public function get_field( $index, $value ) {
81
+ $name = $this->get_field_name_in_editor( $index );
82
  $disabled = $this->get_disable_attribute( $index );
83
  return sprintf(
84
  '<div class="wp-editor-wrap">
95
  }
96
 
97
  /**
98
+ * 設定画面にフィールドを表示(オリジナル項目)
99
+ *
100
  * @param int $group_key
101
  * @param int $field_key
102
  */
106
  <th><?php esc_html_e( 'Default', 'smart-custom-fields' ); ?></th>
107
  <td>
108
  <textarea
109
+ name="<?php echo esc_attr( $this->get_field_name_in_setting( $group_key, $field_key, 'default' ) ); ?>"
110
  class="widefat"
111
+ rows="5"><?php echo esc_textarea( "\n" . $this->get( 'default' ) ); ?></textarea>
112
  </td>
113
  </tr>
114
  <tr>
115
  <th><?php esc_html_e( 'Notes', 'smart-custom-fields' ); ?></th>
116
  <td>
117
  <input type="text"
118
+ name="<?php echo esc_attr( $this->get_field_name_in_setting( $group_key, $field_key, 'notes' ) ); ?>"
119
  class="widefat"
120
+ value="<?php echo esc_attr( $this->get( 'notes' ) ); ?>"
121
  />
122
  </td>
123
  </tr>
124
  <?php
125
  }
126
 
127
+ /**
128
+ * メディアボタンを返す
129
+ *
130
+ * @param string $editor_id
131
+ * @return string
132
+ */
133
  protected function media_buttons( $editor_id = 'content' ) {
134
  $img = '<span class="wp-media-buttons-icon"></span> ';
135
  return sprintf( '<a href="#" class="button insert-media add_media" data-editor="%s" title="%s">%s</a>',
138
  $img . __( 'Add Media' )
139
  );
140
  }
141
+ }
classes/models/class.abstract-field-base.php ADDED
@@ -0,0 +1,241 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Smart_Custom_Fields_Field_Base
4
+ * Version : 1.1.0
5
+ * Author : Takashi Kitajima
6
+ * Created : October 7, 2014
7
+ * Modified : February 28, 2015
8
+ * License : GPLv2
9
+ * License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
+ */
11
+ abstract class Smart_Custom_Fields_Field_Base {
12
+
13
+ /**
14
+ * このフィールドの内部属性値
15
+ * @var array
16
+ */
17
+ protected $attributes = array(
18
+ 'type' => '', // eg. text
19
+ 'display-name' => '', // eg. Text
20
+ 'optgroup' => 'other-fields',
21
+ 'allow-multiple-data' => false,
22
+ );
23
+
24
+ /**
25
+ * このフィールドの設定項目
26
+ * @var array
27
+ */
28
+ protected $options = array(
29
+ 'name' => '', // name 属性
30
+ 'label' => '', // カスタムフィールド入力画面で表示するラベル
31
+ );
32
+
33
+ /**
34
+ * __construct
35
+ */
36
+ public function __construct() {
37
+ $attributes = array_merge( $this->attributes, $this->init() );
38
+ $options = array_merge( $this->options, $this->options() );
39
+ if ( empty( $attributes['type'] ) || empty( $attributes['display-name'] ) ) {
40
+ exit( 'This field object is invalid. Field object must have type and display-name attributes.' );
41
+ }
42
+ if ( empty( $attributes['optgroup'] ) ) {
43
+ $attributes['optgroup'] = 'basic-fields';
44
+ }
45
+ $this->attributes = $attributes;
46
+ $this->options = $options;
47
+ add_filter(
48
+ SCF_Config::PREFIX . 'field-select-' . $attributes['optgroup'],
49
+ array( $this, 'field_select' )
50
+ );
51
+ $this->after_loaded();
52
+
53
+ SCF::add_form_field_instance( $this );
54
+ }
55
+
56
+ /**
57
+ * 必須項目の設定
58
+ *
59
+ * @return array
60
+ */
61
+ abstract protected function init();
62
+
63
+ /**
64
+ * 設定項目の設定
65
+ *
66
+ * @return array
67
+ */
68
+ abstract protected function options();
69
+
70
+ /**
71
+ * フィールド初期化直後に実行する処理
72
+ */
73
+ protected function after_loaded() {
74
+ }
75
+
76
+ /**
77
+ * 投稿画面にフィールドを表示
78
+ *
79
+ * @param int $index インデックス番号
80
+ * @param mixed $value 保存されている値(check のときだけ配列)
81
+ * @return string html
82
+ */
83
+ abstract public function get_field( $index, $value );
84
+
85
+ /**
86
+ * 設定画面でこのフィールドのタイプ選択にこのフィールドのタイプを追加
87
+ *
88
+ * @param array $attributes その optgroup に属するフィールドのリスト
89
+ * @return array
90
+ */
91
+ public function field_select( $attributes ) {
92
+ $attributes[$this->get_attribute( 'type' )] = $this->get_attribute( 'display-name' );
93
+ return $attributes;
94
+ }
95
+
96
+ /**
97
+ * 設定画面にフィールドを表示(共通項目)
98
+ *
99
+ * @param int $group_key
100
+ * @param int $field_key
101
+ */
102
+ public function display_options( $group_key, $field_key ) {
103
+ ?>
104
+ <tr>
105
+ <th><?php esc_html_e( 'Name', 'smart-custom-fields' ); ?><span class="<?php echo esc_attr( SCF_Config::PREFIX . 'require' ); ?>">*</span></th>
106
+ <td>
107
+ <input type="text"
108
+ name="<?php echo esc_attr( $this->get_field_name_in_setting( $group_key, $field_key, 'name' ) ); ?>"
109
+ size="30"
110
+ class="<?php echo esc_attr( SCF_Config::PREFIX . 'field-name' ); ?>"
111
+ value="<?php echo esc_attr( $this->get( 'name' ) ); ?>"
112
+ />
113
+ </td>
114
+ </tr>
115
+ <tr>
116
+ <th><?php esc_html_e( 'Label', 'smart-custom-fields' ); ?></th>
117
+ <td>
118
+ <input type="text"
119
+ name="<?php echo esc_attr( $this->get_field_name_in_setting( $group_key, $field_key, 'label' ) ); ?>"
120
+ size="30"
121
+ class="<?php echo esc_attr( SCF_Config::PREFIX . 'field-label' ); ?>"
122
+ value="<?php echo esc_attr( $this->get( 'label' ) ); ?>"
123
+ />
124
+ </td>
125
+ </tr>
126
+ <?php
127
+ $fields = SCF::get_form_field_instances();
128
+ foreach ( $fields as $Field ) {
129
+ if ( $Field->get_attribute( 'type' ) === $this->get_attribute( 'type' ) ) {
130
+ foreach ( $this->options as $key => $value ) {
131
+ $Field->set( $key, $value );
132
+ }
133
+ }
134
+ $Field->_display_field_options( $group_key, $field_key );
135
+ }
136
+ }
137
+
138
+ /**
139
+ * 設定画面にフィールドを表示(オリジナル項目)
140
+ *
141
+ * @param int $group_key
142
+ * @param int $field_key
143
+ */
144
+ abstract protected function display_field_options( $group_key, $field_key );
145
+ public function _display_field_options( $group_key, $field_key ) {
146
+ ?>
147
+ <tr class="<?php echo esc_attr( SCF_Config::PREFIX . 'field-options' ); ?> <?php echo esc_attr( SCF_Config::PREFIX . 'field-options-' . $this->get_attribute( 'type' ) ); ?> hide">
148
+ <td colspan="2">
149
+ <table>
150
+ <?php $this->display_field_options( $group_key, $field_key ); ?>
151
+ </table>
152
+ </td>
153
+ </tr>
154
+ <?php
155
+ }
156
+
157
+ /**
158
+ * 投稿画面で表示するカスタムフィールドの name 属性値を返す
159
+ *
160
+ * @param string $name 定義されたフィールドの name
161
+ * @param string $index 添字
162
+ * @return string
163
+ */
164
+ protected function get_field_name_in_editor( $index ) {
165
+ return sprintf(
166
+ '%s[%s][%s]',
167
+ SCF_Config::NAME,
168
+ $this->get( 'name' ),
169
+ $index
170
+ );
171
+ }
172
+
173
+ /**
174
+ * 投稿画面で表示するカスタムフィールドを disabled にするかどうか
175
+ * $index が null 以外のときは全てユーザーが保存したデータなので null のときのみ true を返すこと
176
+ *
177
+ * @param string $index 添字
178
+ * @return bool $disabled
179
+ */
180
+ protected function get_disable_attribute( $index ) {
181
+ $disabled = false;
182
+ if ( is_null( $index ) ) {
183
+ $disabled = true;
184
+ }
185
+ return $disabled;
186
+ }
187
+
188
+ /**
189
+ * 設定画面で使用する name 属性値を返す
190
+ *
191
+ * @param int $group_key
192
+ * @param int $field_key
193
+ * @param string $name
194
+ * @return string
195
+ */
196
+ public function get_field_name_in_setting( $group_key, $field_key, $name ) {
197
+ return sprintf(
198
+ '%s[%d][fields][%d][%s]',
199
+ SCF_Config::NAME,
200
+ $group_key,
201
+ $field_key,
202
+ $name
203
+ );
204
+ }
205
+
206
+ /**
207
+ * 設定値を返す
208
+ *
209
+ * @param string $key 取得したいデータのキー
210
+ * @return mixed
211
+ */
212
+ public function get( $key ) {
213
+ if ( array_key_exists( $key, $this->options ) ) {
214
+ return $this->options[$key];
215
+ }
216
+ }
217
+
218
+ /**
219
+ * 設定値を設定
220
+ *
221
+ * @param string $key 取得したいデータのキー
222
+ * @param mixed $value 取得したいデータ
223
+ */
224
+ public function set( $key, $value ) {
225
+ if ( array_key_exists( $key, $this->options ) ) {
226
+ $this->options[$key] = $value;
227
+ }
228
+ }
229
+
230
+ /**
231
+ * 属性値を返す
232
+ *
233
+ * @param string $key 取得したいデータのキー
234
+ * @return mixed
235
+ */
236
+ public function get_attribute( $key ) {
237
+ if ( array_key_exists( $key, $this->attributes ) ) {
238
+ return $this->attributes[$key];
239
+ }
240
+ }
241
+ }
classes/models/class.group.php ADDED
@@ -0,0 +1,132 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Smart_Custom_Fields_Group
4
+ * Version : 1.0.0
5
+ * Author : Takashi Kitajima
6
+ * Created : September 23, 2014
7
+ * Modified : February 27, 2015
8
+ * License : GPLv2
9
+ * License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
+ */
11
+ class Smart_Custom_Fields_Group {
12
+
13
+ /**
14
+ * グループ名
15
+ * @var string
16
+ */
17
+ protected $name = null;
18
+
19
+ /**
20
+ * フィールドオブジェクトの配列
21
+ * @var array
22
+ */
23
+ protected $fields = array();
24
+
25
+ /**
26
+ * 繰り返しグループかどうか
27
+ * @var bool
28
+ */
29
+ protected $repeat = false;
30
+
31
+ /**
32
+ * __construct
33
+ *
34
+ * @param string $group_name グループ名
35
+ * @param bool $repeat 繰り返しグループかどうか
36
+ * @param array $_fields フィールドオブジェクトの配列
37
+ */
38
+ public function __construct( $group_name = null, $repeat = false, array $_fields = array() ) {
39
+ $this->name = $group_name;
40
+ $this->repeat = $repeat;
41
+ $fields = array();
42
+ foreach ( $_fields as $field_attributes ) {
43
+ $Field = SCF::get_form_field_instance( $field_attributes['type'] );
44
+ if ( !is_a( $Field, 'Smart_Custom_Fields_Field_Base' ) ) {
45
+ continue;
46
+ }
47
+ foreach ( $field_attributes as $key => $value ) {
48
+ $Field->set( $key, $value );
49
+ }
50
+
51
+ if ( !empty( $Field ) ) {
52
+ $fields[] = $Field;
53
+ }
54
+ }
55
+ $this->fields = $fields;
56
+ }
57
+
58
+ /**
59
+ * グループ名を返す
60
+ *
61
+ * @return string
62
+ */
63
+ public function get_name() {
64
+ if ( is_numeric( $this->name ) ) {
65
+ return;
66
+ }
67
+ return $this->name;
68
+ }
69
+
70
+ /**
71
+ * この設定ページに保存されている各フィールドを取得
72
+ *
73
+ * @return array
74
+ */
75
+ public function get_fields() {
76
+ return $this->fields;
77
+ }
78
+
79
+ /**
80
+ * 繰り返しグループかどうか
81
+ *
82
+ * @return bool
83
+ */
84
+ public function is_repeatable() {
85
+ return $this->repeat;
86
+ }
87
+
88
+ /**
89
+ * $key が空でなければ hide を表示
90
+ *
91
+ * @param string $key
92
+ */
93
+ private function add_hide_class( $key ) {
94
+ if ( !$key ) {
95
+ echo 'hide';
96
+ }
97
+ }
98
+
99
+ /**
100
+ * 設定画面にグループの共通設定を表示
101
+ *
102
+ * @param int $group_key
103
+ */
104
+ public function display_options( $group_key ) {
105
+ ?>
106
+ <div class="<?php echo esc_attr( SCF_Config::PREFIX . 'group-repeat' ); ?>">
107
+ <div class="<?php echo esc_attr( SCF_Config::PREFIX . 'icon-handle' ); ?>"></div>
108
+ <label>
109
+ <input type="checkbox"
110
+ name="<?php echo esc_attr( SCF_Config::NAME . '[' . $group_key . '][repeat]' ); ?>"
111
+ value="true"
112
+ <?php checked( $this->is_repeatable(), true ); ?>
113
+ />
114
+ <?php esc_html_e( 'Repeat', 'smart-custom-fields' ); ?>
115
+ </label>
116
+ </div>
117
+ <table class="<?php echo esc_attr( SCF_Config::PREFIX . 'group-names' ); ?> <?php $this->add_hide_class( $this->is_repeatable() ); ?>">
118
+ <tr>
119
+ <th><?php esc_html_e( 'Group name', 'smart-custom-fields' ); ?><span class="<?php echo esc_attr( SCF_Config::PREFIX . 'require' ); ?>">*</span></th>
120
+ <td>
121
+ <input type="text"
122
+ name="<?php echo esc_attr( SCF_Config::NAME . '[' . $group_key . '][group-name]' ); ?>"
123
+ size="30"
124
+ class="<?php echo esc_attr( SCF_Config::PREFIX . 'group-name' ); ?>"
125
+ value="<?php echo esc_attr( $this->get_name() ); ?>"
126
+ />
127
+ </td>
128
+ </tr>
129
+ </table>
130
+ <?php
131
+ }
132
+ }
classes/{class.revisions.php → models/class.revisions.php} RENAMED
@@ -1,10 +1,10 @@
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
  */
@@ -14,24 +14,28 @@ class Smart_Custom_Fields_Revisions {
14
  * __construct
15
  */
16
  public function __construct() {
17
- add_filter( 'get_post_metadata', array( $this, 'get_post_metadata' ), 10, 4 );
18
- add_action( 'wp_restore_post_revision', array( $this, 'wp_restore_post_revision' ), 10, 2 );
19
- add_action( 'wp_insert_post', array( $this, 'wp_insert_post' ) );
20
-
21
- // Always auto save when click preview button.
 
 
 
 
 
 
 
22
  add_filter( '_wp_post_revision_fields', array( $this, '_wp_post_revision_fields' ) );
23
- add_action( 'edit_form_after_title', array( $this, 'edit_form_after_title' ) );
24
-
25
- // Add custom fields preview in revision diff page.
26
- add_filter( '_wp_post_revision_field_' . SCF_Config::PREFIX . 'debug-preview', array( $this, '_wp_post_revision_field_debug_preview' ), 10, 3 );
27
-
28
- // Save revision when changing custom fields.
29
- add_filter( 'wp_save_post_revision_check_for_changes', array( $this, 'wp_save_post_revision_check_for_changes' ), 10, 3);
30
  }
31
 
32
  /**
33
- * wp_restore_post_revision
34
  * リビジョンから復元するときに呼び出される
 
35
  * @param int $post_id
36
  * @param int $revision_id
37
  */
@@ -41,17 +45,20 @@ class Smart_Custom_Fields_Revisions {
41
  $post_type = get_post_type();
42
 
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
  }
@@ -64,59 +71,76 @@ class Smart_Custom_Fields_Revisions {
64
  }
65
 
66
  /**
67
- * wp_insert_post
 
 
68
  * @param int $post_id
69
  */
70
  public function wp_insert_post( $post_id ) {
71
- if ( !isset( $_POST[SCF_Config::PREFIX . 'fields-nonce'] ) ) {
72
  return;
73
  }
74
- if ( !wp_verify_nonce( $_POST[SCF_Config::PREFIX . 'fields-nonce'], SCF_Config::NAME . '-fields' ) ) {
75
  return;
76
  }
77
- if ( !isset( $_POST[SCF_Config::NAME] ) ) {
 
78
  return;
79
  }
80
- if ( wp_is_post_revision( $post_id ) ) {
81
- // 繰り返しフィールドのチェックボックスは、普通のチェックボックスと混ざって
82
- // 判別できなくなるのでわかるように保存しておく
83
- $repeat_multiple_data = array();
84
-
85
- $post_type = get_post_type();
86
- $settings = SCF::get_settings( $post_type );
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
  }
103
  }
104
  }
105
  }
 
106
 
107
- delete_metadata( 'post', $post_id, SCF_Config::PREFIX . 'repeat-multiple-data' );
108
- if ( $repeat_multiple_data ) {
109
- update_metadata( 'post', $post_id, SCF_Config::PREFIX . 'repeat-multiple-data', $repeat_multiple_data );
110
- }
111
 
112
- foreach ( $_POST[SCF_Config::NAME] as $name => $values ) {
113
- foreach ( $values as $value ) {
114
- if ( !is_array( $value ) ) {
115
- add_metadata( 'post', $post_id, $name, $value );
116
- } else {
117
- foreach ( $value as $val ) {
118
- add_metadata( 'post', $post_id, $name, $val );
119
- }
 
120
  }
121
  }
122
  }
@@ -124,8 +148,8 @@ class Smart_Custom_Fields_Revisions {
124
  }
125
 
126
  /**
127
- * get_post_metadata
128
  * プレビューのときはプレビューのメタデータを返す
 
129
  * @param mixed $value
130
  * @param int $post_id
131
  * @param string $meta_key
@@ -142,7 +166,8 @@ class Smart_Custom_Fields_Revisions {
142
  }
143
 
144
  /**
145
- * get_preview_id
 
146
  * @param int $post_id
147
  * @return int $preview_id
148
  */
@@ -156,7 +181,8 @@ class Smart_Custom_Fields_Revisions {
156
  }
157
 
158
  /**
159
- * _wp_post_revision_fields
 
160
  * @param array $fields
161
  * @return array $fields
162
  */
@@ -166,7 +192,7 @@ class Smart_Custom_Fields_Revisions {
166
  }
167
 
168
  /**
169
- * edit_form_after_title
170
  */
171
  public function edit_form_after_title() {
172
  printf(
@@ -176,11 +202,11 @@ class Smart_Custom_Fields_Revisions {
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 ) {
@@ -211,12 +237,12 @@ class Smart_Custom_Fields_Revisions {
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();
@@ -230,8 +256,8 @@ class Smart_Custom_Fields_Revisions {
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
  }
1
  <?php
2
  /**
3
  * Smart_Custom_Fields_Revisions
4
+ * Version : 1.1.0
5
  * Author : Takashi Kitajima
6
  * Created : September 23, 2014
7
+ * Modified : February 27, 2015
8
  * License : GPLv2
9
  * License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
  */
14
  * __construct
15
  */
16
  public function __construct() {
17
+ add_filter(
18
+ '_wp_post_revision_field_' . SCF_Config::PREFIX . 'debug-preview',
19
+ array( $this, '_wp_post_revision_field_debug_preview' ),
20
+ 10,
21
+ 3
22
+ );
23
+ add_filter(
24
+ 'wp_save_post_revision_check_for_changes',
25
+ array( $this, 'wp_save_post_revision_check_for_changes' ),
26
+ 10,
27
+ 3
28
+ );
29
  add_filter( '_wp_post_revision_fields', array( $this, '_wp_post_revision_fields' ) );
30
+ add_filter( 'get_post_metadata' , array( $this, 'get_post_metadata' ), 10, 4 );
31
+ add_action( 'edit_form_after_title' , array( $this, 'edit_form_after_title' ) );
32
+ add_action( 'wp_restore_post_revision', array( $this, 'wp_restore_post_revision' ), 10, 2 );
33
+ add_action( 'wp_insert_post' , array( $this, 'wp_insert_post' ) );
 
 
 
34
  }
35
 
36
  /**
 
37
  * リビジョンから復元するときに呼び出される
38
+ *
39
  * @param int $post_id
40
  * @param int $revision_id
41
  */
45
  $post_type = get_post_type();
46
 
47
  $settings = SCF::get_settings( $post_type );
48
+ foreach ( $settings as $Setting ) {
49
+ $groups = $Setting->get_groups();
50
+ foreach ( $groups as $Group ) {
51
+ $fields = $Group->get_fields();
52
+ foreach ( $fields as $Field ) {
53
+ $field_name = $Field->get( 'name' );
54
+ delete_post_meta( $post->ID, $field_name );
55
+ $value = SCF::get( $field_name, $revision->ID );
56
  if ( is_array( $value ) ) {
57
  foreach ( $value as $val ) {
58
+ add_post_meta( $post->ID, $field_name, $val );
59
  }
60
  } else {
61
+ add_post_meta( $post->ID, $field_name, $value );
62
  }
63
  }
64
  }
71
  }
72
 
73
  /**
74
+ * リビジョンデータを保存
75
+ * *_post_meta はリビジョンIDのときに自動的に本物IDに変換して処理してしまうので、*_metadata を使うこと
76
+ *
77
  * @param int $post_id
78
  */
79
  public function wp_insert_post( $post_id ) {
80
+ if ( !isset( $_POST[SCF_Config::NAME] ) ) {
81
  return;
82
  }
83
+ if ( !wp_is_post_revision( $post_id ) ) {
84
  return;
85
  }
86
+ $settings = SCF::get_settings( get_post_type() );
87
+ if ( !$settings ) {
88
  return;
89
  }
90
+
91
+ check_admin_referer(
92
+ SCF_Config::NAME . '-fields',
93
+ SCF_Config::PREFIX . 'fields-nonce'
94
+ );
95
+
96
+ // 繰り返しフィールドのチェックボックスは、普通のチェックボックスと混ざって
97
+ // 判別できなくなるのでわかるように保存しておく
98
+ $repeat_multiple_data = array();
99
+
100
+ // チェックボックスが未入力のときは "" がくるので、それは保存しないように判別
101
+ $multiple_data_fields = array();
102
+
103
+ $post_type = get_post_type();
104
+ $settings = SCF::get_settings( $post_type );
105
+ foreach ( $settings as $Setting ) {
106
+ $groups = $Setting->get_groups();
107
+ foreach ( $groups as $Group ) {
108
+ $fields = $Group->get_fields();
109
+ foreach ( $fields as $Field ) {
110
+ $field_name = $Field->get( 'name' );
111
+ delete_metadata( 'post', $post_id, $field_name );
112
+ if ( $Field->get_attribute( 'allow-multiple-data' ) ) {
113
+ $multiple_data_fields[] = $field_name;
114
+ }
115
+
116
+ if ( $Group->is_repeatable() && $Field->get_attribute( 'allow-multiple-data' ) ) {
117
+ $repeat_multiple_data_fields = $_POST[SCF_Config::NAME][$field_name];
118
+ foreach ( $repeat_multiple_data_fields as $values ) {
119
+ if ( is_array( $values ) ) {
120
+ $repeat_multiple_data[$field_name][] = count( $values );
121
+ } else {
122
+ $repeat_multiple_data[$field_name][] = 0;
123
  }
124
  }
125
  }
126
  }
127
  }
128
+ }
129
 
130
+ delete_metadata( 'post', $post_id, SCF_Config::PREFIX . 'repeat-multiple-data' );
131
+ if ( $repeat_multiple_data ) {
132
+ update_metadata( 'post', $post_id, SCF_Config::PREFIX . 'repeat-multiple-data', $repeat_multiple_data );
133
+ }
134
 
135
+ foreach ( $_POST[SCF_Config::NAME] as $name => $values ) {
136
+ foreach ( $values as $value ) {
137
+ if ( in_array( $name, $multiple_data_fields ) && $value === '' )
138
+ continue;
139
+ if ( !is_array( $value ) ) {
140
+ add_metadata( 'post', $post_id, $name, $value );
141
+ } else {
142
+ foreach ( $value as $val ) {
143
+ add_metadata( 'post', $post_id, $name, $val );
144
  }
145
  }
146
  }
148
  }
149
 
150
  /**
 
151
  * プレビューのときはプレビューのメタデータを返す
152
+ *
153
  * @param mixed $value
154
  * @param int $post_id
155
  * @param string $meta_key
166
  }
167
 
168
  /**
169
+ * プレビューの Post ID を返す
170
+ *
171
  * @param int $post_id
172
  * @return int $preview_id
173
  */
181
  }
182
 
183
  /**
184
+ * リビジョン比較画面でメタデータを表示させるためにキーを追加する
185
+ *
186
  * @param array $fields
187
  * @return array $fields
188
  */
192
  }
193
 
194
  /**
195
+ * プレビュー時にメタデータを保存するためにキーとなる項目を出力する
196
  */
197
  public function edit_form_after_title() {
198
  printf(
202
  }
203
 
204
  /**
205
+ * リビジョン比較画面にメタデータを表示
206
+ *
207
+ * @param $value
208
+ * @param $column
209
+ * @param array $post
210
  * @return string
211
  */
212
  public function _wp_post_revision_field_debug_preview( $value, $column, $post ) {
237
  }
238
 
239
  /**
240
+ * false ならリビジョンとして保存される
241
+ *
242
  * @param bool $check_for_changes
243
+ * @param WP_Post $last_revision 最新のリビジョン
244
+ * @param WP_Post $post 現在の投稿
245
+ * @return bool
246
  */
247
  public function wp_save_post_revision_check_for_changes( $check_for_changes, $last_revision, $post ) {
248
  $post_meta = array();
256
 
257
  if ( isset( $_POST[SCF_Config::NAME] ) ) {
258
  $serialized_post_meta = serialize( $post_meta );
259
+ $serialized_send_data = $_POST[SCF_Config::NAME];
260
+ if ( $serialized_post_meta != $serialized_send_data ) {
261
  return false;
262
  }
263
  }
classes/models/class.setting.php ADDED
@@ -0,0 +1,121 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Smart_Custom_Fields_Setting
4
+ * Version : 1.0.0
5
+ * Author : Takashi Kitajima
6
+ * Created : September 23, 2014
7
+ * Modified : February 27, 2015
8
+ * License : GPLv2
9
+ * License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
+ */
11
+ class Smart_Custom_Fields_Setting {
12
+
13
+ /**
14
+ * カスタムフィールド設定の Post ID
15
+ * @var string
16
+ */
17
+ protected $id;
18
+
19
+ /**
20
+ * カスタムフィールド設定のタイトル
21
+ * @var title
22
+ */
23
+ protected $title;
24
+
25
+ /**
26
+ * 保存されているグループオブジェクトの配列
27
+ * @var array
28
+ */
29
+ protected $groups = array();
30
+
31
+ /**
32
+ * __construct
33
+ *
34
+ * @param int $post_id
35
+ */
36
+ public function __construct( $id, $title ) {
37
+ $this->id = $id;
38
+ $this->title = $title;
39
+ $post_meta = get_post_meta(
40
+ $this->get_id(),
41
+ SCF_Config::PREFIX . 'setting',
42
+ true
43
+ );
44
+ if ( is_array( $post_meta ) ) {
45
+ foreach ( $post_meta as $group ) {
46
+ $group = shortcode_atts( array(
47
+ 'group-name' => '',
48
+ 'repeat' => false,
49
+ 'fields' => array(),
50
+ ), $group );
51
+ $this->add_group(
52
+ $group['group-name'],
53
+ $group['repeat'],
54
+ $group['fields']
55
+ );
56
+ }
57
+ }
58
+ }
59
+
60
+ /**
61
+ * Post ID を取得
62
+ *
63
+ * @return string
64
+ */
65
+ public function get_id() {
66
+ return $this->id;
67
+ }
68
+
69
+ /**
70
+ * post_title を取得
71
+ *
72
+ * @return string
73
+ */
74
+ public function get_title() {
75
+ return $this->title;
76
+ }
77
+
78
+ /**
79
+ * この設定ページに保存されている各グループを取得
80
+ *
81
+ * @return array
82
+ */
83
+ public function get_groups() {
84
+ return $this->groups;
85
+ }
86
+
87
+ /**
88
+ * グループを最後に追加。引数なしで空のグループを追加
89
+ *
90
+ * @param string グループ名
91
+ * @param bool 繰り返し可能かどうか
92
+ * @param array $_fields フィールドオブジェクトの配列
93
+ */
94
+ public function add_group( $group_name = null, $repeat = false, array $fields = array() ) {
95
+ $Group = $this->new_group( $group_name, $repeat, $fields );
96
+ $this->groups[] = $Group;
97
+ }
98
+
99
+ /**
100
+ * グループを先頭に追加。引数なしで空のグループを追加
101
+ *
102
+ * @param string グループ名
103
+ * @param bool 繰り返し可能かどうか
104
+ * @param array $_fields フィールドオブジェクトの配列
105
+ */
106
+ public function add_group_unshift( $group_name = null, $repeat = false, array $fields = array() ) {
107
+ $Group = $this->new_group( $group_name, $repeat, $fields );
108
+ array_unshift( $this->groups, $Group );
109
+ }
110
+
111
+ /**
112
+ * グループを生成して返す
113
+ *
114
+ * @param string グループ名
115
+ * @param bool 繰り返し可能かどうか
116
+ * @param array $_fields フィールドオブジェクトの配列
117
+ */
118
+ protected function new_group( $group_name, $repeat, $fields ) {
119
+ return new Smart_Custom_Fields_Group( $group_name, $repeat, $fields );
120
+ }
121
+ }
css/editor.css CHANGED
@@ -50,8 +50,32 @@
50
  /** ==================================================
51
  * .smart-cf-meta-box-repeat-tables
52
  */
53
- .smart-cf-meta-box-repeat-tables .smart-cf-meta-box-table > .smart-cf-icon-handle {
54
- top: 5px;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
55
  }
56
 
57
  /** ==================================================
@@ -158,12 +182,10 @@
158
  * classes
159
  */
160
  .smart-cf-icon-handle {
161
- background: url( ../images/handle.png ) no-repeat;
162
  cursor: move;
163
  display: inline-block;
164
  margin-right: 10px;
165
- height: 10px;
166
- width: 10px;
167
  overflow: hidden;
168
  position: relative;
169
- }
 
50
  /** ==================================================
51
  * .smart-cf-meta-box-repeat-tables
52
  */
53
+ .smart-cf-meta-box-repeat-tables .smart-cf-meta-box-table > .smart-cf-icon-handle,
54
+ .smart-cf-meta-box-repeat-tables .smart-cf-meta-box-table > .smart-cf-repeat-btn {
55
+ position: relative;
56
+ top: 3px;
57
+ vertical-align: middle;
58
+ }
59
+ .smart-cf-meta-box-repeat-tables .smart-cf-repeat-btn {
60
+ cursor: pointer;
61
+ width: auto;
62
+ height: auto;
63
+ font-size: 1.3em;
64
+ padding: 0;
65
+ -webkit-border-radius: 50%;
66
+ border-radius: 50%;
67
+ display: inline-block;
68
+ vertical-align: middle;
69
+ text-align: center;
70
+ color: #999;
71
+ margin-right: 3px;
72
+ }
73
+ .smart-cf-meta-box-repeat-tables .smart-cf-icon-handle:hover,
74
+ .smart-cf-meta-box-repeat-tables .smart-cf-repeat-btn:hover {
75
+ color: #333;
76
+ }
77
+ .smart-cf-meta-box-repeat-tables table {
78
+ margin-top: 7px;
79
  }
80
 
81
  /** ==================================================
182
  * classes
183
  */
184
  .smart-cf-icon-handle {
 
185
  cursor: move;
186
  display: inline-block;
187
  margin-right: 10px;
 
 
188
  overflow: hidden;
189
  position: relative;
190
+ color: #CCC;
191
+ }
css/settings.css CHANGED
@@ -1,9 +1,9 @@
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,9 +48,15 @@
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,9 +69,12 @@
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,6 +97,13 @@
88
  margin-top: 2px 0;
89
  }
90
 
 
 
 
 
 
 
 
91
  /** ==================================================
92
  * .smart-cf-field
93
  */
@@ -96,6 +112,8 @@
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,17 +138,37 @@
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,3 +193,17 @@
155
  .smart-cf-group .smart-cf-field table.hide {
156
  display: none;
157
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
  .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
  * .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
  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
  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
  }
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
  .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
+ }
js/editor-colorpicker.js CHANGED
@@ -1,5 +1,5 @@
1
  /**
2
- * colorpicker.js
3
  * Version : 1.0.0
4
  * Author : Takashi Kitajima
5
  * Created : October 21, 2014
1
  /**
2
+ * editor-colorpicker.js
3
  * Version : 1.0.0
4
  * Author : Takashi Kitajima
5
  * Created : October 21, 2014
js/editor-datepicker.js CHANGED
@@ -1,5 +1,5 @@
1
  /**
2
- * datepicker.js
3
  * Version : 1.0.0
4
  * Author : Takashi Kitajima
5
  * Created : January 18, 2015
1
  /**
2
+ * editor-datepicker.js
3
  * Version : 1.0.0
4
  * Author : Takashi Kitajima
5
  * Created : January 18, 2015
js/editor.js CHANGED
@@ -1,9 +1,9 @@
1
  /**
2
  * editor.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
  */
@@ -62,8 +62,8 @@ jQuery( function( $ ) {
62
  if ( name ) {
63
  $( this ).attr( 'name',
64
  name.replace(
65
- /^(smart-custom-fields\[.+\])\[_\]/,
66
- '$1[_' + cnt + ']'
67
  )
68
  );
69
  $( this ).removeAttr( 'disabled' );
1
  /**
2
  * editor.js
3
+ * Version : 1.0.1
4
  * Author : Takashi Kitajima
5
  * Created : September 23, 2014
6
+ * Modified : February 27, 2015
7
  * License : GPLv2
8
  * License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
  */
62
  if ( name ) {
63
  $( this ).attr( 'name',
64
  name.replace(
65
+ /^(smart-custom-fields\[.+?\])\[\]/,
66
+ '$1[' + cnt + ']'
67
  )
68
  );
69
  $( this ).removeAttr( 'disabled' );
js/settings-colorpicker.js ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * settings-colorpicker.js
3
+ * Version : 1.0.0
4
+ * Author : Takashi Kitajima
5
+ * Created : March 10, 2014
6
+ * Modified :
7
+ * License : GPLv2
8
+ * License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
+ */
10
+ jQuery( function( $ ) {
11
+ $( document ).on( 'smart-cf-setting-field-open', function( e, options ) {
12
+ if ( $( options ).hasClass( 'smart-cf-field-options-colorpicker' ) ) {
13
+ $( options ).find( '.default-option' ).each( function( i, e ) {
14
+ $( e ).wpColorPicker();
15
+ } );
16
+ }
17
+ } );
18
+ $( document ).on( 'smart-cf-setting-show-options', function( e, options ) {
19
+ if ( $( options ).hasClass( 'smart-cf-field-options-colorpicker' ) ) {
20
+ $( options ).find( '.default-option' ).each( function( i, e ) {
21
+ $( e ).wpColorPicker();
22
+ } );
23
+ }
24
+ } );
25
+ } );
js/settings-datepicker.js ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * settings-datepicker.js
3
+ * Version : 1.0.0
4
+ * Author : Takashi Kitajima
5
+ * Created : March 10, 2015
6
+ * Modified :
7
+ * License : GPLv2
8
+ * License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
+ */
10
+ jQuery( function( $ ) {
11
+ $( document ).on( 'smart-cf-setting-field-open', function( e, options ) {
12
+ if ( $( options ).hasClass( 'smart-cf-field-options-datepicker' ) ) {
13
+ $( options ).find( '.default-option' ).each( function( i, e ) {
14
+ $( e ).datepicker( $( e ).data( 'js' ) );
15
+ } );
16
+ }
17
+ } );
18
+ $( document ).on( 'smart-cf-setting-show-options', function( e, options ) {
19
+ if ( $( options ).hasClass( 'smart-cf-field-options-datepicker' ) ) {
20
+ $( options ).find( '.default-option' ).each( function( i, e ) {
21
+ $( e ).datepicker( $( e ).data( 'js' ) );
22
+ } );
23
+ }
24
+ } );
25
+ } );
js/settings.js CHANGED
@@ -1,9 +1,9 @@
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
  */
@@ -11,9 +11,9 @@ jQuery( function( $ ) {
11
  $( '.smart-cf-fields-wrapper' ).each( function( i, e ) {
12
  var wrapper = $( e );
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,23 +56,26 @@ jQuery( function( $ ) {
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
  } );
77
  } else {
78
  var label = table.find( '.smart-cf-field-label' ).val();
@@ -81,7 +84,11 @@ jQuery( function( $ ) {
81
  }
82
  table.fadeOut( 'fast', function() {
83
  $( this ).addClass( 'hide' );
84
- btn_remove_field_slide.find( 'span' ).text( label );
 
 
 
 
85
  } );
86
  }
87
  } );
@@ -182,6 +189,7 @@ jQuery( function( $ ) {
182
  var show_options = field.find( '.smart-cf-field-options-' + val );
183
  show_options.find( 'input, textarea, select' ).removeAttr( 'disabled' );
184
  show_options.removeClass( 'hide' );
 
185
  } );
186
 
187
  /**
1
  /**
2
  * settings.js
3
+ * Version : 1.1.0
4
  * Author : Takashi Kitajima
5
  * Created : September 23, 2014
6
+ * Modified : March 10, 2015
7
  * License : GPLv2
8
  * License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
  */
11
  $( '.smart-cf-fields-wrapper' ).each( function( i, e ) {
12
  var wrapper = $( e );
13
  var btn_add_group = wrapper.find( '.btn-add-group' );
14
+ var btn_remove_group = wrapper.find( '.btn-remove-group' );
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
  */
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
+ table.find( '.smart-cf-field-options' ).each( function( i, e ) {
77
+ $( this ).trigger( 'smart-cf-setting-field-open', e );
78
+ } );
79
  } );
80
  } else {
81
  var label = table.find( '.smart-cf-field-label' ).val();
84
  }
85
  table.fadeOut( 'fast', function() {
86
  $( this ).addClass( 'hide' );
87
+ if ( label ) {
88
+ field_label.text( label );
89
+ } else {
90
+ field_label.html( "&nbsp;" );
91
+ }
92
  } );
93
  }
94
  } );
189
  var show_options = field.find( '.smart-cf-field-options-' + val );
190
  show_options.find( 'input, textarea, select' ).removeAttr( 'disabled' );
191
  show_options.removeClass( 'hide' );
192
+ show_options.trigger( 'smart-cf-setting-show-options', show_options );
193
  } );
194
 
195
  /**
languages/smart-custom-fields-ja.mo ADDED
Binary file
languages/smart-custom-fields-ja.po ADDED
@@ -0,0 +1,268 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright (C) 2015 Smart Custom Fields
2
+ # This file is distributed under the same license as the Smart Custom Fields package.
3
+ msgid ""
4
+ msgstr ""
5
+ "Project-Id-Version: Smart Custom Fields 1.2.0\n"
6
+ "Report-Msgid-Bugs-To: http://wordpress.org/tag/smart-custom-fields\n"
7
+ "POT-Creation-Date: 2015-02-27 16:55:57+00:00\n"
8
+ "PO-Revision-Date: 2015-02-28 02:04+0900\n"
9
+ "Last-Translator: Takashi Kitajima <inc@2inc.org>\n"
10
+ "Language-Team: \n"
11
+ "Language: ja\n"
12
+ "MIME-Version: 1.0\n"
13
+ "Content-Type: text/plain; charset=UTF-8\n"
14
+ "Content-Transfer-Encoding: 8bit\n"
15
+ "X-Generator: Poedit 1.7.4\n"
16
+ "Plural-Forms: nplurals=1; plural=0;\n"
17
+ "X-Poedit-KeywordsList: __;_e\n"
18
+ "X-Poedit-Basepath: .\n"
19
+ "X-Poedit-SearchPath-0: ..\n"
20
+
21
+ #: classes/controller/class.editor.php:53
22
+ msgid "Image setting"
23
+ msgstr "画像設定"
24
+
25
+ #: classes/controller/class.editor.php:54
26
+ msgid "File setting"
27
+ msgstr "ファイル設定"
28
+
29
+ #: classes/controller/class.settings.php:29
30
+ msgid "Basic fields"
31
+ msgstr "基本フィールド"
32
+
33
+ #: classes/controller/class.settings.php:33
34
+ msgid "Select fields"
35
+ msgstr "選択フィールド"
36
+
37
+ #: classes/controller/class.settings.php:37
38
+ msgid "Content fields"
39
+ msgstr "コンテンツフィールド"
40
+
41
+ #: classes/controller/class.settings.php:41
42
+ msgid "Other fields"
43
+ msgstr "その他のフィールド"
44
+
45
+ #: classes/controller/class.settings.php:63
46
+ msgid "Same name exists!"
47
+ msgstr "同じ名前が存在します!"
48
+
49
+ #: classes/controller/class.settings.php:74
50
+ msgid "Custom Fields"
51
+ msgstr "カスタムフィールド"
52
+
53
+ #: classes/controller/class.settings.php:80
54
+ msgid "Display conditions"
55
+ msgstr "表示条件"
56
+
57
+ #: classes/controller/class.settings.php:134
58
+ msgid "Type"
59
+ msgstr "タイプ"
60
+
61
+ #: classes/controller/class.settings.php:169
62
+ msgid "Add Sub field"
63
+ msgstr "サブフィールドを追加"
64
+
65
+ #: classes/controller/class.settings.php:173
66
+ msgid "Add Field"
67
+ msgstr "フィールド追加"
68
+
69
+ #: classes/controller/class.settings.php:203
70
+ #: classes/fields/class.field-relation.php:178
71
+ msgid "Post Types"
72
+ msgstr "投稿タイプ"
73
+
74
+ #: classes/controller/class.settings.php:210
75
+ msgid "Post Ids ( Comma separated )"
76
+ msgstr "投稿 ID (カンマ区切り)"
77
+
78
+ #: classes/fields/class.field-check.php:19
79
+ msgid "Check"
80
+ msgstr "チェックボックス"
81
+
82
+ #: classes/fields/class.field-check.php:74
83
+ #: classes/fields/class.field-radio.php:72
84
+ #: classes/fields/class.field-select.php:69
85
+ msgid "Choices"
86
+ msgstr "選択肢"
87
+
88
+ #: classes/fields/class.field-check.php:83
89
+ #: classes/fields/class.field-colorpicker.php:78
90
+ #: classes/fields/class.field-datepicker.php:128
91
+ #: classes/fields/class.field-radio.php:81
92
+ #: classes/fields/class.field-select.php:78
93
+ #: classes/fields/class.field-text.php:58
94
+ #: classes/fields/class.field-textarea.php:58
95
+ #: classes/fields/class.field-wysiwyg.php:96
96
+ msgid "Default"
97
+ msgstr "デフォルト"
98
+
99
+ #: classes/fields/class.field-check.php:92
100
+ #: classes/fields/class.field-colorpicker.php:87
101
+ #: classes/fields/class.field-datepicker.php:191
102
+ #: classes/fields/class.field-file.php:85
103
+ #: classes/fields/class.field-image.php:84
104
+ #: classes/fields/class.field-radio.php:90
105
+ #: classes/fields/class.field-relation.php:199
106
+ #: classes/fields/class.field-select.php:87
107
+ #: classes/fields/class.field-text.php:67
108
+ #: classes/fields/class.field-textarea.php:67
109
+ #: classes/fields/class.field-wysiwyg.php:105
110
+ msgid "Notes"
111
+ msgstr "注記"
112
+
113
+ #: classes/fields/class.field-colorpicker.php:20
114
+ msgid "Color picker"
115
+ msgstr "カラーピッカー"
116
+
117
+ #: classes/fields/class.field-datepicker.php:20
118
+ msgid "Date picker"
119
+ msgstr "日付ピッカー"
120
+
121
+ #: classes/fields/class.field-datepicker.php:137
122
+ msgid "Date Format"
123
+ msgstr "日付のフォーマット"
124
+
125
+ #: classes/fields/class.field-datepicker.php:145
126
+ msgid "e.g dd/mm/yy"
127
+ msgstr "例: dd/mm/yy"
128
+
129
+ #: classes/fields/class.field-datepicker.php:155
130
+ msgid "Max Date"
131
+ msgstr "最大日付"
132
+
133
+ #: classes/fields/class.field-datepicker.php:163
134
+ #: classes/fields/class.field-datepicker.php:181
135
+ msgid "e.g +1m +1w"
136
+ msgstr "例: +1m +1w"
137
+
138
+ #: classes/fields/class.field-datepicker.php:173
139
+ msgid "Min Date"
140
+ msgstr "最小日付"
141
+
142
+ #: classes/fields/class.field-file.php:19
143
+ msgid "File"
144
+ msgstr "ファイル"
145
+
146
+ #: classes/fields/class.field-file.php:44
147
+ #: classes/fields/class.field-image.php:44
148
+ msgid "Delete"
149
+ msgstr "削除"
150
+
151
+ #: classes/fields/class.field-file.php:67
152
+ msgid "File Select"
153
+ msgstr "ファイル選択"
154
+
155
+ #: classes/fields/class.field-image.php:19
156
+ msgid "Image"
157
+ msgstr "画像"
158
+
159
+ #: classes/fields/class.field-image.php:66
160
+ msgid "Image Select"
161
+ msgstr "画像選択"
162
+
163
+ #: classes/fields/class.field-radio.php:19
164
+ msgid "Radio"
165
+ msgstr "ラジオボタン"
166
+
167
+ #: classes/fields/class.field-relation.php:21
168
+ msgid "Relation"
169
+ msgstr "リレーション"
170
+
171
+ #: classes/fields/class.field-relation.php:161
172
+ msgid "Load more"
173
+ msgstr "さらに読み込む"
174
+
175
+ #: classes/fields/class.field-select.php:19
176
+ msgid "Select"
177
+ msgstr "セレクトボックス"
178
+
179
+ #: classes/fields/class.field-text.php:19
180
+ msgid "Text"
181
+ msgstr "テキスト"
182
+
183
+ #: classes/fields/class.field-textarea.php:19
184
+ msgid "Textarea"
185
+ msgstr "テキストエリア"
186
+
187
+ #: classes/fields/class.field-wysiwyg.php:20
188
+ msgid "Wysiwyg"
189
+ msgstr "WYSIWYG"
190
+
191
+ #: classes/fields/class.field-wysiwyg.php:121
192
+ #: classes/fields/class.field-wysiwyg.php:122
193
+ msgid "Add Media"
194
+ msgstr "メディアを追加"
195
+
196
+ #: classes/models/class.abstract-field-base.php:105
197
+ msgid "Name"
198
+ msgstr "名前"
199
+
200
+ #: classes/models/class.abstract-field-base.php:116
201
+ msgid "Label"
202
+ msgstr "ラベル"
203
+
204
+ #: classes/models/class.group.php:114
205
+ msgid "Repeat"
206
+ msgstr "繰り返し"
207
+
208
+ #: classes/models/class.group.php:119
209
+ msgid "Group name"
210
+ msgstr "グループ名"
211
+
212
+ #: classes/models/class.revisions.php:190 smart-custom-fields.php:102
213
+ #: smart-custom-fields.php:103 smart-custom-fields.php:104
214
+ msgid "Smart Custom Fields"
215
+ msgstr "Smart Custom Fields"
216
+
217
+ #: smart-custom-fields.php:105 smart-custom-fields.php:106
218
+ #: smart-custom-fields.php:145 smart-custom-fields.php:146
219
+ msgid "Add New"
220
+ msgstr "新規追加"
221
+
222
+ #: smart-custom-fields.php:107
223
+ msgid "New Field"
224
+ msgstr "新規フィールド"
225
+
226
+ #: smart-custom-fields.php:108
227
+ msgid "Edit Field"
228
+ msgstr "フィールド編集"
229
+
230
+ #: smart-custom-fields.php:109
231
+ msgid "View Field"
232
+ msgstr "フィールドを表示"
233
+
234
+ #: smart-custom-fields.php:110
235
+ msgid "All Fields"
236
+ msgstr "すべてのフィールド"
237
+
238
+ #: smart-custom-fields.php:111
239
+ msgid "Search Fields"
240
+ msgstr "フィールドを検索"
241
+
242
+ #: smart-custom-fields.php:112
243
+ msgid "Parent Fields:"
244
+ msgstr "親フィールド:"
245
+
246
+ #: smart-custom-fields.php:113
247
+ msgid "No Fields found."
248
+ msgstr "フィールドは見つかりませんでした。"
249
+
250
+ #: smart-custom-fields.php:114
251
+ msgid "No Fields found in Trash."
252
+ msgstr "ゴミ箱にフィールドは見つかりませんでした"
253
+
254
+ #. Plugin URI of the plugin/theme
255
+ msgid "https://github.com/inc2734/smart-custom-fields/"
256
+ msgstr "https://github.com/inc2734/smart-custom-fields/"
257
+
258
+ #. Description of the plugin/theme
259
+ msgid "Smart Custom Fields is a simple plugin that management custom fields."
260
+ msgstr "Smart Custom Fields はカスタムフィールドを管理するシンプルなプラグインです。"
261
+
262
+ #. Author of the plugin/theme
263
+ msgid "Takashi Kitajima"
264
+ msgstr "Takashi Kitajima"
265
+
266
+ #. Author URI of the plugin/theme
267
+ msgid "http://2inc.org"
268
+ msgstr "http://2inc.org"
languages/smart-custom-fields.pot ADDED
@@ -0,0 +1,268 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright (C) 2015 Smart Custom Fields
2
+ # This file is distributed under the same license as the Smart Custom Fields package.
3
+ msgid ""
4
+ msgstr ""
5
+ "Project-Id-Version: Smart Custom Fields 1.2.0\n"
6
+ "Report-Msgid-Bugs-To: http://wordpress.org/tag/smart-custom-fields\n"
7
+ "POT-Creation-Date: 2015-02-27 16:55:57+00:00\n"
8
+ "MIME-Version: 1.0\n"
9
+ "Content-Type: text/plain; charset=UTF-8\n"
10
+ "Content-Transfer-Encoding: 8bit\n"
11
+ "PO-Revision-Date: 2015-MO-DA HO:MI+ZONE\n"
12
+ "Last-Translator: Takashi Kitajima <inc@2inc.org>\n"
13
+ "Language-Team: Takashi Kitajima <inc@2inc.org>\n"
14
+ "Plural-Forms: nplurals=1; plural=0;\n"
15
+ "X-Poedit-SourceCharset: UTF-8\n"
16
+ "X-Poedit-Basepath: .\n"
17
+ "X-Generator: Poedit 1.7.4\n"
18
+ "X-Poedit-KeywordsList: __;_e\n"
19
+ "X-Poedit-SearchPath-0: ..\n"
20
+
21
+ #: classes/controller/class.editor.php:53
22
+ msgid "Image setting"
23
+ msgstr ""
24
+
25
+ #: classes/controller/class.editor.php:54
26
+ msgid "File setting"
27
+ msgstr ""
28
+
29
+ #: classes/controller/class.settings.php:29
30
+ msgid "Basic fields"
31
+ msgstr ""
32
+
33
+ #: classes/controller/class.settings.php:33
34
+ msgid "Select fields"
35
+ msgstr ""
36
+
37
+ #: classes/controller/class.settings.php:37
38
+ msgid "Content fields"
39
+ msgstr ""
40
+
41
+ #: classes/controller/class.settings.php:41
42
+ msgid "Other fields"
43
+ msgstr ""
44
+
45
+ #: classes/controller/class.settings.php:63
46
+ msgid "Same name exists!"
47
+ msgstr ""
48
+
49
+ #: classes/controller/class.settings.php:74
50
+ msgid "Custom Fields"
51
+ msgstr ""
52
+
53
+ #: classes/controller/class.settings.php:80
54
+ msgid "Display conditions"
55
+ msgstr ""
56
+
57
+ #: classes/controller/class.settings.php:134
58
+ msgid "Type"
59
+ msgstr ""
60
+
61
+ #: classes/controller/class.settings.php:169
62
+ msgid "Add Sub field"
63
+ msgstr ""
64
+
65
+ #: classes/controller/class.settings.php:173
66
+ msgid "Add Field"
67
+ msgstr ""
68
+
69
+ #: classes/controller/class.settings.php:203
70
+ #: classes/fields/class.field-relation.php:178
71
+ msgid "Post Types"
72
+ msgstr ""
73
+
74
+ #: classes/controller/class.settings.php:210
75
+ msgid "Post Ids ( Comma separated )"
76
+ msgstr ""
77
+
78
+ #: classes/fields/class.field-check.php:19
79
+ msgid "Check"
80
+ msgstr ""
81
+
82
+ #: classes/fields/class.field-check.php:74
83
+ #: classes/fields/class.field-radio.php:72
84
+ #: classes/fields/class.field-select.php:69
85
+ msgid "Choices"
86
+ msgstr ""
87
+
88
+ #: classes/fields/class.field-check.php:83
89
+ #: classes/fields/class.field-colorpicker.php:78
90
+ #: classes/fields/class.field-datepicker.php:128
91
+ #: classes/fields/class.field-radio.php:81
92
+ #: classes/fields/class.field-select.php:78
93
+ #: classes/fields/class.field-text.php:58
94
+ #: classes/fields/class.field-textarea.php:58
95
+ #: classes/fields/class.field-wysiwyg.php:96
96
+ msgid "Default"
97
+ msgstr ""
98
+
99
+ #: classes/fields/class.field-check.php:92
100
+ #: classes/fields/class.field-colorpicker.php:87
101
+ #: classes/fields/class.field-datepicker.php:191
102
+ #: classes/fields/class.field-file.php:85
103
+ #: classes/fields/class.field-image.php:84
104
+ #: classes/fields/class.field-radio.php:90
105
+ #: classes/fields/class.field-relation.php:199
106
+ #: classes/fields/class.field-select.php:87
107
+ #: classes/fields/class.field-text.php:67
108
+ #: classes/fields/class.field-textarea.php:67
109
+ #: classes/fields/class.field-wysiwyg.php:105
110
+ msgid "Notes"
111
+ msgstr ""
112
+
113
+ #: classes/fields/class.field-colorpicker.php:20
114
+ msgid "Color picker"
115
+ msgstr ""
116
+
117
+ #: classes/fields/class.field-datepicker.php:20
118
+ msgid "Date picker"
119
+ msgstr ""
120
+
121
+ #: classes/fields/class.field-datepicker.php:137
122
+ msgid "Date Format"
123
+ msgstr ""
124
+
125
+ #: classes/fields/class.field-datepicker.php:145
126
+ msgid "e.g dd/mm/yy"
127
+ msgstr ""
128
+
129
+ #: classes/fields/class.field-datepicker.php:155
130
+ msgid "Max Date"
131
+ msgstr ""
132
+
133
+ #: classes/fields/class.field-datepicker.php:163
134
+ #: classes/fields/class.field-datepicker.php:181
135
+ msgid "e.g +1m +1w"
136
+ msgstr ""
137
+
138
+ #: classes/fields/class.field-datepicker.php:173
139
+ msgid "Min Date"
140
+ msgstr ""
141
+
142
+ #: classes/fields/class.field-file.php:19
143
+ msgid "File"
144
+ msgstr ""
145
+
146
+ #: classes/fields/class.field-file.php:44
147
+ #: classes/fields/class.field-image.php:44
148
+ msgid "Delete"
149
+ msgstr ""
150
+
151
+ #: classes/fields/class.field-file.php:67
152
+ msgid "File Select"
153
+ msgstr ""
154
+
155
+ #: classes/fields/class.field-image.php:19
156
+ msgid "Image"
157
+ msgstr ""
158
+
159
+ #: classes/fields/class.field-image.php:66
160
+ msgid "Image Select"
161
+ msgstr ""
162
+
163
+ #: classes/fields/class.field-radio.php:19
164
+ msgid "Radio"
165
+ msgstr ""
166
+
167
+ #: classes/fields/class.field-relation.php:21
168
+ msgid "Relation"
169
+ msgstr ""
170
+
171
+ #: classes/fields/class.field-relation.php:161
172
+ msgid "Load more"
173
+ msgstr ""
174
+
175
+ #: classes/fields/class.field-select.php:19
176
+ msgid "Select"
177
+ msgstr ""
178
+
179
+ #: classes/fields/class.field-text.php:19
180
+ msgid "Text"
181
+ msgstr ""
182
+
183
+ #: classes/fields/class.field-textarea.php:19
184
+ msgid "Textarea"
185
+ msgstr ""
186
+
187
+ #: classes/fields/class.field-wysiwyg.php:20
188
+ msgid "Wysiwyg"
189
+ msgstr ""
190
+
191
+ #: classes/fields/class.field-wysiwyg.php:121
192
+ #: classes/fields/class.field-wysiwyg.php:122
193
+ msgid "Add Media"
194
+ msgstr ""
195
+
196
+ #: classes/models/class.abstract-field-base.php:105
197
+ msgid "Name"
198
+ msgstr ""
199
+
200
+ #: classes/models/class.abstract-field-base.php:116
201
+ msgid "Label"
202
+ msgstr ""
203
+
204
+ #: classes/models/class.group.php:114
205
+ msgid "Repeat"
206
+ msgstr ""
207
+
208
+ #: classes/models/class.group.php:119
209
+ msgid "Group name"
210
+ msgstr ""
211
+
212
+ #: classes/models/class.revisions.php:190 smart-custom-fields.php:102
213
+ #: smart-custom-fields.php:103 smart-custom-fields.php:104
214
+ msgid "Smart Custom Fields"
215
+ msgstr ""
216
+
217
+ #: smart-custom-fields.php:105 smart-custom-fields.php:106
218
+ #: smart-custom-fields.php:145 smart-custom-fields.php:146
219
+ msgid "Add New"
220
+ msgstr ""
221
+
222
+ #: smart-custom-fields.php:107
223
+ msgid "New Field"
224
+ msgstr ""
225
+
226
+ #: smart-custom-fields.php:108
227
+ msgid "Edit Field"
228
+ msgstr ""
229
+
230
+ #: smart-custom-fields.php:109
231
+ msgid "View Field"
232
+ msgstr ""
233
+
234
+ #: smart-custom-fields.php:110
235
+ msgid "All Fields"
236
+ msgstr ""
237
+
238
+ #: smart-custom-fields.php:111
239
+ msgid "Search Fields"
240
+ msgstr ""
241
+
242
+ #: smart-custom-fields.php:112
243
+ msgid "Parent Fields:"
244
+ msgstr ""
245
+
246
+ #: smart-custom-fields.php:113
247
+ msgid "No Fields found."
248
+ msgstr ""
249
+
250
+ #: smart-custom-fields.php:114
251
+ msgid "No Fields found in Trash."
252
+ msgstr ""
253
+
254
+ #. Plugin URI of the plugin/theme
255
+ msgid "https://github.com/inc2734/smart-custom-fields/"
256
+ msgstr ""
257
+
258
+ #. Description of the plugin/theme
259
+ msgid "Smart Custom Fields is a simple plugin that management custom fields."
260
+ msgstr ""
261
+
262
+ #. Author of the plugin/theme
263
+ msgid "Takashi Kitajima"
264
+ msgstr ""
265
+
266
+ #. Author URI of the plugin/theme
267
+ msgid "http://2inc.org"
268
+ msgstr ""
readme.txt CHANGED
@@ -1,10 +1,10 @@
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
 
@@ -45,10 +45,20 @@ This method can get meta data of any group.
45
  * SCF::gets()
46
  This method can get all meta data.
47
 
 
 
 
 
48
  = GitHub =
49
 
50
  https://github.com/inc2734/smart-custom-fields/
51
 
 
 
 
 
 
 
52
  == Installation ==
53
 
54
  1. Upload `Smart Custom Fields` to the `/wp-content/plugins/` directory
@@ -62,6 +72,28 @@ https://github.com/inc2734/smart-custom-fields/
62
 
63
  == Changelog ==
64
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
65
  = 1.1.0 =
66
  * Add date picker field.
67
 
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.1
7
+ Stable tag: 1.2.0
8
  License: GPLv2
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
45
  * SCF::gets()
46
  This method can get all meta data.
47
 
48
+ = Register custom fields by the code. =
49
+
50
+ https://gist.github.com/inc2734/9f6d65c7473d060d0fd6
51
+
52
  = GitHub =
53
 
54
  https://github.com/inc2734/smart-custom-fields/
55
 
56
+ = Translators =
57
+
58
+ * Japanese(ja) - [JOTAKI Taisuke ](https://profiles.wordpress.org/tai/)
59
+
60
+ You can send your own language pack to me.
61
+
62
  == Installation ==
63
 
64
  1. Upload `Smart Custom Fields` to the `/wp-content/plugins/` directory
72
 
73
  == Changelog ==
74
 
75
+ = 1.2.0 =
76
+ * refactoring. A lot of changes in all.
77
+ * Renewd the Smart_Custom_Fields_Field_Base.
78
+ * Add filter hook smart-cf-register-fields. If You use this hook, you can define custom fields by the code.
79
+ * Add action hook smart-cf-before-editor-enqueue-scripts
80
+ * Add action hook smart-cf-after-editor-enqueue-scripts
81
+ * Add action hook smart-cf-before-settings-enqueue-scripts
82
+ * Add action hook smart-cf-after-settings-enqueue-scripts
83
+
84
+ = 1.1.3 =
85
+ * Change method SCF::get_field to SCF::get_value_by_field
86
+ * Change method SCF::get_sub_field to SCF::get_values_by_group
87
+ * Add method SCF::get_field
88
+ * Add method SCF::choices_eol_to_array
89
+ * remove method Smart_Custom_Fields_Field_Base::get_choices
90
+
91
+ = 1.1.2 =
92
+ * Add action hook smart-cf-fields-loaded
93
+
94
+ = 1.1.1 =
95
+ * UX Improvement of settings page.
96
+
97
  = 1.1.0 =
98
  * Add date picker field.
99
 
smart-custom-fields.php CHANGED
@@ -3,36 +3,18 @@
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
14
  * License URI: http://www.gnu.org/licenses/gpl-2.0.html
15
  */
16
  class Smart_Custom_Fields {
17
 
18
- /**
19
- * post_custom 格納用
20
- * 何度も関数呼び出ししなくて良いように保存
21
- */
22
- protected $post_custom = array();
23
-
24
- /**
25
- * repeat_multiple_data
26
- * 何度も関数呼び出ししなくて良いように保存
27
- */
28
- protected $repeat_multiple_data = array();
29
-
30
- /**
31
- * fields
32
- * 各フォーム部品のオブジェクトを格納する配列
33
- */
34
- protected $fields = array();
35
-
36
  /**
37
  * __construct
38
  */
@@ -43,34 +25,40 @@ class Smart_Custom_Fields {
43
  }
44
 
45
  /**
46
- * plugins_loaded
47
  */
48
  public function plugins_loaded() {
 
 
 
 
 
 
49
  do_action( SCF_Config::PREFIX . 'load' );
50
- require_once plugin_dir_path( __FILE__ ) . 'classes/class.field-base.php';
51
- require_once plugin_dir_path( __FILE__ ) . 'classes/class.settings.php';
52
- require_once plugin_dir_path( __FILE__ ) . 'classes/class.revisions.php';
 
53
  require_once plugin_dir_path( __FILE__ ) . 'classes/class.scf.php';
54
- new Smart_Custom_Fields_Settings();
55
  new Smart_Custom_Fields_Revisions();
56
- new SCF();
57
 
58
  foreach ( glob( plugin_dir_path( __FILE__ ) . 'classes/fields/*.php' ) as $form_item ) {
59
  include_once $form_item;
60
- $basename = basename( $form_item, '.php' );
61
  $classname = preg_replace( '/^class\.field\-(.+)$/', 'Smart_Custom_Fields_Field_$1', $basename );
62
  if ( class_exists( $classname ) ) {
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' ) );
 
70
  }
71
 
72
  /**
73
- * uninstall
74
  */
75
  public static function uninstall() {
76
  $cf_posts = get_posts( array(
@@ -85,401 +73,79 @@ class Smart_Custom_Fields {
85
  }
86
 
87
  /**
88
- * admin_enqueue_scripts
89
- * @param string $hook
90
- */
91
- public function admin_enqueue_scripts( $hook ) {
92
- if ( in_array( $hook, array( 'post-new.php', 'post.php' ) ) ) {
93
- $post_type = get_post_type();
94
- $settings = SCF::get_settings( $post_type );
95
-
96
- if ( empty( $settings ) )
97
- return;
98
-
99
- wp_enqueue_style(
100
- SCF_Config::PREFIX . 'editor',
101
- plugin_dir_url( __FILE__ ) . 'css/editor.css'
102
- );
103
- wp_enqueue_media();
104
- wp_enqueue_script(
105
- SCF_Config::PREFIX . 'editor',
106
- plugin_dir_url( __FILE__ ) . 'js/editor.js',
107
- array( 'jquery' ),
108
- null,
109
- true
110
- );
111
- wp_localize_script( SCF_Config::PREFIX . 'editor', 'smart_cf_uploader', array(
112
- 'image_uploader_title' => esc_html__( 'Image setting', 'smart-custom-fields' ),
113
- 'file_uploader_title' => esc_html__( 'File setting', 'smart-custom-fields' ),
114
- ) );
115
- }
116
- }
117
-
118
- /**
119
- * add_meta_boxes
120
- * 投稿画面にカスタムフィールドを表示
121
- * @param stirng $post_type
122
- * @param object $post
123
- */
124
- public function add_meta_boxes( $post_type, $post ) {
125
- $cf_posts = SCF::get_settings_posts( $post_type );
126
- foreach ( $cf_posts as $post ) {
127
- setup_postdata( $post );
128
- $settings = get_post_meta( $post->ID, SCF_Config::PREFIX . 'setting', true );
129
- if ( !$settings )
130
- continue;
131
- add_meta_box(
132
- SCF_Config::PREFIX . 'custom-field-' . $post->ID,
133
- $post->post_title,
134
- array( $this, 'display_meta_box' ),
135
- $post_type,
136
- 'normal',
137
- 'default',
138
- $settings
139
- );
140
- wp_reset_postdata();
141
- }
142
- }
143
-
144
- /**
145
- * display_meta_box
146
- * @param object $post
147
- * @param array $setings カスタムフィールドの設定情報
148
- */
149
- public function display_meta_box( $post, $settings ) {
150
- $_settings = SCF::get_settings( get_post_type() );
151
- $groups = $_settings[$settings['id']];
152
- $tables = $this->get_tables( $post->ID, $groups );
153
-
154
- printf( '<div class="%s">', esc_attr( SCF_Config::PREFIX . 'meta-box' ) );
155
- $index = 0;
156
- foreach ( $tables as $group_key => $group ) {
157
- $btn_repeat = '';
158
- $is_repeat = ( isset( $group['repeat'] ) && $group['repeat'] === true ) ? true : false;
159
- if ( $is_repeat ) {
160
- if ( $index === 0 ) {
161
- printf(
162
- '<div class="%s">',
163
- esc_attr( SCF_Config::PREFIX . 'meta-box-repeat-tables' )
164
- );
165
- $this->display_tr( $post->ID, $is_repeat, $group['fields'] );
166
- }
167
- }
168
-
169
- $this->display_tr( $post->ID, $is_repeat, $group['fields'], $index );
170
-
171
- // ループの場合は添字をカウントアップ
172
- // ループを抜けたらカウントをもとに戻す
173
- if ( $is_repeat &&
174
- isset( $tables[$group_key + 1 ]['group-name'] ) &&
175
- $tables[$group_key + 1 ]['group-name'] === $group['group-name'] ) {
176
- $index ++;
177
- } else {
178
- $index = 0;
179
- }
180
- if ( $is_repeat && $index === 0 ) {
181
- echo '</div>';
182
- }
183
- }
184
- printf( '</div>' );
185
- wp_nonce_field( SCF_Config::NAME . '-fields', SCF_Config::PREFIX . 'fields-nonce' );
186
- }
187
-
188
- /**
189
- * save_post
190
- * @param int $post_id
191
- */
192
- public function save_post( $post_id ) {
193
- if ( !isset( $_POST[SCF_Config::PREFIX . 'fields-nonce'] ) ) {
194
- return;
195
- }
196
- if ( !wp_verify_nonce( $_POST[SCF_Config::PREFIX . 'fields-nonce'], SCF_Config::NAME . '-fields' ) ) {
197
- return;
198
- }
199
- if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
200
- return;
201
- }
202
- if ( wp_is_post_autosave( $post_id ) || wp_is_post_revision( $post_id ) ){
203
- return;
204
- }
205
- if ( !isset( $_POST[SCF_Config::NAME] ) ) {
206
- return;
207
- }
208
-
209
- // 繰り返しフィールドのチェックボックスは、普通のチェックボックスと混ざって
210
- // 判別できなくなるのでわかるように保存しておく
211
- $repeat_multiple_data = array();
212
-
213
- // チェックボックスが未入力のときは "" がくるので、それは保存しないように判別
214
- $multiple_data_fields = array();
215
-
216
- $post_type = get_post_type();
217
- $settings = SCF::get_settings( $post_type );
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
- }
238
- }
239
- }
240
- }
241
- delete_post_meta( $post_id, SCF_Config::PREFIX . 'repeat-multiple-data' );
242
- if ( $repeat_multiple_data ) {
243
- update_post_meta( $post_id, SCF_Config::PREFIX . 'repeat-multiple-data', $repeat_multiple_data );
244
- }
245
-
246
- foreach ( $_POST[SCF_Config::NAME] as $name => $values ) {
247
- foreach ( $values as $value ) {
248
- if ( in_array( $name, $multiple_data_fields ) && $value === '' )
249
- continue;
250
- if ( !is_array( $value ) ) {
251
- $this->add_post_meta( $post_id, $name, $value );
252
- } else {
253
- foreach ( $value as $val ) {
254
- $this->add_post_meta( $post_id, $name, $val );
255
- }
256
- }
257
- }
258
- }
259
- }
260
-
261
- /**
262
- * add_post_meta
263
- * @param int $post_id
264
- * @param string $name
265
- * @param mixed $value
266
  */
267
- protected function add_post_meta( $post_id, $name, $value ) {
268
- do_action( SCF_Config::PREFIX . '-before-save-post', $post_id, $name, $value );
269
- $is_valid = apply_filters( SCF_Config::PREFIX . '-validate-save-post', true, $post_id, $name, $value );
270
- if ( $is_valid ) {
271
- add_post_meta( $post_id, $name, $value );
272
  }
273
- do_action( SCF_Config::PREFIX . '-after-save-post', $post_id, $name, $value );
274
- }
275
-
276
- /**
277
- * get_post_custom
278
- * @param int $post_id
279
- * @return array
280
- */
281
- protected function get_post_custom( $post_id ) {
282
- $post_custom = $this->post_custom;
283
- if ( empty( $post_custom ) ) {
284
- $post_custom = get_post_custom( $post_id );
285
- if ( empty( $post_custom ) ) {
286
- return array();
287
- }
288
- $this->post_custom = $post_custom;
289
  }
290
- return $this->post_custom;
291
- }
292
-
293
- /**
294
- * get_repeat_multiple_data
295
- * @param int $post_id
296
- * @return array $this->repeat_multiple_data
297
- */
298
- protected function get_repeat_multiple_data( $post_id ) {
299
- $repeat_multiple_data = $this->repeat_multiple_data;
300
- if ( empty( $repeat_multiple_data ) ) {
301
- $repeat_multiple_data = get_post_meta( $post_id, SCF_Config::PREFIX . 'repeat-multiple-data', true );
302
- if ( empty( $repeat_multiple_data ) ) {
303
- return array();
304
- }
305
- if ( is_serialized( $repeat_multiple_data ) ) {
306
- $repeat_multiple_data = maybe_unserialize( $repeat_multiple_data );
307
- }
308
- $this->repeat_multiple_data = $repeat_multiple_data;
309
- }
310
- return $this->repeat_multiple_data;
311
- }
312
-
313
- /**
314
- * get_tables
315
- * カスタムフィールドを出力するための配列を生成
316
- * @param array $groups カスタムフィールド設定ページで保存した設定
317
- * @return array $tables カスタムフィールド表示用のテーブルを出力するための配列
318
- */
319
- protected function get_tables( $post_id, $groups ) {
320
- $post_custom = $this->get_post_custom( $post_id );
321
- $repeat_multiple_data = $this->get_repeat_multiple_data( $post_id );
322
- $tables = array();
323
- foreach ( $groups as $group ) {
324
- // ループのときは、ループの分だけグループを追加する
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
- }
340
- // チェックボックス以外
341
- else {
342
- if ( $loop_count < $post_meta_count )
343
- $loop_count = $post_meta_count;
344
- }
345
- }
346
- }
347
- }
348
- if ( $loop_count >= 1 ) {
349
- for ( $i = $loop_count; $i > 0; $i -- ) {
350
- $tables[] = $group;
351
- }
352
- continue;
353
- }
354
- }
355
- $tables[] = $group;
356
  }
357
- return $tables;
358
  }
359
 
360
  /**
361
- * get_multiple_data_field_value
362
- * @param int $post_id
363
- * @param string $field_name
364
- * @param int $index
365
- * @return array or null
366
- */
367
- protected function get_multiple_data_field_value( $post_id, $field_name, $index ) {
368
- $post_custom = $this->get_post_custom( $post_id );
369
- $repeat_multiple_data = $this->get_repeat_multiple_data( $post_id );
370
- $value = null;
371
- if ( isset( $post_custom[$field_name] ) && is_array( $post_custom[$field_name] ) ) {
372
- $value = $post_custom[$field_name];
373
- // ループのとき
374
- if ( is_array( $repeat_multiple_data ) && array_key_exists( $field_name, $repeat_multiple_data ) ) {
375
- $now_num = 0;
376
- if ( isset( $repeat_multiple_data[$field_name][$index] ) ) {
377
- $now_num = $repeat_multiple_data[$field_name][$index];
378
- }
379
-
380
- // 自分($index)より前の個数の合計が指す index が start
381
- $_temp = array_slice( $repeat_multiple_data[$field_name], 0, $index );
382
- $sum = array_sum( $_temp );
383
- $start = $sum;
384
-
385
- $value = null;
386
- if ( $now_num ) {
387
- $value = array_slice( $post_custom[$field_name], $start, $now_num );
388
- }
389
- }
390
- }
391
- return $value;
392
- }
393
-
394
- /**
395
- * get_single_data_field_value
396
- * @param int $post_id
397
- * @param string $field_name
398
- * @param int $index
399
- * @return string or null
400
- */
401
- protected function get_single_data_field_value( $post_id, $field_name, $index ) {
402
- $post_custom = $this->get_post_custom( $post_id );
403
- $value = null;
404
- if ( isset( $post_custom[$field_name][$index] ) ) {
405
- $value = $post_custom[$field_name][$index];
406
- }
407
- return $value;
408
  }
409
 
410
  /**
411
- * display_tr
412
- * @param int $post_id
413
- * @param bool $is_repeat
414
- * @param array $fields
415
- * @param int, null $index
416
  */
417
- protected function display_tr( $post_id, $is_repeat, $fields, $index = null ) {
418
- $btn_repeat = '';
419
- if ( $is_repeat ) {
420
- $btn_repeat = sprintf( '<span class="%s"></span>', esc_attr( SCF_Config::PREFIX . 'icon-handle' ) );
421
- $btn_repeat .= '<span class="button btn-add-repeat-group">+</span>';
422
- $btn_repeat .= ' <span class="button btn-remove-repeat-group">-</span>';
423
- }
424
-
425
- $style = '';
426
- if ( is_null( $index ) ) {
427
- $style = 'style="display: none;"';
428
- }
429
-
430
- printf(
431
- '<div class="%s" %s>%s<table>',
432
- esc_attr( SCF_Config::PREFIX . 'meta-box-table' ),
433
- $style,
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
- // 複数値許可フィールドのとき
444
- $post_status = get_post_status( $post_id );
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 {
454
- $value = '';
455
- if ( $post_status === 'auto-draft' || is_null( $index ) ) {
456
- if ( !SCF::is_empty( $field['default'] ) ) {
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;
464
- }
465
-
466
- $notes = '';
467
- if ( !empty( $field['notes'] ) ) {
468
- $notes = sprintf(
469
- '<p class="description">%s</p>',
470
- esc_html( $field['notes'] )
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 ),
478
- $form_field,
479
- $notes
480
- );
481
- }
482
- echo '</table></div>';
483
  }
484
  }
485
  new Smart_Custom_Fields();
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.2.0
7
  * Author: Takashi Kitajima
8
  * Author URI: http://2inc.org
9
  * Created: October 9, 2014
10
+ * Modified: February 27, 2015
11
  * Text Domain: smart-custom-fields
12
+ * Domain Path: /languages
13
  * License: GPLv2
14
  * License URI: http://www.gnu.org/licenses/gpl-2.0.html
15
  */
16
  class Smart_Custom_Fields {
17
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
  /**
19
  * __construct
20
  */
25
  }
26
 
27
  /**
28
+ * 各クラス・翻訳ファイルの読み込み
29
  */
30
  public function plugins_loaded() {
31
+ load_plugin_textdomain (
32
+ 'smart-custom-fields',
33
+ false,
34
+ dirname( plugin_basename( __FILE__ ) ) . '/languages'
35
+ );
36
+
37
  do_action( SCF_Config::PREFIX . 'load' );
38
+ require_once plugin_dir_path( __FILE__ ) . 'classes/models/class.setting.php';
39
+ require_once plugin_dir_path( __FILE__ ) . 'classes/models/class.group.php';
40
+ require_once plugin_dir_path( __FILE__ ) . 'classes/models/class.abstract-field-base.php';
41
+ require_once plugin_dir_path( __FILE__ ) . 'classes/models/class.revisions.php';
42
  require_once plugin_dir_path( __FILE__ ) . 'classes/class.scf.php';
 
43
  new Smart_Custom_Fields_Revisions();
 
44
 
45
  foreach ( glob( plugin_dir_path( __FILE__ ) . 'classes/fields/*.php' ) as $form_item ) {
46
  include_once $form_item;
47
+ $basename = basename( $form_item, '.php' );
48
  $classname = preg_replace( '/^class\.field\-(.+)$/', 'Smart_Custom_Fields_Field_$1', $basename );
49
  if ( class_exists( $classname ) ) {
50
  new $classname();
51
  }
52
  }
53
+ do_action( SCF_Config::PREFIX . 'fields-loaded' );
54
+
55
+ add_action( 'init' , array( $this, 'register_post_type' ) );
56
+ add_action( 'admin_menu' , array( $this, 'admin_menu' ) );
57
+ add_action( 'current_screen', array( $this, 'current_screen' ) );
58
  }
59
 
60
  /**
61
+ * アンインストール時の処理
62
  */
63
  public static function uninstall() {
64
  $cf_posts = get_posts( array(
73
  }
74
 
75
  /**
76
+ * 各管理画面の実行
77
+ *
78
+ * @param WP_Screen $screen
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
79
  */
80
+ public function current_screen( $screen ) {
81
+ // 一覧画面
82
+ if ( $screen->id === 'edit-' . SCF_Config::NAME ) {
 
 
83
  }
84
+ // 新規作成・編集画面
85
+ elseif ( $screen->id === SCF_Config::NAME ) {
86
+ require_once plugin_dir_path( __FILE__ ) . 'classes/controller/class.settings.php';
87
+ new Smart_Custom_Fields_Controller_Settings();
 
 
 
 
 
 
 
 
 
 
 
 
88
  }
89
+ // その他の新規作成・編集画面
90
+ elseif ( SCF::get_settings( $screen->id ) ) {
91
+ require_once plugin_dir_path( __FILE__ ) . 'classes/controller/class.editor.php';
92
+ new Smart_Custom_Fields_Controller_Editor();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
93
  }
 
94
  }
95
 
96
  /**
97
+ * カスタム投稿タイプの登録。メニュー表示は別メソッドで実行
98
+ */
99
+ public function register_post_type() {
100
+ $labels = array(
101
+ 'name' => __( 'Smart Custom Fields', 'smart-custom-fields' ),
102
+ 'menu_name' => __( 'Smart Custom Fields', 'smart-custom-fields' ),
103
+ 'name_admin_bar' => __( 'Smart Custom Fields', 'smart-custom-fields' ),
104
+ 'add_new' => __( 'Add New', 'smart-custom-fields' ),
105
+ 'add_new_item' => __( 'Add New', 'smart-custom-fields' ),
106
+ 'new_item' => __( 'New Field', 'smart-custom-fields' ),
107
+ 'edit_item' => __( 'Edit Field', 'smart-custom-fields' ),
108
+ 'view_item' => __( 'View Field', 'smart-custom-fields' ),
109
+ 'all_items' => __( 'All Fields', 'smart-custom-fields' ),
110
+ 'search_items' => __( 'Search Fields', 'smart-custom-fields' ),
111
+ 'parent_item_colon' => __( 'Parent Fields:', 'smart-custom-fields' ),
112
+ 'not_found' => __( 'No Fields found.', 'smart-custom-fields' ),
113
+ 'not_found_in_trash' => __( 'No Fields found in Trash.', 'smart-custom-fields' )
114
+ );
115
+ register_post_type(
116
+ SCF_Config::NAME,
117
+ array(
118
+ 'label' => 'Smart Custom Fields',
119
+ 'labels' => $labels,
120
+ 'public' => false,
121
+ 'show_ui' => true,
122
+ 'capability_type' => 'page',
123
+ 'supports' => array( 'title', 'page-attributes' ),
124
+ 'show_in_menu' => false,
125
+ )
126
+ );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
127
  }
128
 
129
  /**
130
+ * 管理画面にメニューを追加
 
 
 
 
131
  */
132
+ public function admin_menu() {
133
+ add_menu_page(
134
+ 'Smart Custom Fields',
135
+ 'Smart Custom Fields',
136
+ 'manage_options',
137
+ 'edit.php?post_type=' . SCF_Config::NAME,
138
+ false,
139
+ false,
140
+ '80.026'
141
+ );
142
+ add_submenu_page(
143
+ 'edit.php?post_type=' . SCF_Config::NAME,
144
+ __( 'Add New', 'smart-custom-fields' ),
145
+ __( 'Add New', 'smart-custom-fields' ),
146
+ 'manage_options',
147
+ 'post-new.php?post_type=' . SCF_Config::NAME
 
 
148
  );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
149
  }
150
  }
151
  new Smart_Custom_Fields();