Smart Custom Fields - Version 1.3.0

Version Description

  • refactoring.
  • Add profile custom fields.
  • Add filter hook smart-cf-validate-get-value
  • Add method SCF::get_user_meta( $user_id, $name
Download this release

Release Info

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

Code changes from version 1.2.2 to 1.3.0

classes/class.config.php CHANGED
@@ -1,10 +1,10 @@
1
  <?php
2
  /**
3
  * SCF_Config
4
- * Version : 1.0.0
5
  * Author : Takashi Kitajima
6
  * Created : September 23, 2014
7
- * Modified :
8
  * License : GPLv2
9
  * License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
  */
@@ -18,4 +18,9 @@ class SCF_Config {
18
  * prefix
19
  */
20
  const PREFIX = 'smart-cf-';
 
 
 
 
 
21
  }
1
  <?php
2
  /**
3
  * SCF_Config
4
+ * Version : 1.0.1
5
  * Author : Takashi Kitajima
6
  * Created : September 23, 2014
7
+ * Modified : March 16, 2015
8
  * License : GPLv2
9
  * License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
  */
18
  * prefix
19
  */
20
  const PREFIX = 'smart-cf-';
21
+
22
+ /**
23
+ * プロフィール画面用の擬似投稿タイプ
24
+ */
25
+ const PROFILE = 'smart-cf-profile';
26
  }
classes/class.scf.php CHANGED
@@ -1,10 +1,10 @@
1
  <?php
2
  /**
3
  * SCF
4
- * Version : 1.1.2
5
  * Author : Takashi Kitajima
6
  * Created : September 23, 2014
7
- * Modified : March 13, 2015
8
  * License : GPLv2
9
  * License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
  */
@@ -35,7 +35,7 @@ class SCF {
35
  * キーに post_type を設定すること。
36
  * @var array
37
  */
38
- protected static $settings_cache = array();
39
 
40
  /**
41
  * データ取得処理は重いので、一度取得した設定データは cache に保存する。
@@ -44,6 +44,16 @@ class SCF {
44
  */
45
  protected static $repeat_multiple_data_cache = array();
46
 
 
 
 
 
 
 
 
 
 
 
47
  /**
48
  * その投稿の全てのメタデータを良い感じに取得
49
  *
@@ -57,32 +67,12 @@ class SCF {
57
  $post_id = self::get_real_post_id( $post_id );
58
 
59
  if ( empty( $post_id ) ) {
60
- return array();
61
  }
62
 
63
  // 設定画面で未設定のメタデータは投稿が保持していても出力しないようにしないといけないので
64
  // 設定データを取得して出力して良いか判別する
65
- $post_type = self::get_public_post_type( $post_id );
66
- $settings = self::get_settings( $post_type, $post_id );
67
- $post_meta = array();
68
- foreach ( $settings as $Setting ) {
69
- $groups = $Setting->get_groups();
70
- foreach ( $groups as $Group ) {
71
- $is_repeatable = $Group->is_repeatable();
72
- $group_name = $Group->get_name();
73
- if ( $is_repeatable && $group_name ) {
74
- $post_meta[$group_name] = self::get_values_by_group( $post_id, $Group );
75
- }
76
- else {
77
- $fields = $Group->get_fields();
78
- foreach ( $fields as $Field ) {
79
- $field_name = $Field->get( 'name' );
80
- $post_meta[$field_name] = self::get_value_by_field( $post_id, $Field, $is_repeatable );
81
- }
82
- }
83
- }
84
- }
85
- return $post_meta;
86
  }
87
 
88
  /**
@@ -102,17 +92,49 @@ class SCF {
102
  return;
103
  }
104
 
105
- if ( self::get_cache( $post_id, $name ) ) {
106
- self::debug_cache_message( "use get cache. {$post_id} {$name}" );
107
- return self::get_cache( $post_id, $name );
108
- } else {
109
- self::debug_cache_message( "dont use get cache... {$post_id} {$name}" );
 
 
 
 
 
 
 
 
 
 
110
  }
111
 
112
- // 設定画面で未設定のメタデータは投稿が保持していても出力しないようにしないといけないので
 
 
 
 
 
113
  // 設定データを取得して出力して良いか判別する
114
- $post_type = self::get_public_post_type( $post_id );
115
- $settings = self::get_settings( $post_type, $post_id );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
116
  foreach ( $settings as $Setting ) {
117
  $groups = $Setting->get_groups();
118
  foreach ( $groups as $Group ) {
@@ -120,7 +142,9 @@ class SCF {
120
  $is_repeatable = $Group->is_repeatable();
121
  $group_name = $Group->get_name();
122
  if ( $is_repeatable && $group_name && $group_name === $name ) {
123
- return self::get_values_by_group( $post_id, $Group );
 
 
124
  }
125
  // グループ名と一致しない場合は一致するフィールドを返す
126
  else {
@@ -128,7 +152,9 @@ class SCF {
128
  foreach ( $fields as $Field ) {
129
  $field_name = $Field->get( 'name' );
130
  if ( $field_name === $name ) {
131
- return self::get_value_by_field( $post_id, $Field, $is_repeatable );
 
 
132
  }
133
  }
134
  }
@@ -137,18 +163,36 @@ class SCF {
137
  }
138
 
139
  /**
140
- * Post ID がリビジョンのものでも良い感じに投稿タイプを取得
141
  *
142
- * @param int $post_id
143
- * @return string
144
  */
145
- protected static function get_public_post_type( $post_id ) {
146
- if ( $public_post_id = wp_is_post_revision( $post_id ) ) {
147
- $post_type = get_post_type( $public_post_id );
148
- } else {
149
- $post_type = get_post_type( $post_id );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
150
  }
151
- return $post_type;
152
  }
153
 
154
  /**
@@ -170,246 +214,312 @@ class SCF {
170
  /**
171
  * キャシュに保存
172
  *
173
- * @param int $post_id
174
  * @param string $name
175
  * @param mixed $data
176
  */
177
- protected static function save_cache( $post_id, $name, $data ) {
178
- self::$cache[$post_id][$name] = $data;
 
 
 
 
 
179
  }
180
 
181
  /**
182
  * キャッシュを取得
183
  *
184
- * @param int $post_id
185
  * @param string $name
186
  * @return mixed
187
  */
188
- protected static function get_cache( $post_id, $name = null ) {
189
- if ( is_null( $name ) ) {
190
- if ( isset( self::$cache[$post_id] ) ) {
191
- return self::$cache[$post_id];
192
- }
193
- } else {
194
- if ( isset( self::$cache[$post_id][$name] ) ) {
195
- return self::$cache[$post_id][$name];
 
 
 
 
 
196
  }
197
  }
198
  }
199
 
200
  /**
201
- * そのグループのメタデータを取得
 
 
 
 
 
 
 
202
  *
203
- * @param int $post_id
204
  * @param Smart_Custom_Fields_Group $Group
205
  * @return mixed
206
  */
207
- protected static function get_values_by_group( $post_id, $Group ) {
208
- $post_meta = array();
209
- $fields = $Group->get_fields();
 
 
210
  foreach ( $fields as $Field ) {
211
- $field_name = $Field->get( 'name' );
212
- if ( !$field_name ) {
213
- continue;
214
- }
215
- $_post_meta = get_post_meta( $post_id, $field_name );
216
- // チェックボックスの場合
217
- $repeat_multiple_data = self::get_repeat_multiple_data( $post_id );
218
- if ( is_array( $repeat_multiple_data ) && array_key_exists( $field_name, $repeat_multiple_data ) ) {
219
- $start = 0;
220
- foreach ( $repeat_multiple_data[$field_name] as $repeat_multiple_key => $repeat_multiple_value ) {
221
- if ( $repeat_multiple_value === 0 ) {
222
- $value = array();
223
- } else {
224
- $value = array_slice( $_post_meta, $start, $repeat_multiple_value );
225
- $start += $repeat_multiple_value;
226
- }
227
- $post_meta[$repeat_multiple_key][$field_name] = $value;
228
- }
229
  }
230
- // チェックボックス以外
231
- else {
232
- $field_type = $Field->get_attribute( 'type' );
233
- foreach ( $_post_meta as $_post_meta_key => $value ) {
234
- // wysiwyg の場合はフィルタを通す
235
- if ( $field_type === 'wysiwyg' ) {
236
- $value = self::add_the_content_filter( $value );
237
- }
238
- // relation のときは $value = Post ID。公開済みでない場合は取得しない
239
- elseif ( $field_type === 'relation' ) {
240
- if ( get_post_status( $value ) !== 'publish' ) {
241
- continue;
242
- }
243
- }
244
- $post_meta[$_post_meta_key][$field_name] = $value;
245
- }
246
  }
247
  }
248
- self::save_cache( $post_id, $Group->get_name(), $post_meta );
249
- return $post_meta;
 
 
250
  }
251
 
252
  /**
253
  * そのフィールドのメタデータを取得
254
  *
255
- * @param int $post_id
256
  * @param array $field
257
  * @param bool $is_repeatable このフィールドが所属するグループが repeat かどうか
258
  * @return mixed $post_meta
259
  */
260
- protected static function get_value_by_field( $post_id, $Field, $is_repeatable ) {
261
  $field_name = $Field->get( 'name' );
262
  if ( !$field_name ) {
263
  return;
264
  }
265
- if ( $Field->get_attribute( 'allow-multiple-data' ) || $is_repeatable ) {
266
- $post_meta = get_post_meta( $post_id, $field_name );
267
- } else {
268
- $post_meta = get_post_meta( $post_id, $field_name, true );
269
- }
270
-
271
  $field_type = $Field->get_attribute( 'type' );
272
- if ( in_array( $field_type, array( 'wysiwyg' ) ) ) {
273
- if ( is_array( $post_meta ) ) {
274
- $_post_meta = array();
275
- foreach ( $post_meta as $key => $value ) {
276
- $_post_meta[$key] = self::add_the_content_filter( $value );
 
 
 
 
 
277
  }
278
- $post_meta = $_post_meta;
279
- } else {
280
- $post_meta = self::add_the_content_filter( $post_meta );
281
  }
282
- } elseif ( $field_type === 'relation' ) {
283
- $_post_meta = array();
284
- if ( is_array( $post_meta ) ) {
285
- foreach ( $post_meta as $post_id ) {
286
- if ( get_post_status( $post_id ) !== 'publish' ) {
287
- continue;
288
- }
289
- $_post_meta[] = $post_id;
290
- }
291
  }
292
- $post_meta = $_post_meta;
293
  }
294
- self::save_cache( $post_id, $field_name, $post_meta );
295
- return $post_meta;
296
  }
297
 
298
  /**
299
- * その投稿タイプで有効になっている SCF をキャッシュに保存
300
  *
301
- * @param string $post_type
302
  * @param array $settings_posts
303
  */
304
- protected static function save_settings_posts_cache( $post_type, $settings_posts ) {
305
- self::$settings_posts_cache[$post_type] = $settings_posts;
 
 
306
  }
307
 
308
  /**
309
  * その投稿タイプで有効になっている SCF のキャッシュを取得
310
  *
311
- * @param string $post_type
312
- * @return array
313
  */
314
- public static function get_settings_posts_cache( $post_type ) {
315
- if ( isset( self::$settings_posts_cache[$post_type] ) ) {
316
- return self::$settings_posts_cache[$post_type];
 
 
317
  }
318
- return array();
 
 
 
 
 
 
319
  }
320
 
321
  /**
322
  * その投稿タイプで有効になっている SCF を取得
323
  *
324
- * @param string $post_type
325
  * @return array $settings
326
  */
327
- public static function get_settings_posts( $post_type ) {
328
- $posts = array();
329
- if ( self::get_settings_posts_cache( $post_type ) ) {
330
- self::debug_cache_message( "use settings posts cache. {$post_type}" );
331
- return self::get_settings_posts_cache( $post_type );
332
  } else {
333
- self::debug_cache_message( "dont use settings posts cache... {$post_type}" );
334
- }
335
- $settings_posts = get_posts( array(
336
- 'post_type' => SCF_Config::NAME,
337
- 'posts_per_page' => -1,
338
- 'order' => 'ASC',
339
- 'order_by' => 'menu_order',
340
- 'meta_query' => array(
341
- array(
342
- 'key' => SCF_Config::PREFIX . 'condition',
343
- 'compare' => 'LIKE',
344
- 'value' => $post_type,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
345
  ),
346
- ),
347
- ) );
348
- self::save_settings_posts_cache( $post_type, $settings_posts );
349
  return $settings_posts;
350
  }
351
 
352
  /**
353
  * Setting オブジェクトをキャッシュに保存
354
  *
355
- * @param string $post_type
356
- * @param int|false $post_id
357
  * @param Smart_Custom_Fields_Setting $Setting
358
  */
359
- protected static function save_settings_cache( $post_type, $post_id, $Setting ) {
360
- if ( empty( $post_id ) ) {
361
- self::$settings_cache[$post_type][0][] = $Setting;
 
 
 
 
 
362
  } else {
363
- self::$settings_cache[$post_type][$post_id][] = $Setting;
364
  }
365
  }
366
 
367
  /**
368
  * Setting オブジェクトキャッシュを取得
 
 
 
 
 
 
369
  *
370
- * @param string $post_type
371
- * @param int|false $post_id
372
- * @return array
373
  */
374
- public static function get_settings_cache( $post_type, $post_id ) {
375
- $settings = array();
376
- if ( empty( $post_id ) ) {
377
- return $settings;
378
- }
379
- if ( !isset( self::$settings_cache[$post_type] ) ) {
380
- return $settings;
381
  }
382
- if ( isset( self::$settings_cache[$post_type][0] ) ) {
383
- $settings = self::$settings_cache[$post_type][0];
384
- }
385
- if ( !empty( $post_id ) ) {
386
- if ( isset( self::$settings_cache[$post_type][$post_id] ) ) {
387
- $settings = array_merge( $settings, self::$settings_cache[$post_type][$post_id] );
 
 
388
  }
 
389
  }
390
- return $settings;
 
 
 
 
 
 
391
  }
392
 
393
  /**
394
  * Setting オブジェクトの配列を取得
395
  *
396
- * @param string $post_type
397
- * @param int|false $post_id
398
  * @return array $settings
399
  */
400
- public static function get_settings( $post_type, $post_id ) {
401
- if ( empty( $post_id ) ) {
402
- $post_id = get_the_ID();
403
- }
404
- if ( self::get_settings_cache( $post_type, $post_id ) ) {
405
- self::debug_cache_message( "use settings cache. {$post_type} {$post_id}" );
406
- return self::get_settings_cache( $post_type, $post_id );
407
- } else {
408
- self::debug_cache_message( "dont use settings cache... {$post_type} {$post_id}" );
 
 
 
 
 
 
409
  }
 
 
 
 
 
 
 
 
 
 
 
 
410
  $settings = array();
411
- $settings_posts = self::get_settings_posts( $post_type );
412
  foreach ( $settings_posts as $settings_post ) {
 
 
 
 
 
 
 
 
 
413
  $condition_post_ids_raw = get_post_meta(
414
  $settings_post->ID,
415
  SCF_Config::PREFIX . 'condition-post-ids',
@@ -420,49 +530,107 @@ class SCF {
420
  foreach ( $condition_post_ids_raw as $condition_post_id ) {
421
  $condition_post_id = trim( $condition_post_id );
422
  $Setting = SCF::add_setting( $settings_post->ID, $settings_post->post_title );
423
- if ( $post_id == $condition_post_id ) {
424
- $settings[] = $Setting;
425
  }
426
- self::save_settings_cache( $post_type, $condition_post_id, $Setting );
 
 
 
 
 
 
427
  }
428
  } else {
429
  $Setting = SCF::add_setting( $settings_post->ID, $settings_post->post_title );
430
- $settings[] = $Setting;
431
- self::save_settings_cache( $post_type, false, $Setting );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
432
  }
 
 
 
 
433
  }
434
- $settings = apply_filters( SCF_Config::PREFIX . 'register-fields', $settings, $post_type, $post_id );
435
  return $settings;
436
  }
437
 
438
  /**
439
  * 繰り返しに設定された複数許可フィールドデータの区切り識別用データをキャッシュに保存
440
  *
441
- * @param int $post_id
442
  * @param mixed $repeat_multiple_data
443
  */
444
- protected static function save_repeat_multiple_data_cache( $post_id, $repeat_multiple_data ) {
445
- self::$repeat_multiple_data_cache[$post_id] = $repeat_multiple_data;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
446
  }
447
 
448
  /**
449
  * 繰り返しに設定された複数許可フィールドデータの区切り識別用データを取得
450
  *
451
- * @param int $post_id
452
- * @return mixed
453
  */
454
- public static function get_repeat_multiple_data( $post_id ) {
455
  $repeat_multiple_data = array();
456
- if ( isset( self::$repeat_multiple_data_cache[$post_id] ) ) {
457
- return self::$repeat_multiple_data_cache[$post_id];
458
  }
459
- if ( empty( $repeat_multiple_data ) ) {
460
- $_repeat_multiple_data = get_post_meta( $post_id, SCF_Config::PREFIX . 'repeat-multiple-data', true );
461
- if ( $_repeat_multiple_data ) {
462
- $repeat_multiple_data = $_repeat_multiple_data;
463
- }
464
  }
465
- self::save_repeat_multiple_data_cache( $post_id, $repeat_multiple_data );
 
466
  return $repeat_multiple_data;
467
  }
468
 
@@ -528,7 +696,7 @@ class SCF {
528
  * @return Smart_Custom_Fields_Field_Base
529
  */
530
  public static function get_field( $post_type, $field_name ) {
531
- $settings = self::get_settings( $post_type, get_the_ID() );
532
  foreach ( $settings as $Setting ) {
533
  $groups = $Setting->get_groups();
534
  foreach ( $groups as $Group ) {
@@ -566,34 +734,6 @@ class SCF {
566
  return new Smart_Custom_Fields_Setting( $id, $title );
567
  }
568
 
569
- /**
570
- * デフォルトで the_content に適用される関数を適用
571
- *
572
- * @param string $value
573
- * @return string
574
- */
575
- protected static function add_the_content_filter( $value ) {
576
- if ( has_filter( 'the_content', 'wptexturize' ) ) {
577
- $value = wptexturize( $value );
578
- }
579
- if ( has_filter( 'the_content', 'convert_smilies' ) ) {
580
- $value = convert_smilies( $value );
581
- }
582
- if ( has_filter( 'the_content', 'convert_chars' ) ) {
583
- $value = convert_chars( $value );
584
- }
585
- if ( has_filter( 'the_content', 'wpautop' ) ) {
586
- $value = wpautop( $value );
587
- }
588
- if ( has_filter( 'the_content', 'shortcode_unautop' ) ) {
589
- $value = shortcode_unautop( $value );
590
- }
591
- if ( has_filter( 'the_content', 'prepend_attachment' ) ) {
592
- $value = prepend_attachment( $value );
593
- }
594
- return $value;
595
- }
596
-
597
  /**
598
  * キャッシュの使用状況を画面に表示
599
  */
1
  <?php
2
  /**
3
  * SCF
4
+ * Version : 1.1.3
5
  * Author : Takashi Kitajima
6
  * Created : September 23, 2014
7
+ * Modified : March 16, 2015
8
  * License : GPLv2
9
  * License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
  */
35
  * キーに post_type を設定すること。
36
  * @var array
37
  */
38
+ public static $settings_cache = array();
39
 
40
  /**
41
  * データ取得処理は重いので、一度取得した設定データは cache に保存する。
44
  */
45
  protected static $repeat_multiple_data_cache = array();
46
 
47
+ /**
48
+ * 全てのキャッシュをクリア
49
+ */
50
+ public static function clear_all_cache() {
51
+ self::clear_cache();
52
+ self::clear_settings_posts_cache();
53
+ self::clear_settings_cache();
54
+ self::clear_repeat_multiple_data_cache();
55
+ }
56
+
57
  /**
58
  * その投稿の全てのメタデータを良い感じに取得
59
  *
67
  $post_id = self::get_real_post_id( $post_id );
68
 
69
  if ( empty( $post_id ) ) {
70
+ return null;
71
  }
72
 
73
  // 設定画面で未設定のメタデータは投稿が保持していても出力しないようにしないといけないので
74
  // 設定データを取得して出力して良いか判別する
75
+ return self::get_all_meta( get_post( $post_id ) );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
76
  }
77
 
78
  /**
92
  return;
93
  }
94
 
95
+ // 設定画面で未設定のメタデータは投稿が保持していても出力しないようにしないといけないので
96
+ // 設定データを取得して出力して良いか判別する
97
+ return self::get_meta( get_post( $post_id ), $name );
98
+ }
99
+
100
+ /**
101
+ * そのユーザーの任意のメタデータを良い感じに取得
102
+ *
103
+ * @param int $user_id
104
+ * @param string $name グループ名もしくはフィールド名
105
+ * @return mixed
106
+ */
107
+ public static function get_user_meta( $user_id, $name = null ) {
108
+ if ( empty( $user_id ) ) {
109
+ return;
110
  }
111
 
112
+ // $name が null のときは全てのメタデータを返す
113
+ if ( $name === null ) {
114
+ return self::get_all_meta( get_userdata( $user_id ) );
115
+ }
116
+
117
+ // 設定画面で未設定のメタデータはユーザーが保持していても出力しないようにしないといけないので
118
  // 設定データを取得して出力して良いか判別する
119
+ return self::get_meta( get_userdata( $user_id ), $name );
120
+ }
121
+
122
+ /**
123
+ * 任意のメタデータを良い感じに取得
124
+ *
125
+ * @param WP_Post|WP_User $object
126
+ * @param string $name グループ名もしくはフィールド名
127
+ * @return mixed
128
+ */
129
+ protected static function get_meta( $object, $name ) {
130
+ if ( self::get_cache( $object, $name ) ) {
131
+ self::debug_cache_message( "use get cache. [name: {$name}]" );
132
+ return self::get_cache( $object, $name );
133
+ } else {
134
+ self::debug_cache_message( "dont use get cache... [name: {$name}]" );
135
+ }
136
+
137
+ $settings = self::get_settings( $object );
138
  foreach ( $settings as $Setting ) {
139
  $groups = $Setting->get_groups();
140
  foreach ( $groups as $Group ) {
142
  $is_repeatable = $Group->is_repeatable();
143
  $group_name = $Group->get_name();
144
  if ( $is_repeatable && $group_name && $group_name === $name ) {
145
+ $values_by_group = self::get_values_by_group( $object, $Group );
146
+ self::save_cache( $object, $group_name, $values_by_group );
147
+ return $values_by_group;
148
  }
149
  // グループ名と一致しない場合は一致するフィールドを返す
150
  else {
152
  foreach ( $fields as $Field ) {
153
  $field_name = $Field->get( 'name' );
154
  if ( $field_name === $name ) {
155
+ $value_by_field = self::get_value_by_field( $object, $Field, $is_repeatable );
156
+ self::save_cache( $object, $Field->get( 'name' ), $value_by_field );
157
+ return $value_by_field;
158
  }
159
  }
160
  }
163
  }
164
 
165
  /**
166
+ * 全てのメタデータを良い感じに取得
167
  *
168
+ * @param WP_Post|WP_User $object
169
+ * @return mixed
170
  */
171
+ protected static function get_all_meta( $object ) {
172
+ $settings = self::get_settings( $object );
173
+ $post_meta = array();
174
+ foreach ( $settings as $Setting ) {
175
+ $groups = $Setting->get_groups();
176
+ foreach ( $groups as $Group ) {
177
+ $is_repeatable = $Group->is_repeatable();
178
+ $group_name = $Group->get_name();
179
+ if ( $is_repeatable && $group_name ) {
180
+ $values_by_group = self::get_values_by_group( $object, $Group );
181
+ self::save_cache( $object, $group_name, $values_by_group );
182
+ $post_meta[$group_name] = $values_by_group;
183
+ }
184
+ else {
185
+ $fields = $Group->get_fields();
186
+ foreach ( $fields as $Field ) {
187
+ $field_name = $Field->get( 'name' );
188
+ $value_by_field = self::get_value_by_field( $object, $Field, $is_repeatable );
189
+ self::save_cache( $object, $Field->get( 'name' ), $value_by_field );
190
+ $post_meta[$field_name] = $value_by_field;
191
+ }
192
+ }
193
+ }
194
  }
195
+ return $post_meta;
196
  }
197
 
198
  /**
214
  /**
215
  * キャシュに保存
216
  *
217
+ * @param WP_Post|WP_User $object
218
  * @param string $name
219
  * @param mixed $data
220
  */
221
+ protected static function save_cache( $object, $name, $data ) {
222
+ $Meta = new Smart_Custom_Fields_Meta( $object );
223
+ $id = $Meta->get_id();
224
+ $type = $Meta->get_type();
225
+ if ( !empty( $id ) && !empty( $type ) ) {
226
+ self::$cache[$type . '_' . $id][$name] = $data;
227
+ }
228
  }
229
 
230
  /**
231
  * キャッシュを取得
232
  *
233
+ * @param WP_Post|WP_User $object
234
  * @param string $name
235
  * @return mixed
236
  */
237
+ protected static function get_cache( $object, $name = null ) {
238
+ $Meta = new Smart_Custom_Fields_Meta( $object );
239
+ $id = $Meta->get_id();
240
+ $type = $Meta->get_type();
241
+ if ( !empty( $id ) && !empty( $type ) ) {
242
+ if ( is_null( $name ) ) {
243
+ if ( isset( self::$cache[$type . '_' . $id] ) ) {
244
+ return self::$cache[$type . '_' . $id];
245
+ }
246
+ } else {
247
+ if ( isset( self::$cache[$type . '_' . $id][$name] ) ) {
248
+ return self::$cache[$type . '_' . $id][$name];
249
+ }
250
  }
251
  }
252
  }
253
 
254
  /**
255
+ * キャッシュをクリア
256
+ */
257
+ public static function clear_cache() {
258
+ self::$cache = array();
259
+ }
260
+
261
+ /**
262
+ * そのグループのメタデータを取得。グループの場合は必ず繰り返しになっている点に注意
263
  *
264
+ * @param WP_Post|WP_User $object
265
  * @param Smart_Custom_Fields_Group $Group
266
  * @return mixed
267
  */
268
+ protected static function get_values_by_group( $object, $Group ) {
269
+ $is_repeatable = $Group->is_repeatable();
270
+ $meta = array();
271
+ $fields = $Group->get_fields();
272
+ $value_by_fields = array();
273
  foreach ( $fields as $Field ) {
274
+ if ( $Field->get_attribute( 'allow-multiple-data' ) ) {
275
+ $meta[0][$Field->get( 'name' )] = array();
276
+ } else {
277
+ $meta[0][$Field->get( 'name' )] = '';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
278
  }
279
+ }
280
+ $default_meta = $meta[0];
281
+ foreach ( $fields as $Field ) {
282
+ $value_by_field = self::get_value_by_field( $object, $Field, $is_repeatable );
283
+ foreach ( $value_by_field as $i => $value ) {
284
+ $meta[$i][$Field->get( 'name' )] = $value;
 
 
 
 
 
 
 
 
 
 
285
  }
286
  }
287
+ foreach ( $meta as $i => $value ) {
288
+ $meta[$i] = array_merge( $default_meta, $value );
289
+ }
290
+ return $meta;
291
  }
292
 
293
  /**
294
  * そのフィールドのメタデータを取得
295
  *
296
+ * @param WP_Post|WP_User $object
297
  * @param array $field
298
  * @param bool $is_repeatable このフィールドが所属するグループが repeat かどうか
299
  * @return mixed $post_meta
300
  */
301
+ protected static function get_value_by_field( $object, $Field, $is_repeatable ) {
302
  $field_name = $Field->get( 'name' );
303
  if ( !$field_name ) {
304
  return;
305
  }
306
+
307
+ $Meta = new Smart_Custom_Fields_Meta( $object );
308
+
309
+ // ループ内の複数値項目の場合
 
 
310
  $field_type = $Field->get_attribute( 'type' );
311
+ $repeat_multiple_data = self::get_repeat_multiple_data( $object );
312
+ if ( is_array( $repeat_multiple_data ) && isset( $repeat_multiple_data[$field_name] ) ) {
313
+ $_meta = $Meta->get( $field_name );
314
+ $start = 0;
315
+ foreach ( $repeat_multiple_data[$field_name] as $repeat_multiple_key => $repeat_multiple_value ) {
316
+ if ( $repeat_multiple_value === 0 ) {
317
+ $value = array();
318
+ } else {
319
+ $value = array_slice( $_meta, $start, $repeat_multiple_value );
320
+ $start += $repeat_multiple_value;
321
  }
322
+ $value = apply_filters( SCF_Config::PREFIX . 'validate-get-value', $value, $field_type );
323
+ $meta[$repeat_multiple_key] = $value;
 
324
  }
325
+ }
326
+ // それ以外
327
+ else {
328
+ if ( $Field->get_attribute( 'allow-multiple-data' ) || $is_repeatable ) {
329
+ $meta = $Meta->get( $field_name );
330
+ } else {
331
+ $meta = $Meta->get( $field_name, true );
 
 
332
  }
333
+ $meta = apply_filters( SCF_Config::PREFIX . 'validate-get-value', $meta, $field_type );
334
  }
335
+ return $meta;
 
336
  }
337
 
338
  /**
339
+ * その投稿タイプ or ロールで有効になっている SCF をキャッシュに保存
340
  *
341
+ * @param WP_Post|WP_User $object
342
  * @param array $settings_posts
343
  */
344
+ protected static function save_settings_posts_cache( $object, $settings_posts ) {
345
+ $Meta = new Smart_Custom_Fields_Meta( $object );
346
+ $type = $Meta->get_type( false );
347
+ self::$settings_posts_cache[$type] = $settings_posts;
348
  }
349
 
350
  /**
351
  * その投稿タイプで有効になっている SCF のキャッシュを取得
352
  *
353
+ * @param WP_Post|WP_User $object
354
+ * @return array|null
355
  */
356
+ public static function get_settings_posts_cache( $object ) {
357
+ $Meta = new Smart_Custom_Fields_Meta( $object );
358
+ $type = $Meta->get_type( false );
359
+ if ( isset( self::$settings_posts_cache[$type] ) ) {
360
+ return self::$settings_posts_cache[$type];
361
  }
362
+ }
363
+
364
+ /**
365
+ * SCF のキャッシュをクリア
366
+ */
367
+ public static function clear_settings_posts_cache() {
368
+ self::$settings_posts_cache = array();
369
  }
370
 
371
  /**
372
  * その投稿タイプで有効になっている SCF を取得
373
  *
374
+ * @param WP_Post|WP_User $object
375
  * @return array $settings
376
  */
377
+ public static function get_settings_posts( $object ) {
378
+ $settings_posts = array();
379
+ if ( self::get_settings_posts_cache( $object ) !== null ) {
380
+ self::debug_cache_message( "use settings posts cache." );
381
+ return self::get_settings_posts_cache( $object );
382
  } else {
383
+ self::debug_cache_message( "dont use settings posts cache..." );
384
+ }
385
+
386
+ $Meta = new Smart_Custom_Fields_Meta( $object );
387
+ $type = $Meta->get_type( false );
388
+
389
+ switch ( $Meta->get_meta_type() ) {
390
+ case 'post' :
391
+ $key = SCF_Config::PREFIX . 'condition';
392
+ break;
393
+ case 'user' :
394
+ $key = SCF_Config::PREFIX . 'roles';
395
+ break;
396
+ default :
397
+ $key = '';
398
+ }
399
+
400
+ if ( !empty( $key ) && !empty( $type ) ) {
401
+ $settings_posts = get_posts( array(
402
+ 'post_type' => SCF_Config::NAME,
403
+ 'posts_per_page' => -1,
404
+ 'order' => 'ASC',
405
+ 'order_by' => 'menu_order',
406
+ 'meta_query' => array(
407
+ array(
408
+ 'key' => $key,
409
+ 'compare' => 'LIKE',
410
+ 'value' => $type,
411
+ ),
412
  ),
413
+ ) );
414
+ }
415
+ self::save_settings_posts_cache( $object, $settings_posts );
416
  return $settings_posts;
417
  }
418
 
419
  /**
420
  * Setting オブジェクトをキャッシュに保存
421
  *
422
+ * @param int $settings_post_id
423
+ * @param WP_post|WP_User $object
424
  * @param Smart_Custom_Fields_Setting $Setting
425
  */
426
+ protected static function save_settings_cache( $settings_post_id, $Setting, $object = null ) {
427
+ if ( !is_null( $object ) ) {
428
+ $Meta = new Smart_Custom_Fields_Meta( $object );
429
+ $id = $Meta->get_id();
430
+ $meta_type = $Meta->get_meta_type();
431
+ }
432
+ if ( !empty( $meta_type ) && !empty( $id ) ) {
433
+ self::$settings_cache[$settings_post_id][$meta_type . '_' . $id] = $Setting;
434
  } else {
435
+ self::$settings_cache[$settings_post_id][0] = $Setting;
436
  }
437
  }
438
 
439
  /**
440
  * Setting オブジェクトキャッシュを取得
441
+ * その SCF が存在しないとき ... null
442
+ * その SCF が存在する
443
+ * 指定した $meta_type + $id のものが無い
444
+ * 全般のものがある ... Smart_Custom_Fields_Setting
445
+ * 全般のものが無い ... false
446
+ * 指定した $meta_type + $id のものがあるとき ... Smart_Custom_Fields_Setting
447
  *
448
+ * @param int $settings_post_id
449
+ * @param WP_post|WP_User $object
450
+ * @return Smart_Custom_Fields_Setting|false|null
451
  */
452
+ public static function get_settings_cache( $settings_post_id, $object = null ) {
453
+ if ( !is_null( $object ) ) {
454
+ $Meta = new Smart_Custom_Fields_Meta( $object );
455
+ $id = $Meta->get_id();
456
+ $meta_type = $Meta->get_meta_type();
 
 
457
  }
458
+
459
+ if ( isset( self::$settings_cache[$settings_post_id] ) ) {
460
+ $settings_cache = self::$settings_cache[$settings_post_id];
461
+ if ( !empty( $id ) && !empty( $meta_type ) && isset( $settings_cache[$meta_type . '_' . $id] ) ) {
462
+ return $settings_cache[$meta_type . '_' . $id];
463
+ }
464
+ if ( isset( $settings_cache[0] ) ) {
465
+ return $settings_cache[0];
466
  }
467
+ return false;
468
  }
469
+ }
470
+
471
+ /**
472
+ * Setting オブジェクトキャッシュをクリア
473
+ */
474
+ public static function clear_settings_cache() {
475
+ self::$settings_cache = array();
476
  }
477
 
478
  /**
479
  * Setting オブジェクトの配列を取得
480
  *
481
+ * @param WP_Post|WP_User $object
 
482
  * @return array $settings
483
  */
484
+ public static function get_settings( $object ) {
485
+ $Meta = new Smart_Custom_Fields_Meta( $object );
486
+ $id = $Meta->get_id();
487
+ $type = $Meta->get_type( false );
488
+ $meta_type = $Meta->get_meta_type();
489
+
490
+ $settings = array();
491
+ if ( !empty( $type ) ) {
492
+ $settings_posts = self::get_settings_posts( $object );
493
+ if ( $meta_type === 'post' ) {
494
+ $settings = self::get_settings_for_post( $object, $settings_posts );
495
+ }
496
+ elseif ( $meta_type === 'user' ) {
497
+ $settings = self::get_settings_for_profile( $object, $settings_posts );
498
+ }
499
  }
500
+ $settings = apply_filters( SCF_Config::PREFIX . 'register-fields', $settings, $type, $id, $meta_type );
501
+ return $settings;
502
+ }
503
+
504
+ /**
505
+ * Setting オブジェクトの配列を取得(投稿用)
506
+ *
507
+ * @param WP_Post $object
508
+ * @param array $settings_posts
509
+ * @return array
510
+ */
511
+ protected static function get_settings_for_post( $object, $settings_posts ) {
512
  $settings = array();
 
513
  foreach ( $settings_posts as $settings_post ) {
514
+ if ( self::get_settings_cache( $settings_post->ID ) !== null ) {
515
+ self::debug_cache_message( "use settings cache. [id: {$settings_post->ID}]" );
516
+ $Setting = self::get_settings_cache( $settings_post->ID, $object );
517
+ if ( $Setting ) {
518
+ $settings[$settings_post->ID] = $Setting;
519
+ }
520
+ continue;
521
+ }
522
+ self::debug_cache_message( "dont use settings cache... [SCF ID: {$settings_post->ID}] [post_type: {$object->post_type}] [Post ID: {$object->ID}]" );
523
  $condition_post_ids_raw = get_post_meta(
524
  $settings_post->ID,
525
  SCF_Config::PREFIX . 'condition-post-ids',
530
  foreach ( $condition_post_ids_raw as $condition_post_id ) {
531
  $condition_post_id = trim( $condition_post_id );
532
  $Setting = SCF::add_setting( $settings_post->ID, $settings_post->post_title );
533
+ if ( $object->ID == $condition_post_id ) {
534
+ $settings[$settings_post->ID] = $Setting;
535
  }
536
+ $Post = get_post( $condition_post_id );
537
+ if ( empty( $Post ) ) {
538
+ $Post = new stdClass();
539
+ $Post->ID = $condition_post_id;
540
+ $Post = new WP_Post( $Post );
541
+ }
542
+ self::save_settings_cache( $settings_post->ID, $Setting, $Post );
543
  }
544
  } else {
545
  $Setting = SCF::add_setting( $settings_post->ID, $settings_post->post_title );
546
+ $settings[$settings_post->ID] = $Setting;
547
+ self::save_settings_cache( $settings_post->ID, $Setting );
548
+ }
549
+ }
550
+ return $settings;
551
+ }
552
+
553
+ /**
554
+ * Setting オブジェクトの配列を取得(プロフィール用)
555
+ *
556
+ * @param WP_User $object
557
+ * @param array $settings_posts
558
+ * @return array
559
+ */
560
+ protected static function get_settings_for_profile( $object, $settings_posts ) {
561
+ $settings = array();
562
+ foreach ( $settings_posts as $settings_post ) {
563
+ if ( self::get_settings_cache( $settings_post->ID ) !== null ) {
564
+ self::debug_cache_message( "use settings cache. [id: {$settings_post->ID}]" );
565
+ $settings[] = self::get_settings_cache( $settings_post->ID );
566
+ continue;
567
  }
568
+ self::debug_cache_message( "dont use settings cache... [id: {$settings_post->ID}]" );
569
+ $Setting = SCF::add_setting( $settings_post->ID, $settings_post->post_title );
570
+ $settings[] = $Setting;
571
+ self::save_settings_cache( $settings_post->ID, $Setting );
572
  }
 
573
  return $settings;
574
  }
575
 
576
  /**
577
  * 繰り返しに設定された複数許可フィールドデータの区切り識別用データをキャッシュに保存
578
  *
579
+ * @param WP_Post|WP_User $object
580
  * @param mixed $repeat_multiple_data
581
  */
582
+ protected static function save_repeat_multiple_data_cache( $object, $repeat_multiple_data ) {
583
+ $Meta = new Smart_Custom_Fields_Meta( $object );
584
+ $id = $Meta->get_id();
585
+ $type = $Meta->get_type();
586
+ if ( !empty( $id ) && !empty( $type ) ) {
587
+ self::$repeat_multiple_data_cache[$type . '_' . $id] = $repeat_multiple_data;
588
+ }
589
+ }
590
+
591
+ /**
592
+ * 繰り返しに設定された複数許可フィールドデータの区切り識別用データをキャッシュから取得
593
+ *
594
+ * @param WP_Post|WP_User $object
595
+ * @return mixed
596
+ */
597
+ protected static function get_repeat_multiple_data_cache( $object ) {
598
+ $Meta = new Smart_Custom_Fields_Meta( $object );
599
+ $id = $Meta->get_id();
600
+ $type = $Meta->get_type();
601
+ if ( !empty( $id ) && !empty( $type ) ) {
602
+ if ( isset( self::$repeat_multiple_data_cache[$type . '_' . $id] ) ) {
603
+ return self::$repeat_multiple_data_cache[$type . '_' . $id];
604
+ }
605
+ }
606
+ }
607
+
608
+ /**
609
+ * 繰り返しに設定された複数許可フィールドデータの区切り識別用データのキャッシュをクリア
610
+ */
611
+ public static function clear_repeat_multiple_data_cache() {
612
+ self::$repeat_multiple_data_cache = array();
613
  }
614
 
615
  /**
616
  * 繰り返しに設定された複数許可フィールドデータの区切り識別用データを取得
617
  *
618
+ * @param WP_Post|WP_User $object
619
+ * @return array
620
  */
621
+ public static function get_repeat_multiple_data( $object ) {
622
  $repeat_multiple_data = array();
623
+ if ( self::get_repeat_multiple_data_cache( $object ) ) {
624
+ return self::get_repeat_multiple_data_cache( $object );
625
  }
626
+
627
+ $Meta = new Smart_Custom_Fields_Meta( $object );
628
+ $_repeat_multiple_data = $Meta->get( SCF_Config::PREFIX . 'repeat-multiple-data', true );
629
+ if ( !empty( $_repeat_multiple_data ) ) {
630
+ $repeat_multiple_data = $_repeat_multiple_data;
631
  }
632
+
633
+ self::save_repeat_multiple_data_cache( $object, $repeat_multiple_data );
634
  return $repeat_multiple_data;
635
  }
636
 
696
  * @return Smart_Custom_Fields_Field_Base
697
  */
698
  public static function get_field( $post_type, $field_name ) {
699
+ $settings = self::get_settings( get_post( get_the_ID() ) );
700
  foreach ( $settings as $Setting ) {
701
  $groups = $Setting->get_groups();
702
  foreach ( $groups as $Group ) {
734
  return new Smart_Custom_Fields_Setting( $id, $title );
735
  }
736
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
737
  /**
738
  * キャッシュの使用状況を画面に表示
739
  */
classes/controller/class.editor.php CHANGED
@@ -1,20 +1,20 @@
1
  <?php
2
  /**
3
  * Smart_Custom_Fields_Controller_Editor
4
- * Version : 1.0.1
5
  * Author : Takashi Kitajima
6
  * Created : September 23, 2014
7
- * Modified : March 13, 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
  * 各フォーム部品のオブジェクトを格納する配列
@@ -64,8 +64,7 @@ class Smart_Custom_Fields_Controller_Editor {
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, $post->ID );
69
  foreach ( $settings as $Setting ) {
70
  add_meta_box(
71
  SCF_Config::PREFIX . 'custom-field-' . $Setting->get_id(),
@@ -82,12 +81,12 @@ class Smart_Custom_Fields_Controller_Editor {
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;
@@ -98,9 +97,9 @@ class Smart_Custom_Fields_Controller_Editor {
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
  // ループを抜けたらカウントをもとに戻す
@@ -135,109 +134,56 @@ class Smart_Custom_Fields_Controller_Editor {
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, $post_id );
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
  // ループのときは、ループの分だけグループを追加する
@@ -247,21 +193,22 @@ class Smart_Custom_Fields_Controller_Editor {
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
  }
@@ -281,32 +228,35 @@ class Smart_Custom_Fields_Controller_Editor {
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
  }
@@ -316,16 +266,16 @@ class Smart_Custom_Fields_Controller_Editor {
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
  }
@@ -333,12 +283,15 @@ class Smart_Custom_Fields_Controller_Editor {
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(
@@ -362,7 +315,6 @@ class Smart_Custom_Fields_Controller_Editor {
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' );
@@ -372,13 +324,13 @@ class Smart_Custom_Fields_Controller_Editor {
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 {
@@ -388,7 +340,7 @@ class Smart_Custom_Fields_Controller_Editor {
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;
@@ -412,4 +364,14 @@ class Smart_Custom_Fields_Controller_Editor {
412
  }
413
  echo '</table></div>';
414
  }
 
 
 
 
 
 
 
 
 
 
415
  }
1
  <?php
2
  /**
3
  * Smart_Custom_Fields_Controller_Editor
4
+ * Version : 1.0.2
5
  * Author : Takashi Kitajima
6
  * Created : September 23, 2014
7
+ * Modified : March 16, 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
+ * meta_data 格納用。何度も関数呼び出ししなくて良いように保存
15
  * @var array
16
  */
17
+ protected $meta_data = array();
18
 
19
  /**
20
  * 各フォーム部品のオブジェクトを格納する配列
64
  * @param WP_Post $post
65
  */
66
  public function add_meta_boxes( $post_type, $post ) {
67
+ $settings = SCF::get_settings( $post );
 
68
  foreach ( $settings as $Setting ) {
69
  add_meta_box(
70
  SCF_Config::PREFIX . 'custom-field-' . $Setting->get_id(),
81
  /**
82
  * 投稿画面にカスタムフィールドを表示
83
  *
84
+ * @param WP_Post|WP_User $object
85
  * @param array $callback_args カスタムフィールドの設定情報
86
  */
87
+ public function display_meta_box( $object, $callback_args ) {
88
  $groups = $callback_args['args'];
89
+ $tables = $this->get_tables( $object, $groups );
90
 
91
  printf( '<div class="%s">', esc_attr( SCF_Config::PREFIX . 'meta-box' ) );
92
  $index = 0;
97
  '<div class="%s">',
98
  esc_attr( SCF_Config::PREFIX . 'meta-box-repeat-tables' )
99
  );
100
+ $this->display_tr( $object, $is_repeatable, $Group->get_fields() );
101
  }
102
+ $this->display_tr( $object, $is_repeatable, $Group->get_fields(), $index );
103
 
104
  // ループの場合は添字をカウントアップ
105
  // ループを抜けたらカウントをもとに戻す
134
  return;
135
  }
136
 
137
+ $this->save( $_POST, get_post( $post_id ) );
138
+ }
139
+
140
+ /**
141
+ * 送信されたデータを保存
142
+ *
143
+ * @param array $data
144
+ * @param WP_Post|WP_User $object
145
+ */
146
+ protected function save( $data, $object ) {
147
  check_admin_referer(
148
  SCF_Config::NAME . '-fields',
149
  SCF_Config::PREFIX . 'fields-nonce'
150
  );
151
 
152
+ $Meta = new Smart_Custom_Fields_Meta( $object );
153
+ $Meta->save( $_POST );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
154
  }
155
 
156
  /**
157
  * メタデータの取得
158
  *
159
+ * @param int $id 投稿ID or ユーザーID
160
  * @return array
161
  */
162
+ protected function get_all_meta( $id ) {
163
+ $meta_data = $this->meta_data;
164
+ if ( empty( $meta_data ) ) {
165
+ $meta_data = get_post_meta( $id );
166
+ if ( empty( $meta_data ) ) {
167
  return array();
168
  }
169
+ $this->meta_data = $meta_data;
170
  }
171
+ return $this->meta_data;
172
  }
173
 
174
  /**
175
  * カスタムフィールドを出力するための配列を生成
176
  *
177
+ * @param WP_Post|WP_User $object
178
  * @param array $groups カスタムフィールド設定ページで保存した設定
179
  * @return array $tables カスタムフィールド表示用のテーブルを出力するための配列
180
  */
181
+ protected function get_tables( $object, $groups ) {
182
+ $Meta = new Smart_Custom_Fields_Meta( $object );
183
+ $id = $Meta->get_id();
184
+
185
+ $meta_data = $this->get_all_meta( $id );
186
+ $repeat_multiple_data = SCF::get_repeat_multiple_data( $object );
187
  $tables = array();
188
  foreach ( $groups as $Group ) {
189
  // ループのときは、ループの分だけグループを追加する
193
  $fields = $Group->get_fields();
194
  foreach ( $fields as $Field ) {
195
  $field_name = $Field->get( 'name' );
196
+ if ( isset( $meta_data[$field_name] ) && is_array( $meta_data[$field_name] ) ) {
197
+ $meta = $meta_data[$field_name];
198
+ $meta_count = count( $meta );
199
  // 同名のカスタムフィールドが複数のとき(チェックボックス or ループ)
200
+ if ( $meta_count > 1 ) {
201
  // チェックボックスの場合
202
+ if ( is_array( $repeat_multiple_data ) && isset( $repeat_multiple_data[$field_name] ) ) {
203
  $repeat_multiple_data_count = count( $repeat_multiple_data[$field_name] );
204
  if ( $loop_count < $repeat_multiple_data_count )
205
  $loop_count = $repeat_multiple_data_count;
206
  }
207
  // チェックボックス以外
208
  else {
209
+ if ( $loop_count < $meta_count ) {
210
+ $loop_count = $meta_count;
211
+ }
212
  }
213
  }
214
  }
228
  /**
229
  * 複数許可フィールドのメタデータを取得
230
  *
231
+ * @param WP_Post|WP_Post $object
232
  * @param string $field_name
233
  * @param int $index
234
  * @return array or null
235
  */
236
+ protected function get_multiple_data_field_value( $object, $field_name, $index ) {
237
+ $Meta = new Smart_Custom_Fields_Meta( $object );
238
+ $id = $Meta->get_id();
239
+
240
+ $meta_data = $this->get_all_meta( $id );
241
+ $repeat_multiple_data = SCF::get_repeat_multiple_data( $object );
242
  $value = null;
243
+ if ( isset( $meta_data[$field_name] ) && is_array( $meta_data[$field_name] ) ) {
244
+ $value = $meta_data[$field_name];
245
  // ループのとき
246
+ if ( is_array( $repeat_multiple_data ) && isset( $repeat_multiple_data[$field_name] ) ) {
247
  $now_num = 0;
248
+ if ( is_array( $repeat_multiple_data[$field_name] ) && isset( $repeat_multiple_data[$field_name][$index] ) ) {
249
  $now_num = $repeat_multiple_data[$field_name][$index];
250
  }
251
 
252
  // 自分($index)より前の個数の合計が指す index が start
253
  $_temp = array_slice( $repeat_multiple_data[$field_name], 0, $index );
254
+ $sum = array_sum( $_temp );
255
  $start = $sum;
256
 
257
  $value = null;
258
  if ( $now_num ) {
259
+ $value = array_slice( $meta_data[$field_name], $start, $now_num );
260
  }
261
  }
262
  }
266
  /**
267
  * 非複数許可フィールドのメタデータを取得
268
  *
269
+ * @param int $id 投稿ID or ユーザーID
270
  * @param string $field_name
271
  * @param int $index
272
  * @return string or null
273
  */
274
+ protected function get_single_data_field_value( $id, $field_name, $index ) {
275
+ $meta_data = $this->get_all_meta( $id );
276
  $value = null;
277
+ if ( isset( $meta_data[$field_name][$index] ) ) {
278
+ $value = $meta_data[$field_name][$index];
279
  }
280
  return $value;
281
  }
283
  /**
284
  * カスタムフィールド表示 table で使用する各 tr を出力
285
  *
286
+ * @param WP_Post|WP_User $object
287
  * @param bool $is_repeat
288
  * @param array $fields
289
  * @param int, null $index
290
  */
291
+ protected function display_tr( $object, $is_repeat, $fields, $index = null ) {
292
+ $Meta = new Smart_Custom_Fields_Meta( $object );
293
+ $id = $Meta->get_id();
294
+
295
  $btn_repeat = '';
296
  if ( $is_repeat ) {
297
  $btn_repeat = sprintf(
315
  );
316
 
317
  foreach ( $fields as $Field ) {
 
318
  $display_name = $Field->get_attribute( 'display-name' );
319
  $default = $Field->get( 'default' );
320
  $field_name = $Field->get( 'name' );
324
  }
325
 
326
  // 複数値許可フィールドのとき
327
+ $post_status = $this->get_post_status( $id );
328
  if ( $Field->get_attribute( 'allow-multiple-data' ) ) {
329
  $value = array();
330
  if ( !SCF::is_empty( $default ) && ( $post_status === 'auto-draft' || is_null( $index ) ) ) {
331
  $value = SCF::choices_eol_to_array( $default );
332
  }
333
+ $_value = $this->get_multiple_data_field_value( $object, $field_name, $index );
334
  }
335
  // 複数不値許可フィールドのとき
336
  else {
340
  $value = $default;
341
  }
342
  }
343
+ $_value = $this->get_single_data_field_value( $id, $field_name, $index );
344
  }
345
  if ( !is_null( $_value ) ) {
346
  $value = $_value;
364
  }
365
  echo '</table></div>';
366
  }
367
+
368
+ /**
369
+ * 投稿ステータスを返す
370
+ *
371
+ * @param int $post_id
372
+ * @return string
373
+ */
374
+ protected function get_post_status( $post_id ) {
375
+ return get_post_status( $post_id );
376
+ }
377
  }
classes/controller/class.profile.php ADDED
@@ -0,0 +1,100 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Smart_Custom_Fields_Controller_Profile
4
+ * Version : 1.0.0
5
+ * Author : Takashi Kitajima
6
+ * Created : March 16, 2015
7
+ * Modified :
8
+ * License : GPLv2
9
+ * License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
+ */
11
+ class Smart_Custom_Fields_Controller_Profile extends Smart_Custom_Fields_Controller_Editor {
12
+
13
+ /**
14
+ * __construct
15
+ */
16
+ public function __construct() {
17
+ add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
18
+ add_action( 'show_user_profile', array( $this, 'user_profile' ) );
19
+ add_action( 'edit_user_profile', array( $this, 'user_profile' ) );
20
+ add_action( 'personal_options_update', array( $this, 'update' ) );
21
+ add_action( 'edit_user_profile_update', array( $this, 'update' ) );
22
+ }
23
+
24
+ /**
25
+ * 投稿画面用の css、js、翻訳ファイルのロード
26
+ *
27
+ * @param string $hook
28
+ */
29
+ public function admin_enqueue_scripts( $hook ) {
30
+ parent::admin_enqueue_scripts( $hook );
31
+ wp_enqueue_style(
32
+ SCF_Config::PREFIX . 'profile',
33
+ plugins_url( SCF_Config::NAME ) . '/css/profile.css'
34
+ );
35
+ }
36
+
37
+ /**
38
+ * user_profile
39
+ */
40
+ public function user_profile( $user ) {
41
+ printf( '<h3>%s</h3>', esc_html__( 'Custom Fields', 'smart-custom-fields' ) );
42
+ $settings = SCF::get_settings( $user );
43
+ foreach ( $settings as $Setting ) {
44
+ $callback_args['args'] = $Setting->get_groups();
45
+ ?>
46
+ <table class="form-table">
47
+ <tr>
48
+ <th scope="row"><?php echo esc_html( $Setting->get_title() ); ?></th>
49
+ <td><?php $this->display_meta_box( $user, $callback_args ); ?></td>
50
+ </tr>
51
+ </table>
52
+ <?php
53
+ }
54
+ }
55
+
56
+ /**
57
+ * 投稿画面のカスタムフィールドからのメタデータを保存
58
+ *
59
+ * @param int $user_id
60
+ */
61
+ public function update( $user_id ) {
62
+ if ( !current_user_can( 'edit_user', $user_id ) ) {
63
+ return;
64
+ }
65
+ if ( !isset( $_POST[SCF_Config::NAME] ) ) {
66
+ return;
67
+ }
68
+
69
+ $user_data = get_userdata( $user_id );
70
+ $this->save( $_POST, get_userdata( $user_id ) );
71
+ }
72
+
73
+ /**
74
+ * メタデータの取得
75
+ *
76
+ * @param int $id 投稿ID or ユーザーID
77
+ * @return array
78
+ */
79
+ protected function get_all_meta( $id ) {
80
+ $meta_data = $this->meta_data;
81
+ if ( empty( $meta_data ) ) {
82
+ $meta_data = get_user_meta( $id );
83
+ if ( empty( $meta_data ) ) {
84
+ return array();
85
+ }
86
+ $this->meta_data = $meta_data;
87
+ }
88
+ return $this->meta_data;
89
+ }
90
+
91
+ /**
92
+ * 投稿ステータスを返す(ユーザーにステータスは無いので必ず 'auto-draft' を返すこと)
93
+ *
94
+ * @param int $user_id
95
+ * @return string 'auto-draft'
96
+ */
97
+ protected function get_post_status( $user_id ) {
98
+ return 'auto-draft';
99
+ }
100
+ }
classes/controller/class.settings.php CHANGED
@@ -78,9 +78,16 @@ class Smart_Custom_Fields_Controller_Settings {
78
  SCF_Config::NAME
79
  );
80
  add_meta_box(
81
- SCF_Config::PREFIX . 'meta-box-condition',
82
- __( 'Display conditions', 'smart-custom-fields' ),
83
- array( $this, 'display_meta_box_condition' ),
 
 
 
 
 
 
 
84
  SCF_Config::NAME,
85
  'side'
86
  );
@@ -179,11 +186,11 @@ class Smart_Custom_Fields_Controller_Settings {
179
  }
180
 
181
  /**
182
- * メタボックスの表示条件を設定するメタボックスを表示
183
  */
184
- public function display_meta_box_condition() {
185
  $post_types = get_post_types( array(
186
- 'show_ui' => true,
187
  ), 'objects' );
188
  unset( $post_types['attachment'] );
189
  unset( $post_types[SCF_Config::NAME] );
@@ -215,6 +222,30 @@ class Smart_Custom_Fields_Controller_Settings {
215
  );
216
  }
217
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
218
  /**
219
  * 設定を保存
220
  *
@@ -282,5 +313,11 @@ class Smart_Custom_Fields_Controller_Settings {
282
  } else {
283
  update_post_meta( $post_id, SCF_Config::PREFIX . 'condition-post-ids', $_POST[SCF_Config::PREFIX . 'condition-post-ids'] );
284
  }
 
 
 
 
 
 
285
  }
286
  }
78
  SCF_Config::NAME
79
  );
80
  add_meta_box(
81
+ SCF_Config::PREFIX . 'meta-box-condition-post',
82
+ __( 'Display conditions ( Post )', 'smart-custom-fields' ),
83
+ array( $this, 'display_meta_box_condition_post' ),
84
+ SCF_Config::NAME,
85
+ 'side'
86
+ );
87
+ add_meta_box(
88
+ SCF_Config::PREFIX . 'meta-box-condition-profile',
89
+ __( 'Display conditions ( Profile )', 'smart-custom-fields' ),
90
+ array( $this, 'display_meta_box_condition_profile' ),
91
  SCF_Config::NAME,
92
  'side'
93
  );
186
  }
187
 
188
  /**
189
+ * メタボックスの表示条件を設定するメタボックス(投稿用)を表示
190
  */
191
+ public function display_meta_box_condition_post() {
192
  $post_types = get_post_types( array(
193
+ 'show_ui' => true,
194
  ), 'objects' );
195
  unset( $post_types['attachment'] );
196
  unset( $post_types[SCF_Config::NAME] );
222
  );
223
  }
224
 
225
+ /**
226
+ * メタボックスの表示条件を設定するメタボックス(プロフィール用)を表示
227
+ */
228
+ public function display_meta_box_condition_profile() {
229
+ $roles = get_editable_roles();
230
+ $conditions = get_post_meta( get_the_ID(), SCF_Config::PREFIX . 'roles', true );
231
+ $profile_field = '';
232
+ foreach ( $roles as $name => $role ) {
233
+ $current = ( is_array( $conditions ) && in_array( $name, $conditions ) ) ? $name : false;
234
+ $profile_field .= sprintf(
235
+ '<label><input type="checkbox" name="%s" value="%s" %s /> %s</label>',
236
+ esc_attr( SCF_Config::PREFIX . 'roles[]' ),
237
+ esc_attr( $name ),
238
+ checked( $current, $name, false ),
239
+ esc_html__( $role['name'], 'smart-custom-fields' )
240
+ );
241
+ }
242
+ printf(
243
+ '<p><b>%s</b>%s</p>',
244
+ esc_html__( 'Roles', 'smart-custom-fields' ),
245
+ $profile_field
246
+ );
247
+ }
248
+
249
  /**
250
  * 設定を保存
251
  *
313
  } else {
314
  update_post_meta( $post_id, SCF_Config::PREFIX . 'condition-post-ids', $_POST[SCF_Config::PREFIX . 'condition-post-ids'] );
315
  }
316
+
317
+ if ( !isset( $_POST[SCF_Config::PREFIX . 'roles'] ) ) {
318
+ delete_post_meta( $post_id, SCF_Config::PREFIX . 'roles' );
319
+ } else {
320
+ update_post_meta( $post_id, SCF_Config::PREFIX . 'roles', $_POST[SCF_Config::PREFIX . 'roles'] );
321
+ }
322
  }
323
  }
classes/fields/class.field-relation.php CHANGED
@@ -1,10 +1,10 @@
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
  */
@@ -18,6 +18,7 @@ class Smart_Custom_Fields_Field_Relation extends Smart_Custom_Fields_Field_Base
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' ),
@@ -44,7 +45,7 @@ class Smart_Custom_Fields_Field_Relation extends Smart_Custom_Fields_Field_Base
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',
@@ -100,7 +101,7 @@ class Smart_Custom_Fields_Field_Relation extends Smart_Custom_Fields_Field_Base
100
  $posts_per_page = get_option( 'posts_per_page' );
101
 
102
  // 選択肢
103
- $choices_posts = get_posts( array(
104
  'post_type' => $post_type,
105
  'order' => 'ASC',
106
  'orderby' => 'ID',
@@ -119,8 +120,9 @@ class Smart_Custom_Fields_Field_Relation extends Smart_Custom_Fields_Field_Base
119
  $selected_posts = array();
120
  if ( !empty( $value ) && is_array( $value ) ) {
121
  foreach ( $value as $post_id ) {
122
- if ( get_post_status( $post_id ) !== 'publish' )
123
  continue;
 
124
  $post_title = get_the_title( $post_id );
125
  if ( empty( $post_title ) ) {
126
  $post_title = '&nbsp;';
@@ -187,7 +189,7 @@ class Smart_Custom_Fields_Field_Relation extends Smart_Custom_Fields_Field_Base
187
  <td>
188
  <?php
189
  $post_types = get_post_types( array(
190
- 'show_ui' => true,
191
  ), 'objects' );
192
  unset( $post_types['attachment'] );
193
  unset( $post_types[SCF_Config::NAME] );
@@ -215,4 +217,25 @@ class Smart_Custom_Fields_Field_Relation extends Smart_Custom_Fields_Field_Base
215
  </tr>
216
  <?php
217
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
218
  }
1
  <?php
2
  /**
3
  * Smart_Custom_Fields_Field_Relation
4
+ * Version : 1.1.1
5
  * Author : Takashi Kitajima
6
  * Created : October 7, 2014
7
+ * Modified : March 19, 2015
8
  * License : GPLv2
9
  * License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
  */
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
+ add_filter( 'smart-cf-validate-get-value', array( $this, 'validate_get_value' ), 10, 2 );
22
  return array(
23
  'type' => 'relation',
24
  'display-name' => __( 'Relation', 'smart-custom-fields' ),
45
  * @param string $hook
46
  */
47
  public function admin_enqueue_scripts( $hook ) {
48
+ if ( in_array( $hook, array( 'post-new.php', 'post.php', 'user-edit.php', 'profile.php' ) ) ) {
49
  wp_enqueue_script(
50
  SCF_Config::PREFIX . 'editor-relation',
51
  plugins_url( SCF_Config::NAME ) . '/js/editor-relation.js',
101
  $posts_per_page = get_option( 'posts_per_page' );
102
 
103
  // 選択肢
104
+ $choices_posts = get_posts( array(
105
  'post_type' => $post_type,
106
  'order' => 'ASC',
107
  'orderby' => 'ID',
120
  $selected_posts = array();
121
  if ( !empty( $value ) && is_array( $value ) ) {
122
  foreach ( $value as $post_id ) {
123
+ if ( get_post_status( $post_id ) !== 'publish' ) {
124
  continue;
125
+ }
126
  $post_title = get_the_title( $post_id );
127
  if ( empty( $post_title ) ) {
128
  $post_title = '&nbsp;';
189
  <td>
190
  <?php
191
  $post_types = get_post_types( array(
192
+ 'show_ui' => true,
193
  ), 'objects' );
194
  unset( $post_types['attachment'] );
195
  unset( $post_types[SCF_Config::NAME] );
217
  </tr>
218
  <?php
219
  }
220
+
221
+ /**
222
+ * メタデータの表示時にバリデート
223
+ *
224
+ * @param array $value
225
+ * @param string $field_type
226
+ * @return array
227
+ */
228
+ public function validate_get_value( $value, $field_type ) {
229
+ if ( $field_type === $this->get_attribute( 'type' ) ) {
230
+ $validated_value = array();
231
+ foreach ( $value as $post_id ) {
232
+ if ( get_post_status( $post_id ) !== 'publish' ) {
233
+ continue;
234
+ }
235
+ $validated_value[] = $post_id;
236
+ }
237
+ $value = $validated_value;
238
+ }
239
+ return $value;
240
+ }
241
  }
classes/fields/class.field-wysiwyg.php CHANGED
@@ -1,10 +1,10 @@
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
  */
@@ -20,6 +20,7 @@ class Smart_Custom_Fields_Field_Wysiwyg extends Smart_Custom_Fields_Field_Base {
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' ),
@@ -138,4 +139,54 @@ class Smart_Custom_Fields_Field_Wysiwyg extends Smart_Custom_Fields_Field_Base {
138
  $img . __( 'Add Media' )
139
  );
140
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
141
  }
1
  <?php
2
  /**
3
  * Smart_Custom_Fields_Field_Wysiwyg
4
+ * Version : 1.1.1
5
  * Author : Takashi Kitajima
6
  * Created : October 7, 2014
7
+ * Modified : March 19, 2015
8
  * License : GPLv2
9
  * License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
  */
20
  SCF_Config::PREFIX . 'before-editor-enqueue-scripts',
21
  array( $this, 'editor_enqueue_scripts' )
22
  );
23
+ add_filter( 'smart-cf-validate-get-value', array( $this, 'validate_get_value' ), 10, 2 );
24
  return array(
25
  'type' => 'wysiwyg',
26
  'display-name' => __( 'Wysiwyg', 'smart-custom-fields' ),
139
  $img . __( 'Add Media' )
140
  );
141
  }
142
+
143
+ /**
144
+ * メタデータの表示時にバリデート
145
+ *
146
+ * @param mixed $value
147
+ * @param string $field_type
148
+ * @return string|array
149
+ */
150
+ public function validate_get_value( $value, $field_type ) {
151
+ if ( $field_type === $this->get_attribute( 'type' ) ) {
152
+ if ( is_array( $value ) ) {
153
+ $validated_value = array();
154
+ foreach ( $value as $k => $v ) {
155
+ $validated_value[$k] = $this->add_the_content_filter( $v );
156
+ }
157
+ $value = $validated_value;
158
+ } else {
159
+ $value = $this->add_the_content_filter( $value );
160
+ }
161
+ }
162
+ return $value;
163
+ }
164
+
165
+ /**
166
+ * デフォルトで the_content に適用される関数を適用
167
+ *
168
+ * @param string $value
169
+ * @return string
170
+ */
171
+ protected function add_the_content_filter( $value ) {
172
+ if ( has_filter( 'the_content', 'wptexturize' ) ) {
173
+ $value = wptexturize( $value );
174
+ }
175
+ if ( has_filter( 'the_content', 'convert_smilies' ) ) {
176
+ $value = convert_smilies( $value );
177
+ }
178
+ if ( has_filter( 'the_content', 'convert_chars' ) ) {
179
+ $value = convert_chars( $value );
180
+ }
181
+ if ( has_filter( 'the_content', 'wpautop' ) ) {
182
+ $value = wpautop( $value );
183
+ }
184
+ if ( has_filter( 'the_content', 'shortcode_unautop' ) ) {
185
+ $value = shortcode_unautop( $value );
186
+ }
187
+ if ( has_filter( 'the_content', 'prepend_attachment' ) ) {
188
+ $value = prepend_attachment( $value );
189
+ }
190
+ return $value;
191
+ }
192
  }
classes/models/class.group.php CHANGED
@@ -37,7 +37,7 @@ class Smart_Custom_Fields_Group {
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'] );
37
  */
38
  public function __construct( $group_name = null, $repeat = false, array $_fields = array() ) {
39
  $this->name = $group_name;
40
+ $this->repeat = ( $repeat === true ) ? true : false;
41
  $fields = array();
42
  foreach ( $_fields as $field_attributes ) {
43
  $Field = SCF::get_form_field_instance( $field_attributes['type'] );
classes/models/class.meta.php ADDED
@@ -0,0 +1,295 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Smart_Custom_Fields_Meta
4
+ * Version : 1.0.0
5
+ * Author : Takashi Kitajima
6
+ * Created : March 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_Meta {
12
+
13
+ /**
14
+ * 投稿のメタデータを扱うか、ユーザーのメタデータを扱うか
15
+ * @var string post or user
16
+ */
17
+ protected $meta_type = 'post';
18
+
19
+ /**
20
+ * 投稿IDもしくはユーザーID
21
+ * @var int
22
+ */
23
+ protected $id;
24
+
25
+ /**
26
+ * 投稿タイプもしくはロール
27
+ * @var string
28
+ */
29
+ protected $type;
30
+
31
+ /**
32
+ * @param WP_Post|WP_User $object
33
+ */
34
+ public function __construct( $object ) {
35
+ if ( !function_exists( 'get_editable_roles' ) ) {
36
+ require_once( ABSPATH . '/wp-admin/includes/user.php' );
37
+ }
38
+ if ( is_a( $object, 'WP_Post' ) ) {
39
+ $this->id = $object->ID;
40
+ $this->type = $object->post_type;
41
+ $this->meta_type = 'post';
42
+ } elseif ( is_a( $object, 'WP_User' ) ) {
43
+ $this->id = $object->ID;
44
+ $this->type = $object->roles[0];
45
+ $this->meta_type = 'user';
46
+ } elseif( empty( $object ) ) {
47
+ $this->id = null;
48
+ $this->type = null;
49
+ $this->meta_type = null;
50
+ } else {
51
+ throw new Exception( sprintf( 'Invalid $object type error. $object is "%s".', get_class( $object ) ) );
52
+ }
53
+ }
54
+
55
+ /**
56
+ * メタタイプを取得
57
+ *
58
+ * @return string post or user
59
+ */
60
+ public function get_meta_type() {
61
+ return $this->meta_type;
62
+ }
63
+
64
+ /**
65
+ * 投稿IDもしくはユーザーIDを取得
66
+ *
67
+ * @return int
68
+ */
69
+ public function get_id() {
70
+ return $this->id;
71
+ }
72
+
73
+ /**
74
+ * 投稿タイプもしくはロールを取得
75
+ *
76
+ * @param bool $accept_revision 投稿タイプだった場合に、投稿タイプ revision を許可
77
+ * @return string
78
+ */
79
+ public function get_type( $accept_revision = true ) {
80
+ if ( $this->meta_type === 'post' && !$accept_revision ) {
81
+ return $this->get_public_post_type( $this->id );
82
+ }
83
+ return $this->type;
84
+ }
85
+
86
+ /**
87
+ * Post ID がリビジョンのものでも良い感じに投稿タイプを取得
88
+ *
89
+ * @param int $post_id
90
+ * @return string
91
+ */
92
+ protected function get_public_post_type( $post_id ) {
93
+ if ( $public_post_id = wp_is_post_revision( $post_id ) ) {
94
+ $post = get_post( $public_post_id );
95
+ } else {
96
+ $post = get_post( $post_id );
97
+ }
98
+ if ( !empty( $post->post_type ) ) {
99
+ return $post->post_type;
100
+ }
101
+ return $this->type;
102
+ }
103
+
104
+ /**
105
+ * メタデータを取得
106
+ *
107
+ * @param string $key メタキー
108
+ * @param bool $single false だと配列で取得、true だと文字列で取得
109
+ * @return mixed
110
+ */
111
+ public function get( $key = '', $single = false ) {
112
+ return get_metadata( $this->meta_type, $this->id, $key, $single );
113
+ }
114
+
115
+ /**
116
+ * メタデータを更新。そのメタデータが存在しない場合は追加。
117
+ *
118
+ * @param string $key メタキー
119
+ * @param mixed $value 保存する値
120
+ * @param mixed $prev_value 指定された場合、この値のものだけを上書き
121
+ * @return int|false Meta ID
122
+ */
123
+ public function update( $key, $value, $prev_value = '' ) {
124
+ $return = false;
125
+ do_action( SCF_Config::PREFIX . '-before-save-' . $this->meta_type, $this->id, $key, $value );
126
+ $is_valid = apply_filters( SCF_Config::PREFIX . '-validate-save-' . $this->meta_type, $this->id, $key, $value );
127
+ if ( $is_valid ) {
128
+ $return = update_metadata( $this->meta_type, $this->id, $key, $value, $prev_value );
129
+ }
130
+ do_action( SCF_Config::PREFIX . '-after-save-' . $this->meta_type, $this->id, $key, $value );
131
+ return $return;
132
+ }
133
+
134
+ /**
135
+ * メタデータを追加
136
+ *
137
+ * @param string $key メタキー
138
+ * @param mixed $value 保存する値
139
+ * @param bool $unique キーをユニークにするかどうか
140
+ * @return int|false Meta ID
141
+ */
142
+ public function add( $key, $value, $unique = false ) {
143
+ $return = false;
144
+ do_action( SCF_Config::PREFIX . '-before-save-' . $this->meta_type, $this->id, $key, $value );
145
+ $is_valid = apply_filters( SCF_Config::PREFIX . '-validate-save-' . $this->meta_type, $this->id, $key, $value );
146
+ if ( $is_valid ) {
147
+ $return = add_metadata( $this->meta_type, $this->id, $key, $value, $unique );
148
+ }
149
+ do_action( SCF_Config::PREFIX . '-after-save-' . $this->meta_type, $this->id, $key, $value );
150
+ return $return;
151
+ }
152
+
153
+ /**
154
+ * メタデータを削除
155
+ *
156
+ * @param string $key メタキー
157
+ * @param mixed $value 指定した場合、その値をもつメタデータのみ削除
158
+ * @return bool
159
+ */
160
+ public function delete( $key, $value = '' ) {
161
+ return delete_metadata( $this->meta_type, $this->id, $key, $value );
162
+ }
163
+
164
+ /**
165
+ * 送信されたデータをもとにメタデータを保存
166
+ *
167
+ * @param array $POST $_POST を渡すこと
168
+ */
169
+ public function save( array $POST ) {
170
+ // 繰り返しフィールドのチェックボックスは、普通のチェックボックスと混ざって
171
+ // 判別できなくなるのでわかるように保存しておく
172
+ $repeat_multiple_data = array();
173
+
174
+ // チェックボックスが未入力のときは "" がくるので、それは保存しないように判別
175
+ $multiple_data_fields = array();
176
+
177
+ switch ( $this->meta_type ) {
178
+ case 'post' :
179
+ $object = get_post( $this->id );
180
+ break;
181
+ case 'user' :
182
+ $object = get_userdata( $this->id );
183
+ break;
184
+ default :
185
+ $object = null;
186
+ }
187
+
188
+ if ( is_null( $object ) ) {
189
+ return;
190
+ }
191
+
192
+ $this->delete( SCF_Config::PREFIX . 'repeat-multiple-data' );
193
+
194
+ if ( !isset( $POST[SCF_Config::NAME] ) ) {
195
+ return;
196
+ }
197
+
198
+ $settings = SCF::get_settings( $object );
199
+ foreach ( $settings as $Setting ) {
200
+ $groups = $Setting->get_groups();
201
+ foreach ( $groups as $Group ) {
202
+ $fields = $Group->get_fields();
203
+ foreach ( $fields as $Field ) {
204
+ $field_name = $Field->get( 'name' );
205
+ $this->delete( $field_name );
206
+ if ( $Field->get_attribute( 'allow-multiple-data' ) ) {
207
+ $multiple_data_fields[] = $field_name;
208
+ }
209
+ if ( $Group->is_repeatable() && $Field->get_attribute( 'allow-multiple-data' ) ) {
210
+ $repeat_multiple_data_fields = $POST[SCF_Config::NAME][$field_name];
211
+ foreach ( $repeat_multiple_data_fields as $values ) {
212
+ if ( is_array( $values ) ) {
213
+ $repeat_multiple_data[$field_name][] = count( $values );
214
+ } else {
215
+ $repeat_multiple_data[$field_name][] = 0;
216
+ }
217
+ }
218
+ }
219
+ }
220
+ }
221
+ }
222
+
223
+ if ( $repeat_multiple_data ) {
224
+ $this->update( SCF_Config::PREFIX . 'repeat-multiple-data', $repeat_multiple_data );
225
+ }
226
+
227
+ foreach ( $POST[SCF_Config::NAME] as $name => $values ) {
228
+ foreach ( $values as $value ) {
229
+ if ( in_array( $name, $multiple_data_fields ) && $value === '' ) {
230
+ continue;
231
+ }
232
+ if ( !is_array( $value ) ) {
233
+ $this->add( $name, $value );
234
+ } else {
235
+ foreach ( $value as $val ) {
236
+ $this->add( $name, $val );
237
+ }
238
+ }
239
+ }
240
+ }
241
+ }
242
+
243
+ /**
244
+ * 渡されたリビジョンからデータをリストア
245
+ *
246
+ * @param WP_Post $revision
247
+ */
248
+ public function restore( $revision ) {
249
+ switch ( $this->meta_type ) {
250
+ case 'post' :
251
+ $object = get_post( $this->id );
252
+ break;
253
+ default :
254
+ $object = null;
255
+ }
256
+
257
+ if ( is_null( $object ) || !is_a( $revision, 'WP_Post' ) ) {
258
+ return;
259
+ }
260
+
261
+ $settings = SCF::get_settings( $object );
262
+ foreach ( $settings as $Setting ) {
263
+ $groups = $Setting->get_groups();
264
+ foreach ( $groups as $Group ) {
265
+ $fields = $Group->get_fields();
266
+ foreach ( $fields as $Field ) {
267
+ $field_name = $Field->get( 'name' );
268
+ $this->delete( $field_name );
269
+ $value = SCF::get( $field_name, $revision->ID );
270
+ if ( is_array( $value ) ) {
271
+ foreach ( $value as $val ) {
272
+ if ( is_array( $val ) ) {
273
+ foreach ( $val as $v ) {
274
+ // ループ内複数値項目
275
+ $this->add( $field_name, $v );
276
+ }
277
+ } else {
278
+ // ループ内単一項目 or ループ外複数値項目
279
+ $this->add( $field_name, $val );
280
+ }
281
+ }
282
+ } else {
283
+ // ループ外単一項目
284
+ $this->add( $field_name, $value );
285
+ }
286
+ }
287
+ }
288
+ }
289
+
290
+ $repeat_multiple_data = SCF::get_repeat_multiple_data( $revision );
291
+ $repeat_multiple_data_name = SCF_Config::PREFIX . 'repeat-multiple-data';
292
+ $this->delete( $repeat_multiple_data_name );
293
+ $this->update( $repeat_multiple_data_name, $repeat_multiple_data );
294
+ }
295
+ }
classes/models/class.revisions.php CHANGED
@@ -1,10 +1,10 @@
1
  <?php
2
  /**
3
  * Smart_Custom_Fields_Revisions
4
- * Version : 1.1.1
5
  * Author : Takashi Kitajima
6
  * Created : September 23, 2014
7
- * Modified : March 13, 2015
8
  * License : GPLv2
9
  * License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
  */
@@ -40,41 +40,18 @@ class Smart_Custom_Fields_Revisions {
40
  * @param int $revision_id
41
  */
42
  public function wp_restore_post_revision( $post_id, $revision_id ) {
43
- $post = get_post( $post_id );
44
- $revision = get_post( $revision_id );
45
- $post_type = get_post_type();
46
 
47
- $settings = SCF::get_settings( $post_type, $post_id );
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
- }
65
- }
66
-
67
- $repeat_multiple_data_name = SCF_Config::PREFIX . 'repeat-multiple-data';
68
- delete_post_meta( $post->ID, $repeat_multiple_data_name );
69
- $repeat_multiple_data = get_post_meta( $revision->ID, $repeat_multiple_data_name, true );
70
- add_post_meta( $post->ID, $repeat_multiple_data_name, $repeat_multiple_data );
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] ) ) {
@@ -83,7 +60,7 @@ class Smart_Custom_Fields_Revisions {
83
  if ( !wp_is_post_revision( $post_id ) ) {
84
  return;
85
  }
86
- $settings = SCF::get_settings( get_post_type( $post_id ), $post_id );
87
  if ( !$settings ) {
88
  return;
89
  }
@@ -93,62 +70,12 @@ class Smart_Custom_Fields_Revisions {
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( $post_id );
104
- $settings = SCF::get_settings( $post_type, $post_id );
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
- }
147
- }
148
  }
149
 
150
  /**
151
- * プレビューのときはプレビューのメタデータを返す
152
  *
153
  * @param mixed $value
154
  * @param int $post_id
@@ -157,7 +84,7 @@ class Smart_Custom_Fields_Revisions {
157
  * @return mixed $value
158
  */
159
  public function get_post_metadata( $value, $post_id, $meta_key, $single ) {
160
- if ( $preview_id = $this->get_preview_id( $post_id ) ) {
161
  if ( $post_id !== $preview_id ) {
162
  $value = get_post_meta( $preview_id, $meta_key, $single );
163
  }
@@ -212,25 +139,26 @@ class Smart_Custom_Fields_Revisions {
212
  public function _wp_post_revision_field_debug_preview( $value, $column, $post ) {
213
  $output = '';
214
  $values = SCF::gets( $post->ID );
215
- foreach ( $values as $key => $value ) {
216
- $output .= '[' . $key . ']' . "\n";
217
  if ( is_array( $value ) ) {
218
  if ( isset( $value[0] ) && is_array( $value[0] ) ) {
219
- foreach ( $value as $sub_field_values ) {
220
- foreach ( $sub_field_values as $sub_field_key => $sub_field_value ) {
221
- $output .= $sub_field_key . " : ";
222
- if ( is_array( $sub_field_value ) ) {
223
- $output .= implode( ', ', $sub_field_value ) . "\n";
 
224
  } else {
225
- $output .= $sub_field_value . "\n";
226
  }
227
  }
228
  }
229
  } else {
230
- $output .= implode( ', ', $value ) . "\n";
231
  }
232
  } else {
233
- $output .= $value . "\n";
234
  }
235
  }
236
  return $output;
1
  <?php
2
  /**
3
  * Smart_Custom_Fields_Revisions
4
+ * Version : 1.1.2
5
  * Author : Takashi Kitajima
6
  * Created : September 23, 2014
7
+ * Modified : March 19, 2015
8
  * License : GPLv2
9
  * License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
  */
40
  * @param int $revision_id
41
  */
42
  public function wp_restore_post_revision( $post_id, $revision_id ) {
43
+ $post = get_post( $post_id );
44
+ $revision = get_post( $revision_id );
 
45
 
46
+ $Meta = new Smart_Custom_Fields_Meta( $post );
47
+ $Meta->restore( $revision );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
48
  }
49
 
50
  /**
51
  * リビジョンデータを保存
52
  * *_post_meta はリビジョンIDのときに自動的に本物IDに変換して処理してしまうので、*_metadata を使うこと
53
  *
54
+ * @param int $post_id リビジョンの投稿ID
55
  */
56
  public function wp_insert_post( $post_id ) {
57
  if ( !isset( $_POST[SCF_Config::NAME] ) ) {
60
  if ( !wp_is_post_revision( $post_id ) ) {
61
  return;
62
  }
63
+ $settings = SCF::get_settings( get_post( $post_id ) );
64
  if ( !$settings ) {
65
  return;
66
  }
70
  SCF_Config::PREFIX . 'fields-nonce'
71
  );
72
 
73
+ $Meta = new Smart_Custom_Fields_Meta( get_post( $post_id ) );
74
+ $Meta->save( $_POST );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
75
  }
76
 
77
  /**
78
+ * プレビューのときはプレビューのメタデータを返す。ただし、アイキャッチはリビジョンが無いので除外する
79
  *
80
  * @param mixed $value
81
  * @param int $post_id
84
  * @return mixed $value
85
  */
86
  public function get_post_metadata( $value, $post_id, $meta_key, $single ) {
87
+ if ( $preview_id = $this->get_preview_id( $post_id ) && $meta_key !== '_thumbnail_id' ) {
88
  if ( $post_id !== $preview_id ) {
89
  $value = get_post_meta( $preview_id, $meta_key, $single );
90
  }
139
  public function _wp_post_revision_field_debug_preview( $value, $column, $post ) {
140
  $output = '';
141
  $values = SCF::gets( $post->ID );
142
+ foreach ( $values as $field_name_or_group_name => $value ) {
143
+ $output .= sprintf( "■ %s\n", $field_name_or_group_name );
144
  if ( is_array( $value ) ) {
145
  if ( isset( $value[0] ) && is_array( $value[0] ) ) {
146
+ foreach ( $value as $i => $repeat_data_values ) {
147
+ $output .= sprintf( "- #%s\n", $i );
148
+ foreach ( $repeat_data_values as $field_name => $repeat_data_value ) {
149
+ $output .= sprintf( " %s: ", $field_name );
150
+ if ( is_array( $repeat_data_value ) ) {
151
+ $output .= sprintf( "[%s]\n", implode( ', ', $repeat_data_value ) );
152
  } else {
153
+ $output .= sprintf( "%s\n", $repeat_data_value );
154
  }
155
  }
156
  }
157
  } else {
158
+ $output .= sprintf( "[%s]\n", implode( ', ', $value ) );
159
  }
160
  } else {
161
+ $output .= $output .= sprintf( "%s\n", $value );
162
  }
163
  }
164
  return $output;
css/profile.css ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * profile.css
3
+ * Version : 1.0.0
4
+ * Author : Takashi Kitajima
5
+ * Created : March 18, 2014
6
+ * Modified :
7
+ * License : GPLv2
8
+ * License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
+ */
10
+
11
+ /** ==================================================
12
+ * .smart-cf-meta-box
13
+ */
14
+ .smart-cf-meta-box:first-child {
15
+ border-top: #ddd solid 1px;
16
+ }
17
+
18
+ /** ==================================================
19
+ * .smart-cf-meta-box-table
20
+ */
21
+ .smart-cf-meta-box-table {
22
+ background: transparent;
23
+ border-bottom: #ddd solid 1px;
24
+ padding: 10px 0;
25
+ }
css/settings.css CHANGED
@@ -173,11 +173,13 @@
173
  /** ==================================================
174
  * #smart-cf-meta-box-condition
175
  */
176
- #smart-cf-meta-box-condition b {
 
177
  display: block;
178
  margin: 0 0 5px;
179
  }
180
- #smart-cf-meta-box-condition label {
 
181
  display: block;
182
  margin: 0 0 5px;
183
  }
173
  /** ==================================================
174
  * #smart-cf-meta-box-condition
175
  */
176
+ #smart-cf-meta-box-condition-post b,
177
+ #smart-cf-meta-box-condition-profile b {
178
  display: block;
179
  margin: 0 0 5px;
180
  }
181
+ #smart-cf-meta-box-condition-post label,
182
+ #smart-cf-meta-box-condition-profile label {
183
  display: block;
184
  margin: 0 0 5px;
185
  }
js/editor-relation.js CHANGED
@@ -1,9 +1,9 @@
1
  /**
2
  * editor.js
3
- * Version : 1.0.0
4
  * Author : Takashi Kitajima
5
  * Created : September 30, 2014
6
- * Modified :
7
  * License : GPLv2
8
  * License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
  */
@@ -17,7 +17,7 @@ jQuery( function( $ ) {
17
  $( '.smart-cf-meta-box .load-relation-posts' )
18
  .data( 'click_count', 0 )
19
  .click( function() {
20
- var parent = $( this ).parents( '.smart-cf-meta-box-table' );
21
  var click_count = $( this ).data( 'click_count' );
22
  var post_types = $( this ).data( 'post-types' );
23
  var btn_load = $( this );
@@ -56,14 +56,14 @@ jQuery( function( $ ) {
56
  var choices_li = '.smart-cf-relation-children-select li';
57
  $( '.smart-cf-meta-box' ).on( 'click', choices_li, function() {
58
  var id = $( this ).data( 'id' );
59
- var parent = $( this ).parents( table_class );
60
  if ( parent.find( '.smart-cf-relation-right li[data-id="' + id + '"]' ).length === 0 ) {
61
  var clone = $( this ).clone();
62
  clone
63
  .prepend( $( '<span class="smart-cf-icon-handle"></span>' ) )
64
  .append( $( '<span class="relation-remove">-</span>' ) );
65
  parent.find( '.smart-cf-relation-right ul' ).append( clone );
66
- update_relation_value( $( this ).parents( 'tr' ) );
67
  }
68
  } );
69
 
@@ -72,7 +72,7 @@ jQuery( function( $ ) {
72
  */
73
  var relation_remove = '.smart-cf-relation-right li .relation-remove';
74
  $( '.smart-cf-meta-box' ).on( 'click', relation_remove, function() {
75
- var tr = $( this ).parents( 'tr' );
76
  $( this ).parent().remove();
77
  update_relation_value( tr );
78
  } );
@@ -89,7 +89,7 @@ jQuery( function( $ ) {
89
  }
90
  } );
91
  tr.find( '.smart-cf-relation-right li' ).each( function( i, e ) {
92
- var hidden_box = $( this ).parents( table_class ).find( '.smart-cf-relation-children-select' );
93
  var id = $( this ).data( 'id' );
94
  var clone = hidden.first().clone();
95
  var name = clone.attr( 'name' );
@@ -105,7 +105,7 @@ jQuery( function( $ ) {
105
  $( '.smart-cf-meta-box .smart-cf-relation-right ul' ).sortable( {
106
  handle: '.smart-cf-icon-handle',
107
  update: function() {
108
- update_relation_value( $( this ).parents( 'tr' ) );
109
  }
110
  } );
111
  } );
1
  /**
2
  * editor.js
3
+ * Version : 1.0.1
4
  * Author : Takashi Kitajima
5
  * Created : September 30, 2014
6
+ * Modified : March 19, 2015
7
  * License : GPLv2
8
  * License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
  */
17
  $( '.smart-cf-meta-box .load-relation-posts' )
18
  .data( 'click_count', 0 )
19
  .click( function() {
20
+ var parent = $( this ).closest( '.smart-cf-meta-box-table' );
21
  var click_count = $( this ).data( 'click_count' );
22
  var post_types = $( this ).data( 'post-types' );
23
  var btn_load = $( this );
56
  var choices_li = '.smart-cf-relation-children-select li';
57
  $( '.smart-cf-meta-box' ).on( 'click', choices_li, function() {
58
  var id = $( this ).data( 'id' );
59
+ var parent = $( this ).closest( table_class );
60
  if ( parent.find( '.smart-cf-relation-right li[data-id="' + id + '"]' ).length === 0 ) {
61
  var clone = $( this ).clone();
62
  clone
63
  .prepend( $( '<span class="smart-cf-icon-handle"></span>' ) )
64
  .append( $( '<span class="relation-remove">-</span>' ) );
65
  parent.find( '.smart-cf-relation-right ul' ).append( clone );
66
+ update_relation_value( $( this ).closest( 'tr' ) );
67
  }
68
  } );
69
 
72
  */
73
  var relation_remove = '.smart-cf-relation-right li .relation-remove';
74
  $( '.smart-cf-meta-box' ).on( 'click', relation_remove, function() {
75
+ var tr = $( this ).closest( 'tr' );
76
  $( this ).parent().remove();
77
  update_relation_value( tr );
78
  } );
89
  }
90
  } );
91
  tr.find( '.smart-cf-relation-right li' ).each( function( i, e ) {
92
+ var hidden_box = $( this ).closest( table_class ).find( '.smart-cf-relation-children-select' );
93
  var id = $( this ).data( 'id' );
94
  var clone = hidden.first().clone();
95
  var name = clone.attr( 'name' );
105
  $( '.smart-cf-meta-box .smart-cf-relation-right ul' ).sortable( {
106
  handle: '.smart-cf-icon-handle',
107
  update: function() {
108
+ update_relation_value( $( this ).closest( 'tr' ) );
109
  }
110
  } );
111
  } );
js/settings.js CHANGED
@@ -179,7 +179,7 @@ jQuery( function( $ ) {
179
  } );
180
 
181
  wrapper.find( '.smart-cf-field-select' ).change( function() {
182
- var field = $( this ).parents( field_class );
183
  var val = $( this ).val();
184
 
185
  var hide_options = field.find( '.smart-cf-field-options' );
179
  } );
180
 
181
  wrapper.find( '.smart-cf-field-select' ).change( function() {
182
+ var field = $( this ).parents( field_class );
183
  var val = $( this ).val();
184
 
185
  var hide_options = field.find( '.smart-cf-field-options' );
languages/smart-custom-fields-ja.mo CHANGED
Binary file
languages/smart-custom-fields-ja.po CHANGED
@@ -2,30 +2,35 @@
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 "基本フィールド"
@@ -42,154 +47,158 @@ msgstr "コンテンツフィールド"
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
 
@@ -209,48 +218,47 @@ msgstr "繰り返し"
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/"
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.3.0\n"
6
  "Report-Msgid-Bugs-To: http://wordpress.org/tag/smart-custom-fields\n"
7
+ "POT-Creation-Date: 2015-03-20 06:46:56+00:00\n"
8
+ "PO-Revision-Date: 2015-03-20 15:51+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.5\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:60
22
  msgid "Image setting"
23
  msgstr "画像設定"
24
 
25
+ #: classes/controller/class.editor.php:61
26
  msgid "File setting"
27
  msgstr "ファイル設定"
28
 
29
+ #: classes/controller/class.profile.php:47
30
+ #: classes/controller/class.settings.php:76
31
+ msgid "Custom Fields"
32
+ msgstr "カスタムフィールド"
33
+
34
  #: classes/controller/class.settings.php:29
35
  msgid "Basic fields"
36
  msgstr "基本フィールド"
47
  msgid "Other fields"
48
  msgstr "その他のフィールド"
49
 
50
+ #: classes/controller/class.settings.php:64
51
  msgid "Same name exists!"
52
  msgstr "同じ名前が存在します!"
53
 
54
+ #: classes/controller/class.settings.php:82
55
+ msgid "Display conditions ( Post )"
56
+ msgstr "表示条件(投稿)"
57
 
58
+ #: classes/controller/class.settings.php:89
59
+ msgid "Display conditions ( Profile )"
60
+ msgstr "表示条件(プロフィール)"
61
 
62
+ #: classes/controller/class.settings.php:143
63
  msgid "Type"
64
  msgstr "タイプ"
65
 
66
+ #: classes/controller/class.settings.php:178
67
  msgid "Add Sub field"
68
  msgstr "サブフィールドを追加"
69
 
70
+ #: classes/controller/class.settings.php:182
71
  msgid "Add Field"
72
  msgstr "フィールド追加"
73
 
74
+ #: classes/controller/class.settings.php:212
75
+ #: classes/fields/class.field-relation.php:187
76
  msgid "Post Types"
77
  msgstr "投稿タイプ"
78
 
79
+ #: classes/controller/class.settings.php:219
80
  msgid "Post Ids ( Comma separated )"
81
  msgstr "投稿 ID (カンマ区切り)"
82
 
83
+ #: classes/controller/class.settings.php:244
84
+ msgid "Roles"
85
+ msgstr "権限"
86
+
87
+ #: classes/fields/class.field-check.php:21
88
  msgid "Check"
89
  msgstr "チェックボックス"
90
 
91
+ #: classes/fields/class.field-check.php:81
92
+ #: classes/fields/class.field-radio.php:79
93
+ #: classes/fields/class.field-select.php:76
94
  msgid "Choices"
95
  msgstr "選択肢"
96
 
97
+ #: classes/fields/class.field-check.php:90
98
+ #: classes/fields/class.field-colorpicker.php:102
99
+ #: classes/fields/class.field-datepicker.php:124
100
+ #: classes/fields/class.field-radio.php:88
101
+ #: classes/fields/class.field-select.php:85
102
+ #: classes/fields/class.field-text.php:65
103
+ #: classes/fields/class.field-textarea.php:65
104
+ #: classes/fields/class.field-wysiwyg.php:107
105
  msgid "Default"
106
  msgstr "デフォルト"
107
 
108
+ #: classes/fields/class.field-check.php:99
109
+ #: classes/fields/class.field-colorpicker.php:111
110
+ #: classes/fields/class.field-datepicker.php:188
111
+ #: classes/fields/class.field-file.php:92
112
+ #: classes/fields/class.field-image.php:91
113
+ #: classes/fields/class.field-radio.php:97
114
+ #: classes/fields/class.field-relation.php:208
115
+ #: classes/fields/class.field-select.php:94
116
+ #: classes/fields/class.field-text.php:74
117
+ #: classes/fields/class.field-textarea.php:74
118
+ #: classes/fields/class.field-wysiwyg.php:116
119
  msgid "Notes"
120
  msgstr "注記"
121
 
122
+ #: classes/fields/class.field-colorpicker.php:29
123
  msgid "Color picker"
124
  msgstr "カラーピッカー"
125
 
126
+ #: classes/fields/class.field-datepicker.php:29
127
  msgid "Date picker"
128
  msgstr "日付ピッカー"
129
 
130
+ #: classes/fields/class.field-datepicker.php:134
131
  msgid "Date Format"
132
  msgstr "日付のフォーマット"
133
 
134
+ #: classes/fields/class.field-datepicker.php:142
135
  msgid "e.g dd/mm/yy"
136
  msgstr "例: dd/mm/yy"
137
 
138
+ #: classes/fields/class.field-datepicker.php:152
139
  msgid "Max Date"
140
  msgstr "最大日付"
141
 
142
+ #: classes/fields/class.field-datepicker.php:160
143
+ #: classes/fields/class.field-datepicker.php:178
144
  msgid "e.g +1m +1w"
145
  msgstr "例: +1m +1w"
146
 
147
+ #: classes/fields/class.field-datepicker.php:170
148
  msgid "Min Date"
149
  msgstr "最小日付"
150
 
151
+ #: classes/fields/class.field-file.php:21
152
  msgid "File"
153
  msgstr "ファイル"
154
 
155
+ #: classes/fields/class.field-file.php:50
156
+ #: classes/fields/class.field-image.php:50
157
  msgid "Delete"
158
  msgstr "削除"
159
 
160
+ #: classes/fields/class.field-file.php:73
161
  msgid "File Select"
162
  msgstr "ファイル選択"
163
 
164
+ #: classes/fields/class.field-image.php:21
165
  msgid "Image"
166
  msgstr "画像"
167
 
168
+ #: classes/fields/class.field-image.php:72
169
  msgid "Image Select"
170
  msgstr "画像選択"
171
 
172
+ #: classes/fields/class.field-radio.php:21
173
  msgid "Radio"
174
  msgstr "ラジオボタン"
175
 
176
+ #: classes/fields/class.field-relation.php:24
177
  msgid "Relation"
178
  msgstr "リレーション"
179
 
180
+ #: classes/fields/class.field-relation.php:169
181
  msgid "Load more"
182
  msgstr "さらに読み込む"
183
 
184
+ #: classes/fields/class.field-select.php:21
185
  msgid "Select"
186
  msgstr "セレクトボックス"
187
 
188
+ #: classes/fields/class.field-text.php:21
189
  msgid "Text"
190
  msgstr "テキスト"
191
 
192
+ #: classes/fields/class.field-textarea.php:21
193
  msgid "Textarea"
194
  msgstr "テキストエリア"
195
 
196
+ #: classes/fields/class.field-wysiwyg.php:26
197
  msgid "Wysiwyg"
198
  msgstr "WYSIWYG"
199
 
200
+ #: classes/fields/class.field-wysiwyg.php:138
201
+ #: classes/fields/class.field-wysiwyg.php:139
202
  msgid "Add Media"
203
  msgstr "メディアを追加"
204
 
218
  msgid "Group name"
219
  msgstr "グループ名"
220
 
221
+ #: smart-custom-fields.php:123 smart-custom-fields.php:124
222
+ #: smart-custom-fields.php:163 smart-custom-fields.php:164
 
 
 
 
 
223
  msgid "Add New"
224
  msgstr "新規追加"
225
 
226
+ #: smart-custom-fields.php:125
227
  msgid "New Field"
228
  msgstr "新規フィールド"
229
 
230
+ #: smart-custom-fields.php:126
231
  msgid "Edit Field"
232
  msgstr "フィールド編集"
233
 
234
+ #: smart-custom-fields.php:127
235
  msgid "View Field"
236
  msgstr "フィールドを表示"
237
 
238
+ #: smart-custom-fields.php:128
239
  msgid "All Fields"
240
  msgstr "すべてのフィールド"
241
 
242
+ #: smart-custom-fields.php:129
243
  msgid "Search Fields"
244
  msgstr "フィールドを検索"
245
 
246
+ #: smart-custom-fields.php:130
247
  msgid "Parent Fields:"
248
  msgstr "親フィールド:"
249
 
250
+ #: smart-custom-fields.php:131
251
  msgid "No Fields found."
252
  msgstr "フィールドは見つかりませんでした。"
253
 
254
+ #: smart-custom-fields.php:132
255
  msgid "No Fields found in Trash."
256
  msgstr "ゴミ箱にフィールドは見つかりませんでした"
257
 
258
+ #. Plugin Name of the plugin/theme
259
+ msgid "Smart Custom Fields"
260
+ msgstr "Smart Custom Fields"
261
+
262
  #. Plugin URI of the plugin/theme
263
  msgid "https://github.com/inc2734/smart-custom-fields/"
264
  msgstr "https://github.com/inc2734/smart-custom-fields/"
languages/smart-custom-fields.pot CHANGED
@@ -2,9 +2,9 @@
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"
@@ -18,14 +18,19 @@ msgstr ""
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 ""
@@ -42,154 +47,158 @@ msgstr ""
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
 
@@ -209,47 +218,45 @@ msgstr ""
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/"
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.3.0\n"
6
  "Report-Msgid-Bugs-To: http://wordpress.org/tag/smart-custom-fields\n"
7
+ "POT-Creation-Date: 2015-03-20 06:46:56+00:00\n"
8
  "MIME-Version: 1.0\n"
9
  "Content-Type: text/plain; charset=UTF-8\n"
10
  "Content-Transfer-Encoding: 8bit\n"
18
  "X-Poedit-KeywordsList: __;_e\n"
19
  "X-Poedit-SearchPath-0: ..\n"
20
 
21
+ #: classes/controller/class.editor.php:60
22
  msgid "Image setting"
23
  msgstr ""
24
 
25
+ #: classes/controller/class.editor.php:61
26
  msgid "File setting"
27
  msgstr ""
28
 
29
+ #: classes/controller/class.profile.php:47
30
+ #: classes/controller/class.settings.php:76
31
+ msgid "Custom Fields"
32
+ msgstr ""
33
+
34
  #: classes/controller/class.settings.php:29
35
  msgid "Basic fields"
36
  msgstr ""
47
  msgid "Other fields"
48
  msgstr ""
49
 
50
+ #: classes/controller/class.settings.php:64
51
  msgid "Same name exists!"
52
  msgstr ""
53
 
54
+ #: classes/controller/class.settings.php:82
55
+ msgid "Display conditions ( Post )"
56
  msgstr ""
57
 
58
+ #: classes/controller/class.settings.php:89
59
+ msgid "Display conditions ( Profile )"
60
  msgstr ""
61
 
62
+ #: classes/controller/class.settings.php:143
63
  msgid "Type"
64
  msgstr ""
65
 
66
+ #: classes/controller/class.settings.php:178
67
  msgid "Add Sub field"
68
  msgstr ""
69
 
70
+ #: classes/controller/class.settings.php:182
71
  msgid "Add Field"
72
  msgstr ""
73
 
74
+ #: classes/controller/class.settings.php:212
75
+ #: classes/fields/class.field-relation.php:187
76
  msgid "Post Types"
77
  msgstr ""
78
 
79
+ #: classes/controller/class.settings.php:219
80
  msgid "Post Ids ( Comma separated )"
81
  msgstr ""
82
 
83
+ #: classes/controller/class.settings.php:244
84
+ msgid "Roles"
85
+ msgstr ""
86
+
87
+ #: classes/fields/class.field-check.php:21
88
  msgid "Check"
89
  msgstr ""
90
 
91
+ #: classes/fields/class.field-check.php:81
92
+ #: classes/fields/class.field-radio.php:79
93
+ #: classes/fields/class.field-select.php:76
94
  msgid "Choices"
95
  msgstr ""
96
 
97
+ #: classes/fields/class.field-check.php:90
98
+ #: classes/fields/class.field-colorpicker.php:102
99
+ #: classes/fields/class.field-datepicker.php:124
100
+ #: classes/fields/class.field-radio.php:88
101
+ #: classes/fields/class.field-select.php:85
102
+ #: classes/fields/class.field-text.php:65
103
+ #: classes/fields/class.field-textarea.php:65
104
+ #: classes/fields/class.field-wysiwyg.php:107
105
  msgid "Default"
106
  msgstr ""
107
 
108
+ #: classes/fields/class.field-check.php:99
109
+ #: classes/fields/class.field-colorpicker.php:111
110
+ #: classes/fields/class.field-datepicker.php:188
111
+ #: classes/fields/class.field-file.php:92
112
+ #: classes/fields/class.field-image.php:91
113
+ #: classes/fields/class.field-radio.php:97
114
+ #: classes/fields/class.field-relation.php:208
115
+ #: classes/fields/class.field-select.php:94
116
+ #: classes/fields/class.field-text.php:74
117
+ #: classes/fields/class.field-textarea.php:74
118
+ #: classes/fields/class.field-wysiwyg.php:116
119
  msgid "Notes"
120
  msgstr ""
121
 
122
+ #: classes/fields/class.field-colorpicker.php:29
123
  msgid "Color picker"
124
  msgstr ""
125
 
126
+ #: classes/fields/class.field-datepicker.php:29
127
  msgid "Date picker"
128
  msgstr ""
129
 
130
+ #: classes/fields/class.field-datepicker.php:134
131
  msgid "Date Format"
132
  msgstr ""
133
 
134
+ #: classes/fields/class.field-datepicker.php:142
135
  msgid "e.g dd/mm/yy"
136
  msgstr ""
137
 
138
+ #: classes/fields/class.field-datepicker.php:152
139
  msgid "Max Date"
140
  msgstr ""
141
 
142
+ #: classes/fields/class.field-datepicker.php:160
143
+ #: classes/fields/class.field-datepicker.php:178
144
  msgid "e.g +1m +1w"
145
  msgstr ""
146
 
147
+ #: classes/fields/class.field-datepicker.php:170
148
  msgid "Min Date"
149
  msgstr ""
150
 
151
+ #: classes/fields/class.field-file.php:21
152
  msgid "File"
153
  msgstr ""
154
 
155
+ #: classes/fields/class.field-file.php:50
156
+ #: classes/fields/class.field-image.php:50
157
  msgid "Delete"
158
  msgstr ""
159
 
160
+ #: classes/fields/class.field-file.php:73
161
  msgid "File Select"
162
  msgstr ""
163
 
164
+ #: classes/fields/class.field-image.php:21
165
  msgid "Image"
166
  msgstr ""
167
 
168
+ #: classes/fields/class.field-image.php:72
169
  msgid "Image Select"
170
  msgstr ""
171
 
172
+ #: classes/fields/class.field-radio.php:21
173
  msgid "Radio"
174
  msgstr ""
175
 
176
+ #: classes/fields/class.field-relation.php:24
177
  msgid "Relation"
178
  msgstr ""
179
 
180
+ #: classes/fields/class.field-relation.php:169
181
  msgid "Load more"
182
  msgstr ""
183
 
184
+ #: classes/fields/class.field-select.php:21
185
  msgid "Select"
186
  msgstr ""
187
 
188
+ #: classes/fields/class.field-text.php:21
189
  msgid "Text"
190
  msgstr ""
191
 
192
+ #: classes/fields/class.field-textarea.php:21
193
  msgid "Textarea"
194
  msgstr ""
195
 
196
+ #: classes/fields/class.field-wysiwyg.php:26
197
  msgid "Wysiwyg"
198
  msgstr ""
199
 
200
+ #: classes/fields/class.field-wysiwyg.php:138
201
+ #: classes/fields/class.field-wysiwyg.php:139
202
  msgid "Add Media"
203
  msgstr ""
204
 
218
  msgid "Group name"
219
  msgstr ""
220
 
221
+ #: smart-custom-fields.php:123 smart-custom-fields.php:124
222
+ #: smart-custom-fields.php:163 smart-custom-fields.php:164
 
 
 
 
 
223
  msgid "Add New"
224
  msgstr ""
225
 
226
+ #: smart-custom-fields.php:125
227
  msgid "New Field"
228
  msgstr ""
229
 
230
+ #: smart-custom-fields.php:126
231
  msgid "Edit Field"
232
  msgstr ""
233
 
234
+ #: smart-custom-fields.php:127
235
  msgid "View Field"
236
  msgstr ""
237
 
238
+ #: smart-custom-fields.php:128
239
  msgid "All Fields"
240
  msgstr ""
241
 
242
+ #: smart-custom-fields.php:129
243
  msgid "Search Fields"
244
  msgstr ""
245
 
246
+ #: smart-custom-fields.php:130
247
  msgid "Parent Fields:"
248
  msgstr ""
249
 
250
+ #: smart-custom-fields.php:131
251
  msgid "No Fields found."
252
  msgstr ""
253
 
254
+ #: smart-custom-fields.php:132
255
  msgid "No Fields found in Trash."
256
  msgstr ""
257
+ #. Plugin Name of the plugin/theme
258
+ msgid "Smart Custom Fields"
259
+ msgstr ""
260
 
261
  #. Plugin URI of the plugin/theme
262
  msgid "https://github.com/inc2734/smart-custom-fields/"
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: http://www.amazon.co.jp/registry/wishlist/39ANKRNSTNW40
4
  Tags: plugin, custom field, custom, field, meta, meta field, repeat, repeatable
5
  Requires at least: 3.9
6
  Tested up to: 4.1.1
7
- Stable tag: 1.2.2
8
  License: GPLv2
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -45,6 +45,15 @@ This method can get meta data of any group.
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
@@ -72,6 +81,17 @@ You can send your own language pack to me.
72
 
73
  == Changelog ==
74
 
 
 
 
 
 
 
 
 
 
 
 
75
  = 1.2.2 =
76
  * Fixed a bug that can not get the correct data when the posts use post id filtering.
77
  * Changed that original the_content filter does not apply to wisywig field.
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.3.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
+ * SCF::get_user_meta( $user_id, 'field-name' )
49
+ This method can get any user meta data.
50
+
51
+ * SCF::get_user_meta( $user_id, 'group-name' )
52
+ This method can get user meta data of any group.
53
+
54
+ * SCF::get_user_meta( $user_id )
55
+ This method can get all user meta data.
56
+
57
  = Register custom fields by the code. =
58
 
59
  https://gist.github.com/inc2734/9f6d65c7473d060d0fd6
81
 
82
  == Changelog ==
83
 
84
+ = 1.3.0 =
85
+ * refactoring.
86
+ * Add profile custom fields.
87
+ * Add filter hook smart-cf-validate-get-value
88
+ * Add method SCF::get_user_meta( $user_id, $name = null )
89
+ * Fixed a revision bug.
90
+ * Fixed a bug that thumbnail is not displayed correctly in preview.
91
+ * Fixed a relation field bug.
92
+ * Changed return value of SCF::get with multiple data in loop.
93
+ * Changed revision screen format.
94
+
95
  = 1.2.2 =
96
  * Fixed a bug that can not get the correct data when the posts use post id filtering.
97
  * Changed that original the_content filter does not apply to wisywig field.
smart-custom-fields.php CHANGED
@@ -3,11 +3,11 @@
3
  * Plugin name: Smart Custom Fields
4
  * Plugin URI: https://github.com/inc2734/smart-custom-fields/
5
  * Description: Smart Custom Fields is a simple plugin that management custom fields.
6
- * Version: 1.2.2
7
  * Author: Takashi Kitajima
8
  * Author URI: http://2inc.org
9
  * Created: October 9, 2014
10
- * Modified: March 14, 2015
11
  * Text Domain: smart-custom-fields
12
  * Domain Path: /languages
13
  * License: GPLv2
@@ -35,6 +35,7 @@ class Smart_Custom_Fields {
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';
@@ -78,12 +79,6 @@ class Smart_Custom_Fields {
78
  * @param WP_Screen $screen
79
  */
80
  public function current_screen( $screen ) {
81
- $post_id = false;
82
- if ( !empty( $_GET['post'] ) ) {
83
- $post_id = $_GET['post'];
84
- } elseif ( !empty( $_POST['post_ID'] ) ) {
85
- $post_id = $_POST['post_ID'];
86
- }
87
  // 一覧画面
88
  if ( $screen->id === 'edit-' . SCF_Config::NAME ) {
89
  }
@@ -93,9 +88,30 @@ class Smart_Custom_Fields {
93
  new Smart_Custom_Fields_Controller_Settings();
94
  }
95
  // その他の新規作成・編集画面
96
- elseif ( SCF::get_settings( $screen->id, $post_id ) ) {
97
- require_once plugin_dir_path( __FILE__ ) . 'classes/controller/class.editor.php';
98
- new Smart_Custom_Fields_Controller_Editor();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
99
  }
100
  }
101
 
@@ -153,5 +169,39 @@ class Smart_Custom_Fields {
153
  'post-new.php?post_type=' . SCF_Config::NAME
154
  );
155
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
156
  }
157
  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.3.0
7
  * Author: Takashi Kitajima
8
  * Author URI: http://2inc.org
9
  * Created: October 9, 2014
10
+ * Modified: March 19, 2015
11
  * Text Domain: smart-custom-fields
12
  * Domain Path: /languages
13
  * License: GPLv2
35
  );
36
 
37
  do_action( SCF_Config::PREFIX . 'load' );
38
+ require_once plugin_dir_path( __FILE__ ) . 'classes/models/class.meta.php';
39
  require_once plugin_dir_path( __FILE__ ) . 'classes/models/class.setting.php';
40
  require_once plugin_dir_path( __FILE__ ) . 'classes/models/class.group.php';
41
  require_once plugin_dir_path( __FILE__ ) . 'classes/models/class.abstract-field-base.php';
79
  * @param WP_Screen $screen
80
  */
81
  public function current_screen( $screen ) {
 
 
 
 
 
 
82
  // 一覧画面
83
  if ( $screen->id === 'edit-' . SCF_Config::NAME ) {
84
  }
88
  new Smart_Custom_Fields_Controller_Settings();
89
  }
90
  // その他の新規作成・編集画面
91
+ elseif ( in_array( $screen->id, get_post_types() ) ) {
92
+ $post_id = $this->get_post_id_in_admin();
93
+ $Post = new stdClass();
94
+ $Post->ID = $post_id;
95
+ $Post->post_type = $screen->id;
96
+ if ( SCF::get_settings( new WP_Post( $Post ) ) ) {
97
+ require_once plugin_dir_path( __FILE__ ) . 'classes/controller/class.editor.php';
98
+ new Smart_Custom_Fields_Revisions();
99
+ new Smart_Custom_Fields_Controller_Editor();
100
+ }
101
+ }
102
+ // プロフィール編集画面
103
+ elseif ( in_array( $screen->id, array( 'profile', 'user-edit' ) ) ) {
104
+ $user_id = $this->get_user_id_in_admin();
105
+ $user_data = get_userdata( $user_id );
106
+ $roles[0] = false;
107
+ if ( $user_data ) {
108
+ $roles = $user_data->roles;
109
+ }
110
+ if ( SCF::get_settings( get_userdata( $user_id ) ) ) {
111
+ require_once plugin_dir_path( __FILE__ ) . 'classes/controller/class.editor.php';
112
+ require_once plugin_dir_path( __FILE__ ) . 'classes/controller/class.profile.php';
113
+ new Smart_Custom_Fields_Controller_Profile();
114
+ }
115
  }
116
  }
117
 
169
  'post-new.php?post_type=' . SCF_Config::NAME
170
  );
171
  }
172
+
173
+ /**
174
+ * 編集画面でその投稿のIDを取得
175
+ *
176
+ * @return int
177
+ */
178
+ protected function get_post_id_in_admin() {
179
+ $post_id = false;
180
+ if ( !empty( $_GET['post'] ) ) {
181
+ $post_id = $_GET['post'];
182
+ } elseif ( !empty( $_POST['post_ID'] ) ) {
183
+ $post_id = $_POST['post_ID'];
184
+ }
185
+ return $post_id;
186
+ }
187
+
188
+ /**
189
+ * プロフィール、ユーザー編集画面でそのユーザーのIDを取得
190
+ *
191
+ * @return int
192
+ */
193
+ protected function get_user_id_in_admin() {
194
+ $screen = get_current_screen();
195
+ $user_id = false;
196
+ if ( !empty( $_GET['user_id'] ) ) {
197
+ $user_id = $_GET['user_id'];
198
+ } elseif ( !empty( $_POST['user_id'] ) ) {
199
+ $user_id = $_POST['user_id'];
200
+ } elseif ( $screen->id === 'profile' ) {
201
+ $current_user = wp_get_current_user();
202
+ $user_id = $current_user->ID;
203
+ }
204
+ return $user_id;
205
+ }
206
  }
207
  new Smart_Custom_Fields();