Smart Custom Fields - Version 1.4.0

Version Description

  • refactoring controllers.
  • Add term custom fields.
  • Add filter hook smart-cf-is_use_default_when_not_saved
  • Changed to the default value is used if the value has not been saved. If you want to revert to the previous behavior, return false in smart-cf-is_use_default_when_not_saved.
Download this release

Release Info

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

Code changes from version 1.3.2 to 1.4.0

classes/class.scf.php CHANGED
@@ -1,10 +1,10 @@
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
  */
@@ -119,10 +119,33 @@ class SCF {
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
  */
@@ -165,7 +188,7 @@ class SCF {
165
  /**
166
  * 全てのメタデータを良い感じに取得
167
  *
168
- * @param WP_Post|WP_User $object
169
  * @return mixed
170
  */
171
  protected static function get_all_meta( $object ) {
@@ -214,38 +237,40 @@ class SCF {
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
  }
@@ -261,7 +286,7 @@ class SCF {
261
  /**
262
  * そのグループのメタデータを取得。グループの場合は必ず繰り返しになっている点に注意
263
  *
264
- * @param WP_Post|WP_User $object
265
  * @param Smart_Custom_Fields_Group $Group
266
  * @return mixed
267
  */
@@ -293,7 +318,7 @@ class SCF {
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
@@ -310,7 +335,11 @@ class SCF {
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 ) {
@@ -319,45 +348,105 @@ class SCF {
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
 
@@ -369,9 +458,9 @@ class SCF {
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 ) {
@@ -393,6 +482,9 @@ class SCF {
393
  case 'user' :
394
  $key = SCF_Config::PREFIX . 'roles';
395
  break;
 
 
 
396
  default :
397
  $key = '';
398
  }
@@ -407,7 +499,7 @@ class SCF {
407
  array(
408
  'key' => $key,
409
  'compare' => 'LIKE',
410
- 'value' => $type,
411
  ),
412
  ),
413
  ) );
@@ -420,7 +512,7 @@ class SCF {
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 ) {
@@ -446,7 +538,7 @@ class SCF {
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 ) {
@@ -478,13 +570,13 @@ class SCF {
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();
@@ -496,6 +588,9 @@ class SCF {
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;
@@ -573,34 +668,47 @@ class SCF {
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
  }
@@ -615,7 +723,7 @@ class SCF {
615
  /**
616
  * 繰り返しに設定された複数許可フィールドデータの区切り識別用データを取得
617
  *
618
- * @param WP_Post|WP_User $object
619
  * @return array
620
  */
621
  public static function get_repeat_multiple_data( $object ) {
@@ -689,14 +797,14 @@ class SCF {
689
 
690
  /**
691
  * 管理画面で保存されたフィールドを取得
692
- * 同じ投稿タイプで、同名のフィールド名を持つフィールドを複数定義しても一つしか返らないので注意
693
  *
694
- * @param string $post_type
695
  * @param string $field_name
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 ) {
@@ -718,6 +826,9 @@ class SCF {
718
  */
719
  public static function choices_eol_to_array( $choices ) {
720
  if ( !is_array( $choices ) ) {
 
 
 
721
  $choices = str_replace( array( "\r\n", "\r", "\n" ), "\n", $choices );
722
  return explode( "\n", $choices );
723
  }
1
  <?php
2
  /**
3
  * SCF
4
+ * Version : 1.2.0
5
  * Author : Takashi Kitajima
6
  * Created : September 23, 2014
7
+ * Modified : March 27, 2015
8
  * License : GPLv2
9
  * License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
  */
119
  return self::get_meta( get_userdata( $user_id ), $name );
120
  }
121
 
122
+ /**
123
+ * そのタームの任意のメタデータを良い感じに取得
124
+ *
125
+ * @param int $term_id
126
+ * @param string $taxonomy_name
127
+ * @param string $name グループ名もしくはフィールド名
128
+ * @return mixed
129
+ */
130
+ public static function get_term_meta( $term_id, $taxonomy_name, $name = null ) {
131
+ if ( empty( $term_id ) || empty( $taxonomy_name ) ) {
132
+ return;
133
+ }
134
+
135
+ // $name が null のときは全てのメタデータを返す
136
+ if ( $name === null ) {
137
+ return self::get_all_meta( get_term( $term_id, $taxonomy_name ) );
138
+ }
139
+
140
+ // 設定画面で未設定のメタデータはタームが保持していても出力しないようにしないといけないので
141
+ // 設定データを取得して出力して良いか判別する
142
+ return self::get_meta( get_term( $term_id, $taxonomy_name ), $name );
143
+ }
144
+
145
  /**
146
  * 任意のメタデータを良い感じに取得
147
  *
148
+ * @param WP_Post|WP_User|object $object
149
  * @param string $name グループ名もしくはフィールド名
150
  * @return mixed
151
  */
188
  /**
189
  * 全てのメタデータを良い感じに取得
190
  *
191
+ * @param WP_Post|WP_User|object $object
192
  * @return mixed
193
  */
194
  protected static function get_all_meta( $object ) {
237
  /**
238
  * キャシュに保存
239
  *
240
+ * @param WP_Post|WP_User|object $object
241
  * @param string $name
242
  * @param mixed $data
243
  */
244
  protected static function save_cache( $object, $name, $data ) {
245
+ $Meta = new Smart_Custom_Fields_Meta( $object );
246
+ $id = $Meta->get_id();
247
+ $type = $Meta->get_type();
248
+ $meta_type = $Meta->get_meta_type();
249
+ if ( !empty( $id ) && !empty( $type ) && !empty( $meta_type ) ) {
250
+ self::$cache[$meta_type . '_' . $type . '_' . $id][$name] = $data;
251
  }
252
  }
253
 
254
  /**
255
  * キャッシュを取得
256
  *
257
+ * @param WP_Post|WP_User|object $object
258
  * @param string $name
259
  * @return mixed
260
  */
261
  protected static function get_cache( $object, $name = null ) {
262
+ $Meta = new Smart_Custom_Fields_Meta( $object );
263
+ $id = $Meta->get_id();
264
+ $type = $Meta->get_type();
265
+ $meta_type = $Meta->get_meta_type();
266
+ if ( !empty( $id ) && !empty( $type ) && !empty( $meta_type ) ) {
267
  if ( is_null( $name ) ) {
268
+ if ( isset( self::$cache[$meta_type . '_' . $type . '_' . $id] ) ) {
269
+ return self::$cache[$meta_type . '_' . $type . '_' . $id];
270
  }
271
  } else {
272
+ if ( isset( self::$cache[$meta_type . '_' . $type . '_' . $id][$name] ) ) {
273
+ return self::$cache[$meta_type . '_' . $type . '_' . $id][$name];
274
  }
275
  }
276
  }
286
  /**
287
  * そのグループのメタデータを取得。グループの場合は必ず繰り返しになっている点に注意
288
  *
289
+ * @param WP_Post|WP_User|object $object
290
  * @param Smart_Custom_Fields_Group $Group
291
  * @return mixed
292
  */
318
  /**
319
  * そのフィールドのメタデータを取得
320
  *
321
+ * @param WP_Post|WP_User|object $object
322
  * @param array $field
323
  * @param bool $is_repeatable このフィールドが所属するグループが repeat かどうか
324
  * @return mixed $post_meta
335
  $field_type = $Field->get_attribute( 'type' );
336
  $repeat_multiple_data = self::get_repeat_multiple_data( $object );
337
  if ( is_array( $repeat_multiple_data ) && isset( $repeat_multiple_data[$field_name] ) ) {
338
+ if ( $Meta->is_saved_by_key( $field_name ) || !$Meta->is_use_default_when_not_saved() ) {
339
+ $_meta = $Meta->get( $field_name );
340
+ } else {
341
+ $_meta = self::get_default_value( $Field );
342
+ }
343
  $start = 0;
344
  foreach ( $repeat_multiple_data[$field_name] as $repeat_multiple_key => $repeat_multiple_value ) {
345
  if ( $repeat_multiple_value === 0 ) {
348
  $value = array_slice( $_meta, $start, $repeat_multiple_value );
349
  $start += $repeat_multiple_value;
350
  }
351
+ if ( $Meta->is_saved_by_key( $field_name ) || $Meta->is_use_default_when_not_saved() ) {
352
+ $value = apply_filters( SCF_Config::PREFIX . 'validate-get-value', $value, $field_type );
353
+ }
354
  $meta[$repeat_multiple_key] = $value;
355
  }
356
  }
357
  // それ以外
358
  else {
359
  if ( $Field->get_attribute( 'allow-multiple-data' ) || $is_repeatable ) {
360
+ if ( $Meta->is_saved_by_key( $field_name ) || !$Meta->is_use_default_when_not_saved() ) {
361
+ $meta = $Meta->get( $field_name );
362
+ } else {
363
+ $meta = self::get_default_value( $Field );
364
+ }
365
  } else {
366
+ if ( $Meta->is_saved_by_key( $field_name ) || !$Meta->is_use_default_when_not_saved() ) {
367
+ $meta = $Meta->get( $field_name, true );
368
+ } else {
369
+ $meta = self::get_default_value( $Field, true );
370
+ }
371
+ }
372
+ if ( $Meta->is_saved_by_key( $field_name ) || $Meta->is_use_default_when_not_saved() ) {
373
+ $meta = apply_filters( SCF_Config::PREFIX . 'validate-get-value', $meta, $field_type );
374
  }
 
375
  }
376
  return $meta;
377
  }
378
 
379
  /**
380
+ * 初期値を返す
381
  *
382
+ * @param Smart_Custom_Fields_Field_Base $Field
383
+ * @param bool $single
384
+ * @return array|strings
385
+ */
386
+ public static function get_default_value( $Field, $single = false ) {
387
+ if ( !is_a( $Field, 'Smart_Custom_Fields_Field_Base' ) ) {
388
+ if ( $single ) {
389
+ return '';
390
+ }
391
+ return array();
392
+ }
393
+
394
+ $choices = $Field->get( 'choices' );
395
+ $default = $Field->get( 'default' );
396
+
397
+ if ( $Field->get_attribute( 'allow-multiple-data' ) ) {
398
+ $choices = SCF::choices_eol_to_array( $choices );
399
+ $default = SCF::choices_eol_to_array( $default );
400
+ $default_sanitized = array();
401
+ foreach ( $default as $key => $value ) {
402
+ if ( in_array( $value, $choices ) ) {
403
+ $default_sanitized[$key] = $value;
404
+ }
405
+ }
406
+ return $default_sanitized;
407
+ }
408
+
409
+ // 文字列を返す
410
+ if ( $single ) {
411
+ return $default;
412
+ }
413
+ // 配列を返す
414
+ else {
415
+ if ( is_array( $default ) ) {
416
+ return $default;
417
+ }
418
+ if ( $default === '' || $default === false || $default === null ) {
419
+ return array();
420
+ }
421
+ return ( array ) $default;
422
+ }
423
+ }
424
+
425
+ /**
426
+ * その投稿タイプ or ロール or タームで有効になっている SCF をキャッシュに保存
427
+ *
428
+ * @param WP_Post|WP_User|object $object
429
  * @param array $settings_posts
430
  */
431
  protected static function save_settings_posts_cache( $object, $settings_posts ) {
432
+ $Meta = new Smart_Custom_Fields_Meta( $object );
433
+ $type = $Meta->get_type( false );
434
+ $meta_type = $Meta->get_meta_type();
435
+ self::$settings_posts_cache[$meta_type . '_' . $type] = $settings_posts;
436
  }
437
 
438
  /**
439
+ * その投稿タイプ or ロール or タームで有効になっている SCF のキャッシュを取得
440
  *
441
+ * @param WP_Post|WP_User|object $object
442
  * @return array|null
443
  */
444
  public static function get_settings_posts_cache( $object ) {
445
+ $Meta = new Smart_Custom_Fields_Meta( $object );
446
+ $type = $Meta->get_type( false );
447
+ $meta_type = $Meta->get_meta_type();
448
+ if ( isset( self::$settings_posts_cache[$meta_type . '_' . $type] ) ) {
449
+ return self::$settings_posts_cache[$meta_type . '_' . $type];
450
  }
451
  }
452
 
458
  }
459
 
460
  /**
461
+ * その投稿タイプ or ロール or タームで有効になっている SCF を取得
462
  *
463
+ * @param WP_Post|WP_User|object $object
464
  * @return array $settings
465
  */
466
  public static function get_settings_posts( $object ) {
482
  case 'user' :
483
  $key = SCF_Config::PREFIX . 'roles';
484
  break;
485
+ case 'term' :
486
+ $key = SCF_Config::PREFIX . 'taxonomies';
487
+ break;
488
  default :
489
  $key = '';
490
  }
499
  array(
500
  'key' => $key,
501
  'compare' => 'LIKE',
502
+ 'value' => sprintf( '"%s"', $type ),
503
  ),
504
  ),
505
  ) );
512
  * Setting オブジェクトをキャッシュに保存
513
  *
514
  * @param int $settings_post_id
515
+ * @param WP_post|WP_User|object $object
516
  * @param Smart_Custom_Fields_Setting $Setting
517
  */
518
  protected static function save_settings_cache( $settings_post_id, $Setting, $object = null ) {
538
  * 指定した $meta_type + $id のものがあるとき ... Smart_Custom_Fields_Setting
539
  *
540
  * @param int $settings_post_id
541
+ * @param WP_post|WP_User $object|object
542
  * @return Smart_Custom_Fields_Setting|false|null
543
  */
544
  public static function get_settings_cache( $settings_post_id, $object = null ) {
570
  /**
571
  * Setting オブジェクトの配列を取得
572
  *
573
+ * @param WP_Post|WP_User|object $object
574
  * @return array $settings
575
  */
576
  public static function get_settings( $object ) {
577
+ $Meta = new Smart_Custom_Fields_Meta( $object );
578
+ $id = $Meta->get_id();
579
+ $type = $Meta->get_type( false );
580
  $meta_type = $Meta->get_meta_type();
581
 
582
  $settings = array();
588
  elseif ( $meta_type === 'user' ) {
589
  $settings = self::get_settings_for_profile( $object, $settings_posts );
590
  }
591
+ elseif ( $meta_type === 'term' ) {
592
+ $settings = self::get_settings_for_term( $object, $settings_posts );
593
+ }
594
  }
595
  $settings = apply_filters( SCF_Config::PREFIX . 'register-fields', $settings, $type, $id, $meta_type );
596
  return $settings;
668
  return $settings;
669
  }
670
 
671
+ /**
672
+ * Setting オブジェクトの配列を取得(ターム用)
673
+ *
674
+ * @param WP_User $object
675
+ * @param array $settings_posts
676
+ * @return array
677
+ */
678
+ protected static function get_settings_for_term( $object, $settings_posts ) {
679
+ return self::get_settings_for_profile( $object, $settings_posts );
680
+ }
681
+
682
  /**
683
  * 繰り返しに設定された複数許可フィールドデータの区切り識別用データをキャッシュに保存
684
  *
685
+ * @param WP_Post|WP_User|object $object
686
  * @param mixed $repeat_multiple_data
687
  */
688
  protected static function save_repeat_multiple_data_cache( $object, $repeat_multiple_data ) {
689
+ $Meta = new Smart_Custom_Fields_Meta( $object );
690
+ $id = $Meta->get_id();
691
+ $type = $Meta->get_type();
692
+ $meta_type = $Meta->get_meta_type();
693
+ if ( !empty( $id ) && !empty( $type ) && !empty( $meta_type ) ) {
694
+ self::$repeat_multiple_data_cache[$meta_type . '_' . $type . '_' . $id] = $repeat_multiple_data;
695
  }
696
  }
697
 
698
  /**
699
  * 繰り返しに設定された複数許可フィールドデータの区切り識別用データをキャッシュから取得
700
  *
701
+ * @param WP_Post|WP_User|object $object
702
  * @return mixed
703
  */
704
  protected static function get_repeat_multiple_data_cache( $object ) {
705
+ $Meta = new Smart_Custom_Fields_Meta( $object );
706
+ $id = $Meta->get_id();
707
+ $type = $Meta->get_type();
708
+ $meta_type = $Meta->get_meta_type();
709
  if ( !empty( $id ) && !empty( $type ) ) {
710
+ if ( isset( self::$repeat_multiple_data_cache[$meta_type . '_' . $type . '_' . $id] ) ) {
711
+ return self::$repeat_multiple_data_cache[$meta_type . '_' . $type . '_' . $id];
712
  }
713
  }
714
  }
723
  /**
724
  * 繰り返しに設定された複数許可フィールドデータの区切り識別用データを取得
725
  *
726
+ * @param WP_Post|WP_User|object $object
727
  * @return array
728
  */
729
  public static function get_repeat_multiple_data( $object ) {
797
 
798
  /**
799
  * 管理画面で保存されたフィールドを取得
800
+ * 同名のフィールド名を持つフィールドを複数定義しても一つしか返らないので注意
801
  *
802
+ * @param WP_Post|WP_User|object $object
803
  * @param string $field_name
804
+ * @return Smart_Custom_Fields_Field_Base|null
805
  */
806
+ public static function get_field( $object, $field_name ) {
807
+ $settings = self::get_settings( $object );
808
  foreach ( $settings as $Setting ) {
809
  $groups = $Setting->get_groups();
810
  foreach ( $groups as $Group ) {
826
  */
827
  public static function choices_eol_to_array( $choices ) {
828
  if ( !is_array( $choices ) ) {
829
+ if ( $choices === '' || $choices === false || $choices === null ) {
830
+ return array();
831
+ }
832
  $choices = str_replace( array( "\r\n", "\r", "\n" ), "\n", $choices );
833
  return explode( "\n", $choices );
834
  }
classes/controller/class.controller-base.php ADDED
@@ -0,0 +1,305 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Smart_Custom_Fields_Controller_Base
4
+ * Version : 1.0.0
5
+ * Author : Takashi Kitajima
6
+ * Created : April 27, 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_Base {
12
+
13
+ /**
14
+ * 各フォーム部品のオブジェクトを格納する配列
15
+ * @var array
16
+ */
17
+ protected $fields = array();
18
+
19
+ /**
20
+ * __construct
21
+ */
22
+ public function __construct() {
23
+ add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
24
+ }
25
+
26
+ /**
27
+ * 投稿画面用の css、js、翻訳ファイルのロード
28
+ *
29
+ * @param string $hook
30
+ */
31
+ public function admin_enqueue_scripts( $hook ) {
32
+ do_action( SCF_Config::PREFIX . 'before-editor-enqueue-scripts' );
33
+ wp_enqueue_style(
34
+ SCF_Config::PREFIX . 'editor',
35
+ plugins_url( SCF_Config::NAME ) . '/css/editor.css'
36
+ );
37
+ wp_enqueue_media();
38
+ wp_enqueue_script(
39
+ SCF_Config::PREFIX . 'editor',
40
+ plugins_url( SCF_Config::NAME ) . '/js/editor.js',
41
+ array( 'jquery' ),
42
+ null,
43
+ true
44
+ );
45
+ wp_localize_script( SCF_Config::PREFIX . 'editor', 'smart_cf_uploader', array(
46
+ 'image_uploader_title' => esc_html__( 'Image setting', 'smart-custom-fields' ),
47
+ 'file_uploader_title' => esc_html__( 'File setting', 'smart-custom-fields' ),
48
+ ) );
49
+ do_action( SCF_Config::PREFIX . 'after-editor-enqueue-scripts' );
50
+ }
51
+
52
+ /**
53
+ * 投稿画面にカスタムフィールドを表示
54
+ *
55
+ * @param WP_Post|WP_User|object $object
56
+ * @param array $callback_args カスタムフィールドの設定情報
57
+ */
58
+ public function display_meta_box( $object, $callback_args ) {
59
+ $groups = $callback_args['args'];
60
+ $tables = $this->get_tables( $object, $groups );
61
+
62
+ printf( '<div class="%s">', esc_attr( SCF_Config::PREFIX . 'meta-box' ) );
63
+ $index = 0;
64
+ foreach ( $tables as $group_key => $Group ) {
65
+ $is_repeatable = $Group->is_repeatable();
66
+ if ( $is_repeatable && $index === 0 ) {
67
+ printf(
68
+ '<div class="%s">',
69
+ esc_attr( SCF_Config::PREFIX . 'meta-box-repeat-tables' )
70
+ );
71
+ $this->display_tr( $object, $is_repeatable, $Group->get_fields() );
72
+ }
73
+ $this->display_tr( $object, $is_repeatable, $Group->get_fields(), $index );
74
+
75
+ // ループの場合は添字をカウントアップ
76
+ // ループを抜けたらカウントをもとに戻す
77
+ if ( $is_repeatable &&
78
+ isset( $tables[$group_key + 1 ] ) &&
79
+ $tables[$group_key + 1 ]->get_name() === $Group->get_name() ) {
80
+ $index ++;
81
+ } else {
82
+ $index = 0;
83
+ }
84
+ if ( $is_repeatable && $index === 0 ) {
85
+ printf( '</div>' );
86
+ }
87
+ }
88
+ printf( '</div>' );
89
+ wp_nonce_field( SCF_Config::NAME . '-fields', SCF_Config::PREFIX . 'fields-nonce' );
90
+ }
91
+
92
+ /**
93
+ * 送信されたデータを保存
94
+ *
95
+ * @param array $data
96
+ * @param WP_Post|WP_User|object $object
97
+ */
98
+ protected function save( $data, $object ) {
99
+ check_admin_referer(
100
+ SCF_Config::NAME . '-fields',
101
+ SCF_Config::PREFIX . 'fields-nonce'
102
+ );
103
+
104
+ $Meta = new Smart_Custom_Fields_Meta( $object );
105
+ $Meta->save( $_POST );
106
+ }
107
+
108
+ /**
109
+ * カスタムフィールドを出力するための配列を生成
110
+ *
111
+ * @param WP_Post|WP_User $object
112
+ * @param array $groups カスタムフィールド設定ページで保存した設定
113
+ * @return array $tables カスタムフィールド表示用のテーブルを出力するための配列
114
+ */
115
+ protected function get_tables( $object, $groups ) {
116
+ $Meta = new Smart_Custom_Fields_Meta( $object );
117
+ $id = $Meta->get_id();
118
+
119
+ $repeat_multiple_data = SCF::get_repeat_multiple_data( $object );
120
+ $tables = array();
121
+ foreach ( $groups as $Group ) {
122
+ // ループのときは、ループの分だけグループを追加する
123
+ // ループだけどループがないとき(新規登録時とか)は1つだけ入れる
124
+ if ( $Group->is_repeatable() === true ) {
125
+ $loop_count = 1;
126
+ $fields = $Group->get_fields();
127
+ foreach ( $fields as $Field ) {
128
+ $field_name = $Field->get( 'name' );
129
+ $meta = $Meta->get( $field_name );
130
+ if ( is_array( $meta ) ) {
131
+ $meta_count = count( $meta );
132
+ // 同名のカスタムフィールドが複数のとき(チェックボックス or ループ)
133
+ if ( $meta_count > 1 ) {
134
+ // チェックボックスの場合
135
+ if ( $Field->get_attribute( 'allow-multiple-data' ) ) {
136
+ if ( is_array( $repeat_multiple_data ) && isset( $repeat_multiple_data[$field_name] ) ) {
137
+ $repeat_multiple_data_count = count( $repeat_multiple_data[$field_name] );
138
+ if ( $loop_count < $repeat_multiple_data_count ) {
139
+ $loop_count = $repeat_multiple_data_count;
140
+ }
141
+ }
142
+ }
143
+ // チェックボックス以外
144
+ else {
145
+ if ( $loop_count < $meta_count ) {
146
+ $loop_count = $meta_count;
147
+ }
148
+ }
149
+ }
150
+ }
151
+ }
152
+ if ( $loop_count >= 1 ) {
153
+ for ( $i = $loop_count; $i > 0; $i -- ) {
154
+ $tables[] = $Group;
155
+ }
156
+ continue;
157
+ }
158
+ }
159
+ $tables[] = $Group;
160
+ }
161
+ return $tables;
162
+ }
163
+
164
+ /**
165
+ * 複数許可フィールドのメタデータを取得
166
+ *
167
+ * @param WP_Post|WP_Post $object
168
+ * @param Smart_Custom_Fields_Field_Base $Field
169
+ * @param int $index
170
+ * @return array or null
171
+ */
172
+ public function get_multiple_data_field_value( $object, $Field, $index ) {
173
+ $Meta = new Smart_Custom_Fields_Meta( $object );
174
+ $id = $Meta->get_id();
175
+ $field_name = $Field->get( 'name' );
176
+
177
+ if ( is_null( $index ) ) {
178
+ return SCF::get_default_value( $Field );
179
+ }
180
+
181
+ if ( $Meta->is_saved_by_key( $field_name ) || !$Meta->is_use_default_when_not_saved() ) {
182
+ $value = $Meta->get( $field_name );
183
+ if ( !isset( $value[$index] ) ) {
184
+ return SCF::get_default_value( $Field );
185
+ }
186
+ } else {
187
+ return SCF::get_default_value( $Field );
188
+ }
189
+
190
+ // ループのとき
191
+ $repeat_multiple_data = SCF::get_repeat_multiple_data( $object );
192
+ if ( is_array( $repeat_multiple_data ) && isset( $repeat_multiple_data[$field_name] ) ) {
193
+ $now_num = 0;
194
+ if ( is_array( $repeat_multiple_data[$field_name] ) && isset( $repeat_multiple_data[$field_name][$index] ) ) {
195
+ $now_num = $repeat_multiple_data[$field_name][$index];
196
+ }
197
+
198
+ // 自分($index)より前の個数の合計が指す index が start
199
+ $_temp = array_slice( $repeat_multiple_data[$field_name], 0, $index );
200
+ $sum = array_sum( $_temp );
201
+ $start = $sum;
202
+
203
+ if ( $now_num ) {
204
+ $value = array_slice( $value, $start, $now_num );
205
+ }
206
+ }
207
+ return $value;
208
+ }
209
+
210
+ /**
211
+ * 非複数許可フィールドのメタデータを取得
212
+ *
213
+ * @param int $id 投稿ID or ユーザーID
214
+ * @param Smart_Custom_Fields_Field_Base $Field
215
+ * @param int $index
216
+ * @return string or null
217
+ */
218
+ public function get_single_data_field_value( $object, $Field, $index ) {
219
+ $Meta = new Smart_Custom_Fields_Meta( $object );
220
+ $id = $Meta->get_id();
221
+ $field_name = $Field->get( 'name' );
222
+
223
+ if ( is_null( $index ) ) {
224
+ return SCF::get_default_value( $Field, true );
225
+ }
226
+
227
+ if ( $Meta->is_saved_by_key( $field_name ) || !$Meta->is_use_default_when_not_saved() ) {
228
+ $value = $Meta->get( $field_name );
229
+ if ( isset( $value[$index] ) ) {
230
+ return $value[$index];
231
+ }
232
+ }
233
+ return SCF::get_default_value( $Field, true );
234
+ }
235
+
236
+ /**
237
+ * カスタムフィールド表示 table で使用する各 tr を出力
238
+ *
239
+ * @param WP_Post|WP_User $object
240
+ * @param bool $is_repeat
241
+ * @param array $fields
242
+ * @param int, null $index
243
+ */
244
+ protected function display_tr( $object, $is_repeat, $fields, $index = null ) {
245
+ $Meta = new Smart_Custom_Fields_Meta( $object );
246
+ $id = $Meta->get_id();
247
+
248
+ $btn_repeat = '';
249
+ if ( $is_repeat ) {
250
+ $btn_repeat = sprintf(
251
+ '<span class="%s"></span>',
252
+ esc_attr( SCF_Config::PREFIX . 'icon-handle dashicons dashicons-menu' )
253
+ );
254
+ $btn_repeat .= '<span class="btn-add-repeat-group dashicons dashicons-plus-alt '.SCF_Config::PREFIX.'repeat-btn"></span>';
255
+ $btn_repeat .= ' <span class="btn-remove-repeat-group dashicons dashicons-dismiss '.SCF_Config::PREFIX.'repeat-btn"></span>';
256
+ }
257
+
258
+ $style = '';
259
+ if ( is_null( $index ) ) {
260
+ $style = 'style="display: none;"';
261
+ }
262
+
263
+ printf(
264
+ '<div class="%s" %s>%s<table>',
265
+ esc_attr( SCF_Config::PREFIX . 'meta-box-table' ),
266
+ $style,
267
+ $btn_repeat
268
+ );
269
+
270
+ foreach ( $fields as $Field ) {
271
+ $display_name = $Field->get_attribute( 'display-name' );
272
+ $field_name = $Field->get( 'name' );
273
+ $field_label = $Field->get( 'label' );
274
+ if ( !$field_label ) {
275
+ $field_label = $field_name;
276
+ }
277
+
278
+ // 複数値許可フィールドのとき
279
+ if ( $Field->get_attribute( 'allow-multiple-data' ) ) {
280
+ $value = $this->get_multiple_data_field_value( $object, $Field, $index );
281
+ }
282
+ // 複数不値許可フィールドのとき
283
+ else {
284
+ $value = $this->get_single_data_field_value( $object, $Field, $index );
285
+ }
286
+
287
+ $notes = $Field->get( 'notes' );
288
+ if ( !empty( $notes ) ) {
289
+ $notes = sprintf(
290
+ '<p class="description">%s</p>',
291
+ esc_html( $notes )
292
+ );
293
+ }
294
+
295
+ $form_field = $Field->get_field( $index, $value );
296
+ printf(
297
+ '<tr><th>%s</th><td>%s%s</td></tr>',
298
+ esc_html( $field_label ),
299
+ $form_field,
300
+ $notes
301
+ );
302
+ }
303
+ echo '</table></div>';
304
+ }
305
+ }
classes/controller/class.editor.php CHANGED
@@ -1,60 +1,22 @@
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
- * 各フォーム部品のオブジェクトを格納する配列
21
- * @var array
22
- */
23
- protected $fields = array();
24
 
25
  /**
26
  * __construct
27
  */
28
  public function __construct() {
29
- add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
30
- add_action( 'add_meta_boxes' , array( $this, 'add_meta_boxes' ), 10, 2 );
31
- add_action( 'save_post' , array( $this, 'save_post' ) );
32
- }
33
-
34
- /**
35
- * 投稿画面用の css、js、翻訳ファイルのロード
36
- *
37
- * @param string $hook
38
- */
39
- public function admin_enqueue_scripts( $hook ) {
40
- do_action( SCF_Config::PREFIX . 'before-editor-enqueue-scripts' );
41
- wp_enqueue_style(
42
- SCF_Config::PREFIX . 'editor',
43
- plugins_url( SCF_Config::NAME ) . '/css/editor.css'
44
- );
45
- wp_enqueue_media();
46
- wp_enqueue_script(
47
- SCF_Config::PREFIX . 'editor',
48
- plugins_url( SCF_Config::NAME ) . '/js/editor.js',
49
- array( 'jquery' ),
50
- null,
51
- true
52
- );
53
- wp_localize_script( SCF_Config::PREFIX . 'editor', 'smart_cf_uploader', array(
54
- 'image_uploader_title' => esc_html__( 'Image setting', 'smart-custom-fields' ),
55
- 'file_uploader_title' => esc_html__( 'File setting', 'smart-custom-fields' ),
56
- ) );
57
- do_action( SCF_Config::PREFIX . 'after-editor-enqueue-scripts' );
58
  }
59
 
60
  /**
@@ -78,46 +40,6 @@ class Smart_Custom_Fields_Controller_Editor {
78
  }
79
  }
80
 
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;
93
- foreach ( $tables as $group_key => $Group ) {
94
- $is_repeatable = $Group->is_repeatable();
95
- if ( $is_repeatable && $index === 0 ) {
96
- printf(
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
- // ループを抜けたらカウントをもとに戻す
106
- if ( $is_repeatable &&
107
- isset( $tables[$group_key + 1 ] ) &&
108
- $tables[$group_key + 1 ]->get_name() === $Group->get_name() ) {
109
- $index ++;
110
- } else {
111
- $index = 0;
112
- }
113
- if ( $is_repeatable && $index === 0 ) {
114
- printf( '</div>' );
115
- }
116
- }
117
- printf( '</div>' );
118
- wp_nonce_field( SCF_Config::NAME . '-fields', SCF_Config::PREFIX . 'fields-nonce' );
119
- }
120
-
121
  /**
122
  * 投稿画面のカスタムフィールドからのメタデータを保存
123
  *
@@ -136,242 +58,4 @@ class Smart_Custom_Fields_Controller_Editor {
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
- // ループのときは、ループの分だけグループを追加する
190
- // ループだけどループがないとき(新規登録時とか)は1つだけ入れる
191
- if ( $Group->is_repeatable() === true ) {
192
- $loop_count = 1;
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
- }
215
- }
216
- if ( $loop_count >= 1 ) {
217
- for ( $i = $loop_count; $i > 0; $i -- ) {
218
- $tables[] = $Group;
219
- }
220
- continue;
221
- }
222
- }
223
- $tables[] = $Group;
224
- }
225
- return $tables;
226
- }
227
-
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
- }
263
- return $value;
264
- }
265
-
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
- }
282
-
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(
298
- '<span class="%s"></span>',
299
- esc_attr( SCF_Config::PREFIX . 'icon-handle dashicons dashicons-menu' )
300
- );
301
- $btn_repeat .= '<span class="btn-add-repeat-group dashicons dashicons-plus-alt '.SCF_Config::PREFIX.'repeat-btn"></span>';
302
- $btn_repeat .= ' <span class="btn-remove-repeat-group dashicons dashicons-dismiss '.SCF_Config::PREFIX.'repeat-btn"></span>';
303
- }
304
-
305
- $style = '';
306
- if ( is_null( $index ) ) {
307
- $style = 'style="display: none;"';
308
- }
309
-
310
- printf(
311
- '<div class="%s" %s>%s<table>',
312
- esc_attr( SCF_Config::PREFIX . 'meta-box-table' ),
313
- $style,
314
- $btn_repeat
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' );
321
- $field_label = $Field->get( 'label' );
322
- if ( !$field_label ) {
323
- $field_label = $field_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 {
337
- $value = '';
338
- if ( $post_status === 'auto-draft' || is_null( $index ) ) {
339
- if ( !SCF::is_empty( $default ) ) {
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;
347
- }
348
-
349
- $notes = $Field->get( 'notes' );
350
- if ( !empty( $notes ) ) {
351
- $notes = sprintf(
352
- '<p class="description">%s</p>',
353
- esc_html( $notes )
354
- );
355
- }
356
-
357
- $form_field = $Field->get_field( $index, $value );
358
- printf(
359
- '<tr><th>%s</th><td>%s%s</td></tr>',
360
- esc_html( $field_label ),
361
- $form_field,
362
- $notes
363
- );
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
- }
1
  <?php
2
  /**
3
  * Smart_Custom_Fields_Controller_Editor
4
+ * Version : 1.1.0
5
  * Author : Takashi Kitajima
6
  * Created : September 23, 2014
7
+ * Modified : April 28, 2015
8
  * License : GPLv2
9
  * License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
  */
11
+ class Smart_Custom_Fields_Controller_Editor extends Smart_Custom_Fields_Controller_Base {
 
 
 
 
 
 
 
 
 
 
 
 
12
 
13
  /**
14
  * __construct
15
  */
16
  public function __construct() {
17
+ parent::__construct();
18
+ add_action( 'add_meta_boxes', array( $this, 'add_meta_boxes' ), 10, 2 );
19
+ add_action( 'save_post' , array( $this, 'save_post' ) );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
  }
21
 
22
  /**
40
  }
41
  }
42
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43
  /**
44
  * 投稿画面のカスタムフィールドからのメタデータを保存
45
  *
58
 
59
  $this->save( $_POST, get_post( $post_id ) );
60
  }
61
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
classes/controller/class.profile.php CHANGED
@@ -1,20 +1,20 @@
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' ) );
@@ -35,7 +35,9 @@ class Smart_Custom_Fields_Controller_Profile extends Smart_Custom_Fields_Control
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' ) );
@@ -66,35 +68,6 @@ class Smart_Custom_Fields_Controller_Profile extends Smart_Custom_Fields_Control
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
- }
1
  <?php
2
  /**
3
  * Smart_Custom_Fields_Controller_Profile
4
+ * Version : 1.0.1
5
  * Author : Takashi Kitajima
6
  * Created : March 16, 2015
7
+ * Modified : April 26, 2015
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_Base {
12
 
13
  /**
14
  * __construct
15
  */
16
  public function __construct() {
17
+ parent::__construct();
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' ) );
35
  }
36
 
37
  /**
38
+ * カスタムフィールドを表示
39
+ *
40
+ * @param WP_User $user
41
  */
42
  public function user_profile( $user ) {
43
  printf( '<h3>%s</h3>', esc_html__( 'Custom Fields', 'smart-custom-fields' ) );
68
  return;
69
  }
70
 
 
71
  $this->save( $_POST, get_userdata( $user_id ) );
72
  }
73
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
classes/controller/class.settings.php CHANGED
@@ -1,10 +1,10 @@
1
  <?php
2
  /**
3
  * Smart_Custom_Fields_Controller_Settings
4
- * Version : 1.1.0
5
  * Author : Takashi Kitajima
6
  * Created : September 23, 2014
7
- * Modified : February 27, 2015
8
  * License : GPLv2
9
  * License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
  */
@@ -91,6 +91,13 @@ class Smart_Custom_Fields_Controller_Settings {
91
  SCF_Config::NAME,
92
  'side'
93
  );
 
 
 
 
 
 
 
94
  }
95
 
96
  /**
@@ -246,6 +253,32 @@ class Smart_Custom_Fields_Controller_Settings {
246
  );
247
  }
248
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
249
  /**
250
  * 設定を保存
251
  *
@@ -319,5 +352,11 @@ class Smart_Custom_Fields_Controller_Settings {
319
  } else {
320
  update_post_meta( $post_id, SCF_Config::PREFIX . 'roles', $_POST[SCF_Config::PREFIX . 'roles'] );
321
  }
 
 
 
 
 
 
322
  }
323
  }
1
  <?php
2
  /**
3
  * Smart_Custom_Fields_Controller_Settings
4
+ * Version : 1.2.0
5
  * Author : Takashi Kitajima
6
  * Created : September 23, 2014
7
+ * Modified : April 26, 2015
8
  * License : GPLv2
9
  * License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
  */
91
  SCF_Config::NAME,
92
  'side'
93
  );
94
+ add_meta_box(
95
+ SCF_Config::PREFIX . 'meta-box-condition-taxonomy',
96
+ __( 'Display conditions ( Taxonomy )', 'smart-custom-fields' ),
97
+ array( $this, 'display_meta_box_condition_taxonomy' ),
98
+ SCF_Config::NAME,
99
+ 'side'
100
+ );
101
  }
102
 
103
  /**
253
  );
254
  }
255
 
256
+ /**
257
+ * メタボックスの表示条件を設定するメタボックス(タクソノミー用)を表示
258
+ */
259
+ public function display_meta_box_condition_taxonomy() {
260
+ $taxonomies = get_taxonomies( array(
261
+ 'show_ui' => true,
262
+ ), 'objects' );
263
+ $conditions = get_post_meta( get_the_ID(), SCF_Config::PREFIX . 'taxonomies', true );
264
+ $taxonomy_field = '';
265
+ foreach ( $taxonomies as $name => $taxonomy ) {
266
+ $current = ( is_array( $conditions ) && in_array( $name, $conditions ) ) ? $name : false;
267
+ $taxonomy_field .= sprintf(
268
+ '<label><input type="checkbox" name="%s" value="%s" %s /> %s</label>',
269
+ esc_attr( SCF_Config::PREFIX . 'taxonomies[]' ),
270
+ esc_attr( $name ),
271
+ checked( $current, $name, false ),
272
+ esc_html__( $taxonomy->label, 'smart-custom-fields' )
273
+ );
274
+ }
275
+ printf(
276
+ '<p><b>%s</b>%s</p>',
277
+ esc_html__( 'Taxonomies', 'smart-custom-fields' ),
278
+ $taxonomy_field
279
+ );
280
+ }
281
+
282
  /**
283
  * 設定を保存
284
  *
352
  } else {
353
  update_post_meta( $post_id, SCF_Config::PREFIX . 'roles', $_POST[SCF_Config::PREFIX . 'roles'] );
354
  }
355
+
356
+ if ( !isset( $_POST[SCF_Config::PREFIX . 'taxonomies'] ) ) {
357
+ delete_post_meta( $post_id, SCF_Config::PREFIX . 'taxonomies' );
358
+ } else {
359
+ update_post_meta( $post_id, SCF_Config::PREFIX . 'taxonomies', $_POST[SCF_Config::PREFIX . 'taxonomies'] );
360
+ }
361
  }
362
  }
classes/controller/class.taxonomy.php ADDED
@@ -0,0 +1,94 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Smart_Custom_Fields_Controller_Taxonomy
4
+ * Version : 1.0.0
5
+ * Author : Takashi Kitajima
6
+ * Created : April 26, 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_Taxonomy extends Smart_Custom_Fields_Controller_Base {
12
+
13
+ /**
14
+ * タクソノミーの名前
15
+ * @var string
16
+ */
17
+ protected $taxonomy;
18
+
19
+ /**
20
+ * __construct
21
+ */
22
+ public function __construct() {
23
+ parent::__construct();
24
+
25
+ $this->taxonomy = $_REQUEST['taxonomy'];
26
+ add_action( $this->taxonomy . '_edit_form_fields', array( $this, 'edit_form_fields' ) );
27
+ add_action( 'edited_terms' , array( $this, 'update' ), 10, 2 );
28
+ add_action( 'delete_term' , array( $this, 'delete' ), 10, 4 );
29
+ }
30
+
31
+ /**
32
+ * 投稿画面用の css、js、翻訳ファイルのロード
33
+ *
34
+ * @param string $hook
35
+ */
36
+ public function admin_enqueue_scripts( $hook ) {
37
+ parent::admin_enqueue_scripts( $hook );
38
+ wp_enqueue_style(
39
+ SCF_Config::PREFIX . 'taxonomy',
40
+ plugins_url( SCF_Config::NAME ) . '/css/taxonomy.css'
41
+ );
42
+ }
43
+
44
+ /**
45
+ * カスタムフィールドを表示
46
+ *
47
+ * @param object $term
48
+ */
49
+ public function edit_form_fields( $term ) {
50
+ $settings = SCF::get_settings( $term );
51
+ foreach ( $settings as $Setting ) {
52
+ $callback_args['args'] = $Setting->get_groups();
53
+ ?>
54
+ <table class="form-table">
55
+ <tr>
56
+ <th scope="row"><?php echo esc_html( $Setting->get_title() ); ?></th>
57
+ <td><?php $this->display_meta_box( $term, $callback_args ); ?></td>
58
+ </tr>
59
+ </table>
60
+ <?php
61
+ }
62
+ }
63
+
64
+ /**
65
+ * 投稿画面のカスタムフィールドからのメタデータを保存
66
+ *
67
+ * @param int $term_id
68
+ * @param string $taxonomy
69
+ */
70
+ public function update( $term_id, $taxonomy ) {
71
+ if ( !current_user_can( 'manage_categories' ) ) {
72
+ return;
73
+ }
74
+ if ( !isset( $_POST[SCF_Config::NAME] ) ) {
75
+ return;
76
+ }
77
+
78
+ $term = get_term( $term_id, $taxonomy );
79
+ $this->save( $_POST, $term );
80
+ }
81
+
82
+ /**
83
+ * メタデータの削除
84
+ *
85
+ * @param int $term_id
86
+ * @param int $term_taxonomy_id
87
+ * @param string $taxonomy
88
+ * @param object $deleted_term
89
+ */
90
+ public function delete( $term_id, $term_taxonomy_id, $taxonomy, $deleted_term ) {
91
+ $Meta = new Smart_Custom_Fields_Meta( $deleted_term );
92
+ $Meta->delete();
93
+ }
94
+ }
classes/fields/class.field-relation.php CHANGED
@@ -1,10 +1,10 @@
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
  */
@@ -45,7 +45,7 @@ class Smart_Custom_Fields_Field_Relation extends Smart_Custom_Fields_Field_Base
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',
1
  <?php
2
  /**
3
  * Smart_Custom_Fields_Field_Relation
4
+ * Version : 1.2.0
5
  * Author : Takashi Kitajima
6
  * Created : October 7, 2014
7
+ * Modified : April 26, 2015
8
  * License : GPLv2
9
  * License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
  */
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', 'edit-tags.php' ) ) ) {
49
  wp_enqueue_script(
50
  SCF_Config::PREFIX . 'editor-relation',
51
  plugins_url( SCF_Config::NAME ) . '/js/editor-relation.js',
classes/models/class.ajax.php ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Smart_Custom_Fields_Ajax
4
+ * Version : 1.1.0
5
+ * Author : Takashi Kitajima
6
+ * Created : April 27, 2015
7
+ * Modified :
8
+ * License : GPLv2
9
+ * License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
+ */
11
+ class Smart_Custom_Fields_Ajax {
12
+
13
+ /**
14
+ * Ajax リクエストのときだけ発火させたい処理をフックさせる
15
+ */
16
+ public function __construct() {
17
+ if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
18
+ add_action( 'delete_term', array( $this, 'delete_term' ), 10, 4 );
19
+ }
20
+ }
21
+
22
+ /**
23
+ * タームのメタ情報を削除
24
+ *
25
+ * @param int $term_id
26
+ * @param int $term_taxonomy_id
27
+ * @param string $taxonomy
28
+ * @param object $deleted_term
29
+ */
30
+ public function delete_term( $term_id, $term_taxonomy_id, $taxonomy, $deleted_term ) {
31
+ $Meta = new Smart_Custom_Fields_Meta( $deleted_term );
32
+ $Meta->delete();
33
+ }
34
+ }
classes/models/class.meta.php CHANGED
@@ -1,53 +1,67 @@
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
  }
@@ -55,14 +69,14 @@ class Smart_Custom_Fields_Meta {
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
  */
@@ -71,7 +85,7 @@ class Smart_Custom_Fields_Meta {
71
  }
72
 
73
  /**
74
- * 投稿タイプもしくはロールを取得
75
  *
76
  * @param bool $accept_revision 投稿タイプだった場合に、投稿タイプ revision を許可
77
  * @return string
@@ -101,15 +115,85 @@ class Smart_Custom_Fields_Meta {
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
  /**
@@ -125,7 +209,30 @@ class Smart_Custom_Fields_Meta {
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;
@@ -144,7 +251,17 @@ class Smart_Custom_Fields_Meta {
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;
@@ -157,8 +274,34 @@ class Smart_Custom_Fields_Meta {
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
  /**
@@ -181,6 +324,9 @@ class Smart_Custom_Fields_Meta {
181
  case 'user' :
182
  $object = get_userdata( $this->id );
183
  break;
 
 
 
184
  default :
185
  $object = null;
186
  }
@@ -292,4 +438,17 @@ class Smart_Custom_Fields_Meta {
292
  $this->delete( $repeat_multiple_data_name );
293
  $this->update( $repeat_multiple_data_name, $repeat_multiple_data );
294
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
295
  }
1
  <?php
2
  /**
3
  * Smart_Custom_Fields_Meta
4
+ * Version : 1.1.0
5
  * Author : Takashi Kitajima
6
  * Created : March 17, 2015
7
+ * Modified : April 26, 2015
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
+ * @var WP_Post|WP_User|object
15
+ */
16
+ protected $object;
17
+
18
  /**
19
  * 投稿のメタデータを扱うか、ユーザーのメタデータを扱うか
20
+ * @var string post or user or term
21
  */
22
  protected $meta_type = 'post';
23
 
24
  /**
25
+ * 投稿ID or ユーザーID or タームID
26
  * @var int
27
  */
28
  protected $id;
29
 
30
  /**
31
+ * 投稿タイプ or ロール or タクソノミー
32
  * @var string
33
  */
34
  protected $type;
35
 
36
  /**
37
+ * @param WP_Post|WP_User|object $object
38
  */
39
  public function __construct( $object ) {
40
  if ( !function_exists( 'get_editable_roles' ) ) {
41
  require_once( ABSPATH . '/wp-admin/includes/user.php' );
42
  }
43
+ $this->object = $object;
44
  if ( is_a( $object, 'WP_Post' ) ) {
45
  $this->id = $object->ID;
46
  $this->type = $object->post_type;
47
  $this->meta_type = 'post';
48
+ }
49
+ elseif ( is_a( $object, 'WP_User' ) ) {
50
  $this->id = $object->ID;
51
  $this->type = $object->roles[0];
52
  $this->meta_type = 'user';
53
+ }
54
+ elseif ( isset( $object->term_id ) ) {
55
+ $this->id = $object->term_id;
56
+ $this->type = $object->taxonomy;
57
+ $this->meta_type = 'term';
58
+ }
59
+ elseif( empty( $object ) || is_wp_error( $object ) ) {
60
  $this->id = null;
61
  $this->type = null;
62
  $this->meta_type = null;
63
+ }
64
+ else {
65
  throw new Exception( sprintf( 'Invalid $object type error. $object is "%s".', get_class( $object ) ) );
66
  }
67
  }
69
  /**
70
  * メタタイプを取得
71
  *
72
+ * @return string post or user or term
73
  */
74
  public function get_meta_type() {
75
  return $this->meta_type;
76
  }
77
 
78
  /**
79
+ * 投稿ID or ユーザーID or タームIDを取得
80
  *
81
  * @return int
82
  */
85
  }
86
 
87
  /**
88
+ * 投稿タイプ or ロール or タクソノミーを取得
89
  *
90
  * @param bool $accept_revision 投稿タイプだった場合に、投稿タイプ revision を許可
91
  * @return string
115
  return $this->type;
116
  }
117
 
118
+ /**
119
+ * 指定されたキーのカスタムフィールドが既に保存されているか
120
+ *
121
+ * @param string $key
122
+ * @return bool
123
+ */
124
+ public function is_saved_by_key( $key ) {
125
+ if ( _get_meta_table( $this->meta_type ) ) {
126
+ if ( $this->meta_type === 'post' ) {
127
+ $meta = get_post_custom_values( $key, $this->id );
128
+ if ( !is_null( $meta ) ) {
129
+ return true;
130
+ }
131
+ }
132
+ elseif ( $this->meta_type === 'user' ) {
133
+ $meta = get_user_option( $key, $this->id );
134
+ if ( $meta !== false ) {
135
+ return true;
136
+ }
137
+ }
138
+ } else {
139
+ $meta = get_option( $this->get_option_name() );
140
+ if ( isset( $meta[$key] ) ) {
141
+ return true;
142
+ }
143
+ }
144
+ return false;
145
+ }
146
+
147
+ /**
148
+ * $is_use_default_when_not_saved が true = true // 1.3.x までは false
149
+ * $is_use_default_when_not_saved が false で meta_type が post で post_status が auto-draft = true
150
+ *
151
+ * @return bool
152
+ */
153
+ public function is_use_default_when_not_saved() {
154
+ $use_default_when_not_saved = apply_filters( SCF_Config::PREFIX . 'is_use_default_when_not_saved', true );
155
+ if (
156
+ $use_default_when_not_saved !== false
157
+ ||
158
+ $use_default_when_not_saved === false && $this->meta_type === 'post' && in_array( get_post_status( $this->object ), array( 'auto-draft' ) )
159
+ ) {
160
+ return true;
161
+ }
162
+ return false;
163
+ }
164
+
165
  /**
166
  * メタデータを取得
167
  *
168
  * @param string $key メタキー
169
  * @param bool $single false だと配列で取得、true だと文字列で取得
170
+ * @return string|array
171
  */
172
  public function get( $key = '', $single = false ) {
173
+ if ( _get_meta_table( $this->meta_type ) ) {
174
+ return get_metadata( $this->meta_type, $this->id, $key, $single );
175
+ } else {
176
+ $option = get_option( $this->get_option_name() );
177
+ if ( $key !=='' && isset( $option[$key] ) ) {
178
+ if ( $single && is_array( $option[$key] ) ) {
179
+ if ( isset( $option[$key][0] ) ) {
180
+ return $option[$key][0];
181
+ }
182
+ } else {
183
+ return $option[$key];
184
+ }
185
+ }
186
+
187
+ if ( $key === '' && $option !== false ) {
188
+ return $option;
189
+ }
190
+
191
+ // get_metadata は存在しないとき空文字を返すので揃える
192
+ if ( $single ) {
193
+ return '';
194
+ }
195
+ return array();
196
+ }
197
  }
198
 
199
  /**
209
  do_action( SCF_Config::PREFIX . '-before-save-' . $this->meta_type, $this->id, $key, $value );
210
  $is_valid = apply_filters( SCF_Config::PREFIX . '-validate-save-' . $this->meta_type, $this->id, $key, $value );
211
  if ( $is_valid ) {
212
+ if ( _get_meta_table( $this->meta_type ) ) {
213
+ $return = update_metadata( $this->meta_type, $this->id, $key, $value, $prev_value );
214
+ } else {
215
+ $option_name = $this->get_option_name();
216
+ $option = get_option( $option_name );
217
+ if ( isset( $option[$key] ) ) {
218
+ if ( $prev_value !== '' ) {
219
+ foreach( $option[$key] as $option_key => $option_value ) {
220
+ if ( $prev_value === $option_value ) {
221
+ $option[$key][$option_key] = $value;
222
+ break;
223
+ }
224
+ }
225
+ } else {
226
+ foreach( $option[$key] as $option_key => $option_value ) {
227
+ $option[$key][$option_key] = $value;
228
+ }
229
+ }
230
+ } else {
231
+ $option[$key][] = $value;
232
+ }
233
+ $option = stripslashes_deep( $option );
234
+ $return = update_option( $option_name, $option, false );
235
+ }
236
  }
237
  do_action( SCF_Config::PREFIX . '-after-save-' . $this->meta_type, $this->id, $key, $value );
238
  return $return;
251
  do_action( SCF_Config::PREFIX . '-before-save-' . $this->meta_type, $this->id, $key, $value );
252
  $is_valid = apply_filters( SCF_Config::PREFIX . '-validate-save-' . $this->meta_type, $this->id, $key, $value );
253
  if ( $is_valid ) {
254
+ if ( _get_meta_table( $this->meta_type ) ) {
255
+ $return = add_metadata( $this->meta_type, $this->id, $key, $value, $unique );
256
+ } else {
257
+ $option_name = $this->get_option_name();
258
+ $option = get_option( $option_name );
259
+ if ( !$unique || !isset( $option[$key] ) ) {
260
+ $option[$key][] = $value;
261
+ $option = stripslashes_deep( $option );
262
+ $return = update_option( $option_name, $option, false );
263
+ }
264
+ }
265
  }
266
  do_action( SCF_Config::PREFIX . '-after-save-' . $this->meta_type, $this->id, $key, $value );
267
  return $return;
274
  * @param mixed $value 指定した場合、その値をもつメタデータのみ削除
275
  * @return bool
276
  */
277
+ public function delete( $key = '', $value = '' ) {
278
+ if ( _get_meta_table( $this->meta_type ) ) {
279
+ if ( $key ) {
280
+ return delete_metadata( $this->meta_type, $this->id, $key, $value );
281
+ }
282
+ } else {
283
+ $option_name = $this->get_option_name();
284
+
285
+ if ( !$key ) {
286
+ return delete_option( $option_name );
287
+ }
288
+
289
+ $option = get_option( $option_name );
290
+
291
+ if ( isset( $option[$key] ) && $value === '' ) {
292
+ unset( $option[$key] );
293
+ return update_option( $option_name, $option );
294
+ }
295
+
296
+ if ( isset( $option[$key] ) && $value !== '' ) {
297
+ foreach ( $option[$key] as $option_key => $option_value ) {
298
+ if ( $option_value === $value ) {
299
+ unset( $option[$key][$option_key] );
300
+ }
301
+ }
302
+ return update_option( $option_name, $option );
303
+ }
304
+ }
305
  }
306
 
307
  /**
324
  case 'user' :
325
  $object = get_userdata( $this->id );
326
  break;
327
+ case 'term' :
328
+ $object = get_term( $this->id, $this->type );
329
+ break;
330
  default :
331
  $object = null;
332
  }
438
  $this->delete( $repeat_multiple_data_name );
439
  $this->update( $repeat_multiple_data_name, $repeat_multiple_data );
440
  }
441
+
442
+ /**
443
+ * options テーブルに保存するためのオプション名を取得
444
+ */
445
+ protected function get_option_name() {
446
+ return sprintf(
447
+ '%s%s-%s-%d',
448
+ SCF_Config::PREFIX,
449
+ $this->meta_type,
450
+ $this->type,
451
+ $this->id
452
+ );
453
+ }
454
  }
css/settings.css CHANGED
@@ -1,9 +1,9 @@
1
  /**
2
  * settings.css
3
- * Version : 1.0.2
4
  * Author : Takashi Kitajima
5
  * Created : September 23, 2014
6
- * Modified : April 11, 2015
7
  * License : GPLv2
8
  * License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
  */
@@ -175,12 +175,14 @@
175
  * #smart-cf-meta-box-condition
176
  */
177
  #smart-cf-meta-box-condition-post b,
178
- #smart-cf-meta-box-condition-profile b {
 
179
  display: block;
180
  margin: 0 0 5px;
181
  }
182
  #smart-cf-meta-box-condition-post label,
183
- #smart-cf-meta-box-condition-profile label {
 
184
  display: block;
185
  margin: 0 0 5px;
186
  }
1
  /**
2
  * settings.css
3
+ * Version : 1.0.3
4
  * Author : Takashi Kitajima
5
  * Created : September 23, 2014
6
+ * Modified : April 26, 2015
7
  * License : GPLv2
8
  * License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
  */
175
  * #smart-cf-meta-box-condition
176
  */
177
  #smart-cf-meta-box-condition-post b,
178
+ #smart-cf-meta-box-condition-profile b,
179
+ #smart-cf-meta-box-condition-taxonomy b {
180
  display: block;
181
  margin: 0 0 5px;
182
  }
183
  #smart-cf-meta-box-condition-post label,
184
+ #smart-cf-meta-box-condition-profile label,
185
+ #smart-cf-meta-box-condition-taxonomy label {
186
  display: block;
187
  margin: 0 0 5px;
188
  }
css/taxonomy.css ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * taxonomy.css
3
+ * Version : 1.0.0
4
+ * Author : Takashi Kitajima
5
+ * Created : April 26, 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-table
13
+ */
14
+ .smart-cf-meta-box-table {
15
+ background: transparent;
16
+ border-bottom-color: #ddd;
17
+ }
languages/smart-custom-fields-ja.mo CHANGED
Binary file
languages/smart-custom-fields-ja.po CHANGED
@@ -2,10 +2,10 @@
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.2\n"
6
  "Report-Msgid-Bugs-To: http://wordpress.org/tag/smart-custom-fields\n"
7
- "POT-Creation-Date: 2015-04-24 02:00:47+00:00\n"
8
- "PO-Revision-Date: 2015-04-24 11:01+0900\n"
9
  "Last-Translator: Takashi Kitajima <inc@2inc.org>\n"
10
  "Language-Team: \n"
11
  "Language: ja\n"
@@ -18,15 +18,15 @@ msgstr ""
18
  "X-Poedit-Basepath: .\n"
19
  "X-Poedit-SearchPath-0: ..\n"
20
 
21
- #: classes/controller/class.editor.php:54
22
  msgid "Image setting"
23
  msgstr "画像設定"
24
 
25
- #: classes/controller/class.editor.php:55
26
  msgid "File setting"
27
  msgstr "ファイル設定"
28
 
29
- #: classes/controller/class.profile.php:41
30
  #: classes/controller/class.settings.php:76
31
  msgid "Custom Fields"
32
  msgstr "カスタムフィールド"
@@ -59,31 +59,39 @@ msgstr "表示条件(投稿)"
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:188
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-boolean.php:24
88
  msgid "Boolean"
89
  msgstr "真偽値"
@@ -260,45 +268,45 @@ msgid "Group name"
260
  msgstr "グループ名"
261
 
262
  #. Plugin Name of the plugin/theme
263
- #: classes/models/class.revisions.php:117 smart-custom-fields.php:130
264
- #: smart-custom-fields.php:131 smart-custom-fields.php:132
265
  msgid "Smart Custom Fields"
266
  msgstr "Smart Custom Fields"
267
 
268
- #: smart-custom-fields.php:133 smart-custom-fields.php:134
269
- #: smart-custom-fields.php:173 smart-custom-fields.php:174
270
  msgid "Add New"
271
  msgstr "新規追加"
272
 
273
- #: smart-custom-fields.php:135
274
  msgid "New Field"
275
  msgstr "新規フィールド"
276
 
277
- #: smart-custom-fields.php:136
278
  msgid "Edit Field"
279
  msgstr "フィールド編集"
280
 
281
- #: smart-custom-fields.php:137
282
  msgid "View Field"
283
  msgstr "フィールドを表示"
284
 
285
- #: smart-custom-fields.php:138
286
  msgid "All Fields"
287
  msgstr "すべてのフィールド"
288
 
289
- #: smart-custom-fields.php:139
290
  msgid "Search Fields"
291
  msgstr "フィールドを検索"
292
 
293
- #: smart-custom-fields.php:140
294
  msgid "Parent Fields:"
295
  msgstr "親フィールド:"
296
 
297
- #: smart-custom-fields.php:141
298
  msgid "No Fields found."
299
  msgstr "フィールドは見つかりませんでした。"
300
 
301
- #: smart-custom-fields.php:142
302
  msgid "No Fields found in Trash."
303
  msgstr "ゴミ箱にフィールドは見つかりませんでした"
304
 
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.4.0\n"
6
  "Report-Msgid-Bugs-To: http://wordpress.org/tag/smart-custom-fields\n"
7
+ "POT-Creation-Date: 2015-04-29 04:43:41+00:00\n"
8
+ "PO-Revision-Date: 2015-04-29 13:44+0900\n"
9
  "Last-Translator: Takashi Kitajima <inc@2inc.org>\n"
10
  "Language-Team: \n"
11
  "Language: ja\n"
18
  "X-Poedit-Basepath: .\n"
19
  "X-Poedit-SearchPath-0: ..\n"
20
 
21
+ #: classes/controller/class.controller-base.php:46
22
  msgid "Image setting"
23
  msgstr "画像設定"
24
 
25
+ #: classes/controller/class.controller-base.php:47
26
  msgid "File setting"
27
  msgstr "ファイル設定"
28
 
29
+ #: classes/controller/class.profile.php:43
30
  #: classes/controller/class.settings.php:76
31
  msgid "Custom Fields"
32
  msgstr "カスタムフィールド"
59
  msgid "Display conditions ( Profile )"
60
  msgstr "表示条件(プロフィール)"
61
 
62
+ #: classes/controller/class.settings.php:96
63
+ msgid "Display conditions ( Taxonomy )"
64
+ msgstr "表示条件(タクソノミー)"
65
+
66
+ #: classes/controller/class.settings.php:150
67
  msgid "Type"
68
  msgstr "タイプ"
69
 
70
+ #: classes/controller/class.settings.php:185
71
  msgid "Add Sub field"
72
  msgstr "サブフィールドを追加"
73
 
74
+ #: classes/controller/class.settings.php:189
75
  msgid "Add Field"
76
  msgstr "フィールド追加"
77
 
78
+ #: classes/controller/class.settings.php:219
79
  #: classes/fields/class.field-relation.php:188
80
  msgid "Post Types"
81
  msgstr "投稿タイプ"
82
 
83
+ #: classes/controller/class.settings.php:226
84
  msgid "Post Ids ( Comma separated )"
85
  msgstr "投稿 ID (カンマ区切り)"
86
 
87
+ #: classes/controller/class.settings.php:251
88
  msgid "Roles"
89
  msgstr "権限"
90
 
91
+ #: classes/controller/class.settings.php:277
92
+ msgid "Taxonomies"
93
+ msgstr "タクソノミー"
94
+
95
  #: classes/fields/class.field-boolean.php:24
96
  msgid "Boolean"
97
  msgstr "真偽値"
268
  msgstr "グループ名"
269
 
270
  #. Plugin Name of the plugin/theme
271
+ #: classes/models/class.revisions.php:117 smart-custom-fields.php:157
272
+ #: smart-custom-fields.php:158 smart-custom-fields.php:159
273
  msgid "Smart Custom Fields"
274
  msgstr "Smart Custom Fields"
275
 
276
+ #: smart-custom-fields.php:160 smart-custom-fields.php:161
277
+ #: smart-custom-fields.php:207 smart-custom-fields.php:208
278
  msgid "Add New"
279
  msgstr "新規追加"
280
 
281
+ #: smart-custom-fields.php:162
282
  msgid "New Field"
283
  msgstr "新規フィールド"
284
 
285
+ #: smart-custom-fields.php:163
286
  msgid "Edit Field"
287
  msgstr "フィールド編集"
288
 
289
+ #: smart-custom-fields.php:164
290
  msgid "View Field"
291
  msgstr "フィールドを表示"
292
 
293
+ #: smart-custom-fields.php:165
294
  msgid "All Fields"
295
  msgstr "すべてのフィールド"
296
 
297
+ #: smart-custom-fields.php:166
298
  msgid "Search Fields"
299
  msgstr "フィールドを検索"
300
 
301
+ #: smart-custom-fields.php:167
302
  msgid "Parent Fields:"
303
  msgstr "親フィールド:"
304
 
305
+ #: smart-custom-fields.php:168
306
  msgid "No Fields found."
307
  msgstr "フィールドは見つかりませんでした。"
308
 
309
+ #: smart-custom-fields.php:169
310
  msgid "No Fields found in Trash."
311
  msgstr "ゴミ箱にフィールドは見つかりませんでした"
312
 
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.3.2\n"
6
  "Report-Msgid-Bugs-To: http://wordpress.org/tag/smart-custom-fields\n"
7
- "POT-Creation-Date: 2015-04-24 02:00:47+00:00\n"
8
  "MIME-Version: 1.0\n"
9
  "Content-Type: text/plain; charset=UTF-8\n"
10
  "Content-Transfer-Encoding: 8bit\n"
@@ -12,15 +12,15 @@ msgstr ""
12
  "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
13
  "Language-Team: LANGUAGE <LL@li.org>\n"
14
 
15
- #: classes/controller/class.editor.php:54
16
  msgid "Image setting"
17
  msgstr ""
18
 
19
- #: classes/controller/class.editor.php:55
20
  msgid "File setting"
21
  msgstr ""
22
 
23
- #: classes/controller/class.profile.php:41
24
  #: classes/controller/class.settings.php:76
25
  msgid "Custom Fields"
26
  msgstr ""
@@ -53,31 +53,39 @@ msgstr ""
53
  msgid "Display conditions ( Profile )"
54
  msgstr ""
55
 
56
- #: classes/controller/class.settings.php:143
 
 
 
 
57
  msgid "Type"
58
  msgstr ""
59
 
60
- #: classes/controller/class.settings.php:178
61
  msgid "Add Sub field"
62
  msgstr ""
63
 
64
- #: classes/controller/class.settings.php:182
65
  msgid "Add Field"
66
  msgstr ""
67
 
68
- #: classes/controller/class.settings.php:212
69
  #: classes/fields/class.field-relation.php:188
70
  msgid "Post Types"
71
  msgstr ""
72
 
73
- #: classes/controller/class.settings.php:219
74
  msgid "Post Ids ( Comma separated )"
75
  msgstr ""
76
 
77
- #: classes/controller/class.settings.php:244
78
  msgid "Roles"
79
  msgstr ""
80
 
 
 
 
 
81
  #: classes/fields/class.field-boolean.php:24
82
  msgid "Boolean"
83
  msgstr ""
@@ -253,47 +261,47 @@ msgstr ""
253
  msgid "Group name"
254
  msgstr ""
255
 
256
- #. #-#-#-#-# smart-custom-fields.pot (Smart Custom Fields 1.3.2) #-#-#-#-#
257
  #. Plugin Name of the plugin/theme
258
- #: classes/models/class.revisions.php:117 smart-custom-fields.php:130
259
- #: smart-custom-fields.php:131 smart-custom-fields.php:132
260
  msgid "Smart Custom Fields"
261
  msgstr ""
262
 
263
- #: smart-custom-fields.php:133 smart-custom-fields.php:134
264
- #: smart-custom-fields.php:173 smart-custom-fields.php:174
265
  msgid "Add New"
266
  msgstr ""
267
 
268
- #: smart-custom-fields.php:135
269
  msgid "New Field"
270
  msgstr ""
271
 
272
- #: smart-custom-fields.php:136
273
  msgid "Edit Field"
274
  msgstr ""
275
 
276
- #: smart-custom-fields.php:137
277
  msgid "View Field"
278
  msgstr ""
279
 
280
- #: smart-custom-fields.php:138
281
  msgid "All Fields"
282
  msgstr ""
283
 
284
- #: smart-custom-fields.php:139
285
  msgid "Search Fields"
286
  msgstr ""
287
 
288
- #: smart-custom-fields.php:140
289
  msgid "Parent Fields:"
290
  msgstr ""
291
 
292
- #: smart-custom-fields.php:141
293
  msgid "No Fields found."
294
  msgstr ""
295
 
296
- #: smart-custom-fields.php:142
297
  msgid "No Fields found in Trash."
298
  msgstr ""
299
 
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.4.0\n"
6
  "Report-Msgid-Bugs-To: http://wordpress.org/tag/smart-custom-fields\n"
7
+ "POT-Creation-Date: 2015-04-29 04:43:41+00:00\n"
8
  "MIME-Version: 1.0\n"
9
  "Content-Type: text/plain; charset=UTF-8\n"
10
  "Content-Transfer-Encoding: 8bit\n"
12
  "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
13
  "Language-Team: LANGUAGE <LL@li.org>\n"
14
 
15
+ #: classes/controller/class.controller-base.php:46
16
  msgid "Image setting"
17
  msgstr ""
18
 
19
+ #: classes/controller/class.controller-base.php:47
20
  msgid "File setting"
21
  msgstr ""
22
 
23
+ #: classes/controller/class.profile.php:43
24
  #: classes/controller/class.settings.php:76
25
  msgid "Custom Fields"
26
  msgstr ""
53
  msgid "Display conditions ( Profile )"
54
  msgstr ""
55
 
56
+ #: classes/controller/class.settings.php:96
57
+ msgid "Display conditions ( Taxonomy )"
58
+ msgstr ""
59
+
60
+ #: classes/controller/class.settings.php:150
61
  msgid "Type"
62
  msgstr ""
63
 
64
+ #: classes/controller/class.settings.php:185
65
  msgid "Add Sub field"
66
  msgstr ""
67
 
68
+ #: classes/controller/class.settings.php:189
69
  msgid "Add Field"
70
  msgstr ""
71
 
72
+ #: classes/controller/class.settings.php:219
73
  #: classes/fields/class.field-relation.php:188
74
  msgid "Post Types"
75
  msgstr ""
76
 
77
+ #: classes/controller/class.settings.php:226
78
  msgid "Post Ids ( Comma separated )"
79
  msgstr ""
80
 
81
+ #: classes/controller/class.settings.php:251
82
  msgid "Roles"
83
  msgstr ""
84
 
85
+ #: classes/controller/class.settings.php:277
86
+ msgid "Taxonomies"
87
+ msgstr ""
88
+
89
  #: classes/fields/class.field-boolean.php:24
90
  msgid "Boolean"
91
  msgstr ""
261
  msgid "Group name"
262
  msgstr ""
263
 
264
+ #. #-#-#-#-# smart-custom-fields.pot (Smart Custom Fields 1.4.0) #-#-#-#-#
265
  #. Plugin Name of the plugin/theme
266
+ #: classes/models/class.revisions.php:117 smart-custom-fields.php:157
267
+ #: smart-custom-fields.php:158 smart-custom-fields.php:159
268
  msgid "Smart Custom Fields"
269
  msgstr ""
270
 
271
+ #: smart-custom-fields.php:160 smart-custom-fields.php:161
272
+ #: smart-custom-fields.php:207 smart-custom-fields.php:208
273
  msgid "Add New"
274
  msgstr ""
275
 
276
+ #: smart-custom-fields.php:162
277
  msgid "New Field"
278
  msgstr ""
279
 
280
+ #: smart-custom-fields.php:163
281
  msgid "Edit Field"
282
  msgstr ""
283
 
284
+ #: smart-custom-fields.php:164
285
  msgid "View Field"
286
  msgstr ""
287
 
288
+ #: smart-custom-fields.php:165
289
  msgid "All Fields"
290
  msgstr ""
291
 
292
+ #: smart-custom-fields.php:166
293
  msgid "Search Fields"
294
  msgstr ""
295
 
296
+ #: smart-custom-fields.php:167
297
  msgid "Parent Fields:"
298
  msgstr ""
299
 
300
+ #: smart-custom-fields.php:168
301
  msgid "No Fields found."
302
  msgstr ""
303
 
304
+ #: smart-custom-fields.php:169
305
  msgid "No Fields found in Trash."
306
  msgstr ""
307
 
readme.txt CHANGED
@@ -3,8 +3,8 @@ Contributors: inc2734, toro_unit
3
  Donate link: http://www.amazon.co.jp/registry/wishlist/39ANKRNSTNW40
4
  Tags: plugin, custom field, custom, field, meta, meta field, repeat, repeatable
5
  Requires at least: 3.9
6
- Tested up to: 4.1.1
7
- Stable tag: 1.3.2
8
  License: GPLv2
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -39,7 +39,6 @@ https://www.youtube.com/watch?v=WxPZurn0yvI
39
 
40
  * SCF::get( 'field-name' )
41
  This method can get any meta data.
42
-
43
  * SCF::get( 'group-name' )
44
  This method can get meta data of any group.
45
 
@@ -48,13 +47,18 @@ This method can get all meta data.
48
 
49
  * SCF::get_user_meta( $user_id, 'field-name' )
50
  This method can get any user meta data.
51
-
52
  * SCF::get_user_meta( $user_id, 'group-name' )
53
  This method can get user meta data of any group.
54
-
55
  * SCF::get_user_meta( $user_id )
56
  This method can get all user meta data.
57
 
 
 
 
 
 
 
 
58
  = Register custom fields by the code. =
59
 
60
  https://gist.github.com/inc2734/9f6d65c7473d060d0fd6
@@ -82,6 +86,12 @@ You can send your own language pack to me.
82
 
83
  == Changelog ==
84
 
 
 
 
 
 
 
85
  = 1.3.2 =
86
  * Add preview size setting in the image field.
87
  * Add display direction setting in the checkbox and radio field.
3
  Donate link: http://www.amazon.co.jp/registry/wishlist/39ANKRNSTNW40
4
  Tags: plugin, custom field, custom, field, meta, meta field, repeat, repeatable
5
  Requires at least: 3.9
6
+ Tested up to: 4.2.1
7
+ Stable tag: 1.4.0
8
  License: GPLv2
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
39
 
40
  * SCF::get( 'field-name' )
41
  This method can get any meta data.
 
42
  * SCF::get( 'group-name' )
43
  This method can get meta data of any group.
44
 
47
 
48
  * SCF::get_user_meta( $user_id, 'field-name' )
49
  This method can get any user meta data.
 
50
  * SCF::get_user_meta( $user_id, 'group-name' )
51
  This method can get user meta data of any group.
 
52
  * SCF::get_user_meta( $user_id )
53
  This method can get all user meta data.
54
 
55
+ * SCF::get_term_meta( $term_id, $taxonomy 'field-name' )
56
+ This method can get any term meta data.
57
+ * SCF::get_term_meta( $term_id, $taxonomy, 'group-name' )
58
+ This method can get term meta data of any group.
59
+ * SCF::get_term_meta( $term_id, $taxonomy )
60
+ This method can get all term meta data.
61
+
62
  = Register custom fields by the code. =
63
 
64
  https://gist.github.com/inc2734/9f6d65c7473d060d0fd6
86
 
87
  == Changelog ==
88
 
89
+ = 1.4.0 =
90
+ * refactoring controllers.
91
+ * Add term custom fields.
92
+ * Add filter hook smart-cf-is_use_default_when_not_saved
93
+ * Changed to the default value is used if the value has not been saved. If you want to revert to the previous behavior, return false in smart-cf-is_use_default_when_not_saved.
94
+
95
  = 1.3.2 =
96
  * Add preview size setting in the image field.
97
  * Add display direction setting in the checkbox and radio 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.3.2
7
  * Author: Takashi Kitajima
8
  * Author URI: http://2inc.org
9
  * Created: October 9, 2014
10
- * Modified: April 24, 2015
11
  * Text Domain: smart-custom-fields
12
  * Domain Path: /languages
13
  * License: GPLv2
@@ -47,6 +47,7 @@ class Smart_Custom_Fields {
47
  require_once plugin_dir_path( __FILE__ ) . 'classes/models/class.group.php';
48
  require_once plugin_dir_path( __FILE__ ) . 'classes/models/class.abstract-field-base.php';
49
  require_once plugin_dir_path( __FILE__ ) . 'classes/models/class.revisions.php';
 
50
  require_once plugin_dir_path( __FILE__ ) . 'classes/class.scf.php';
51
  new Smart_Custom_Fields_Revisions();
52
 
@@ -61,6 +62,7 @@ class Smart_Custom_Fields {
61
  do_action( SCF_Config::PREFIX . 'fields-loaded' );
62
 
63
  add_action( 'init' , array( $this, 'register_post_type' ) );
 
64
  add_action( 'admin_menu' , array( $this, 'admin_menu' ) );
65
  add_action( 'current_screen', array( $this, 'current_screen' ) );
66
  }
@@ -78,6 +80,18 @@ class Smart_Custom_Fields {
78
  wp_delete_post( $post->ID, true );
79
  }
80
  delete_post_meta_by_key( SCF_Config::PREFIX . 'repeat-multiple-data' );
 
 
 
 
 
 
 
 
 
 
 
 
81
  }
82
 
83
  /**
@@ -101,6 +115,7 @@ class Smart_Custom_Fields {
101
  $Post->ID = $post_id;
102
  $Post->post_type = $screen->id;
103
  if ( SCF::get_settings( new WP_Post( $Post ) ) ) {
 
104
  require_once plugin_dir_path( __FILE__ ) . 'classes/controller/class.editor.php';
105
  new Smart_Custom_Fields_Revisions();
106
  new Smart_Custom_Fields_Controller_Editor();
@@ -115,11 +130,23 @@ class Smart_Custom_Fields {
115
  $roles = $user_data->roles;
116
  }
117
  if ( SCF::get_settings( get_userdata( $user_id ) ) ) {
118
- require_once plugin_dir_path( __FILE__ ) . 'classes/controller/class.editor.php';
119
  require_once plugin_dir_path( __FILE__ ) . 'classes/controller/class.profile.php';
120
  new Smart_Custom_Fields_Controller_Profile();
121
  }
122
  }
 
 
 
 
 
 
 
 
 
 
 
 
123
  }
124
 
125
  /**
@@ -155,6 +182,13 @@ class Smart_Custom_Fields {
155
  );
156
  }
157
 
 
 
 
 
 
 
 
158
  /**
159
  * 管理画面にメニューを追加
160
  */
@@ -210,5 +244,20 @@ class Smart_Custom_Fields {
210
  }
211
  return $user_id;
212
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
213
  }
214
  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.4.0
7
  * Author: Takashi Kitajima
8
  * Author URI: http://2inc.org
9
  * Created: October 9, 2014
10
+ * Modified: April 28, 2015
11
  * Text Domain: smart-custom-fields
12
  * Domain Path: /languages
13
  * License: GPLv2
47
  require_once plugin_dir_path( __FILE__ ) . 'classes/models/class.group.php';
48
  require_once plugin_dir_path( __FILE__ ) . 'classes/models/class.abstract-field-base.php';
49
  require_once plugin_dir_path( __FILE__ ) . 'classes/models/class.revisions.php';
50
+ require_once plugin_dir_path( __FILE__ ) . 'classes/models/class.ajax.php';
51
  require_once plugin_dir_path( __FILE__ ) . 'classes/class.scf.php';
52
  new Smart_Custom_Fields_Revisions();
53
 
62
  do_action( SCF_Config::PREFIX . 'fields-loaded' );
63
 
64
  add_action( 'init' , array( $this, 'register_post_type' ) );
65
+ add_action( 'init' , array( $this, 'ajax_request' ) );
66
  add_action( 'admin_menu' , array( $this, 'admin_menu' ) );
67
  add_action( 'current_screen', array( $this, 'current_screen' ) );
68
  }
80
  wp_delete_post( $post->ID, true );
81
  }
82
  delete_post_meta_by_key( SCF_Config::PREFIX . 'repeat-multiple-data' );
83
+
84
+ // option の smart-cf-xxx を削除
85
+ global $wpdb;
86
+ $wpdb->query(
87
+ $wpdb->prepare(
88
+ "
89
+ DELETE FROM $wpdb->options
90
+ WHERE option_name LIKE %s
91
+ ",
92
+ SCF_Config::PREFIX . '%'
93
+ )
94
+ );
95
  }
96
 
97
  /**
115
  $Post->ID = $post_id;
116
  $Post->post_type = $screen->id;
117
  if ( SCF::get_settings( new WP_Post( $Post ) ) ) {
118
+ require_once plugin_dir_path( __FILE__ ) . 'classes/controller/class.controller-base.php';
119
  require_once plugin_dir_path( __FILE__ ) . 'classes/controller/class.editor.php';
120
  new Smart_Custom_Fields_Revisions();
121
  new Smart_Custom_Fields_Controller_Editor();
130
  $roles = $user_data->roles;
131
  }
132
  if ( SCF::get_settings( get_userdata( $user_id ) ) ) {
133
+ require_once plugin_dir_path( __FILE__ ) . 'classes/controller/class.controller-base.php';
134
  require_once plugin_dir_path( __FILE__ ) . 'classes/controller/class.profile.php';
135
  new Smart_Custom_Fields_Controller_Profile();
136
  }
137
  }
138
+ // タグ、カテゴリー、タクソノミー
139
+ elseif ( $screen->taxonomy ) {
140
+ $term_id = $this->get_term_id_in_admin();
141
+ if ( $term_id ) {
142
+ $term = get_term( $term_id, $screen->taxonomy );
143
+ if ( SCF::get_settings( $term ) ) {
144
+ require_once plugin_dir_path( __FILE__ ) . 'classes/controller/class.controller-base.php';
145
+ require_once plugin_dir_path( __FILE__ ) . 'classes/controller/class.taxonomy.php';
146
+ new Smart_Custom_Fields_Controller_Taxonomy();
147
+ }
148
+ }
149
+ }
150
  }
151
 
152
  /**
182
  );
183
  }
184
 
185
+ /**
186
+ * Ajax リクエストのときに発火させたい処理をフックさせる
187
+ */
188
+ public function ajax_request() {
189
+ $Ajax = new Smart_Custom_Fields_Ajax();
190
+ }
191
+
192
  /**
193
  * 管理画面にメニューを追加
194
  */
244
  }
245
  return $user_id;
246
  }
247
+
248
+ /**
249
+ * ターム編集画面でそのタームのIDを取得
250
+ *
251
+ * @return int
252
+ */
253
+ protected function get_term_id_in_admin() {
254
+ $term_id = false;
255
+ if ( !empty( $_GET['tag_ID'] ) ) {
256
+ $term_id = $_GET['tag_ID'];
257
+ } elseif ( !empty( $_POST['tag_ID'] ) ) {
258
+ $term_id = $_POST['tag_ID'];
259
+ }
260
+ return $term_id;
261
+ }
262
  }
263
  new Smart_Custom_Fields();