Smart Custom Fields - Version 4.1.2

Version Description

  • Fix PHP syntax error.
Download this release

Release Info

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

Code changes from version 4.1.0 to 4.1.2

classes/class.rest-api.php CHANGED
@@ -20,11 +20,15 @@ class Smart_Custom_Fields_Rest_API {
20
  /**
21
  * Register routes
22
  */
23
- public function register_rest_api_routes(){
24
- register_rest_route( SCF_Config::PREFIX.'api', '/search/posts', array(
25
- 'methods' => 'GET',
26
- 'callback' => array( $this, 'get_all_posts' ),
27
- ));
 
 
 
 
28
  }
29
 
30
  /**
@@ -37,7 +41,7 @@ class Smart_Custom_Fields_Rest_API {
37
  'post_status' => 'publish',
38
  'orderby' => 'date',
39
  'order' => 'ASC',
40
- 'posts_per_page' => -1 // all posts
41
  )
42
  );
43
 
20
  /**
21
  * Register routes
22
  */
23
+ public function register_rest_api_routes() {
24
+ register_rest_route(
25
+ SCF_Config::PREFIX . 'api',
26
+ '/search/posts',
27
+ array(
28
+ 'methods' => 'GET',
29
+ 'callback' => array( $this, 'get_all_posts' ),
30
+ )
31
+ );
32
  }
33
 
34
  /**
41
  'post_status' => 'publish',
42
  'orderby' => 'date',
43
  'order' => 'ASC',
44
+ 'posts_per_page' => -1, // all posts
45
  )
46
  );
47
 
classes/class.scf.php CHANGED
@@ -12,12 +12,14 @@ class SCF {
12
 
13
  /**
14
  * Array of the registered fields ( Smart_Custom_Fields_Field_Base )
 
15
  * @var array
16
  */
17
  protected static $fields = array();
18
 
19
  /**
20
  * Array of the custom options pages.
 
21
  * @var array
22
  */
23
  protected static $options_pages = array();
@@ -47,7 +49,7 @@ class SCF {
47
  * Getting the post meta data to feel good
48
  *
49
  * @param string $name group name or field name
50
- * @param int $post_id
51
  * @return mixed
52
  */
53
  public static function get( $name, $post_id = null ) {
@@ -68,7 +70,7 @@ class SCF {
68
  /**
69
  * Getting the user meta data to feel good
70
  *
71
- * @param int $user_id
72
  * @param string $name group name or field name
73
  * @return mixed
74
  */
@@ -90,7 +92,7 @@ class SCF {
90
  /**
91
  * Getting the term meta data to feel good
92
  *
93
- * @param int $term_id
94
  * @param string $taxonomy_name
95
  * @param string $name group name or field name
96
  * @return mixed
@@ -122,7 +124,7 @@ class SCF {
122
  return;
123
  }
124
 
125
- if ( !isset( self::$options_pages[$menu_slug] ) ) {
126
  return;
127
  }
128
 
@@ -142,7 +144,7 @@ class SCF {
142
  * Getting any meta data to feel good
143
  *
144
  * @param WP_Post|WP_User|WP_Term|stdClass $object
145
- * @param string $name group name or field name
146
  * @return mixed
147
  */
148
  protected static function get_meta( $object, $name ) {
@@ -169,7 +171,7 @@ class SCF {
169
  foreach ( $groups as $Group ) {
170
  $Field = $Group->get_field( $name );
171
  if ( $Field ) {
172
- $is_repeatable = $Group->is_repeatable();
173
  $value_by_field = self::get_value_by_field( $object, $Field, $is_repeatable );
174
  $Cache->save_meta( $object, $name, $value_by_field );
175
  return $value_by_field;
@@ -179,14 +181,14 @@ class SCF {
179
  }
180
 
181
  /**
182
- * Getting all of any meta data to feel good
183
  *
184
  * @param WP_Post|WP_User|WP_Term|stdClass $object
185
  * @return mixed
186
  */
187
  protected static function get_all_meta( $object ) {
188
- $Cache = Smart_Custom_Fields_Cache::getInstance();
189
- $settings = self::get_settings( $object );
190
  $post_meta = array();
191
  foreach ( $settings as $Setting ) {
192
  $groups = $Setting->get_groups();
@@ -196,15 +198,14 @@ class SCF {
196
  if ( $is_repeatable && $group_name ) {
197
  $values_by_group = self::get_values_by_group( $object, $Group );
198
  $Cache->save_meta( $object, $group_name, $values_by_group );
199
- $post_meta[$group_name] = $values_by_group;
200
- }
201
- else {
202
  $fields = $Group->get_fields();
203
  foreach ( $fields as $Field ) {
204
- $field_name = $Field->get( 'name' );
205
  $value_by_field = self::get_value_by_field( $object, $Field, $is_repeatable );
206
  $Cache->save_meta( $object, $field_name, $value_by_field );
207
- $post_meta[$field_name] = $value_by_field;
208
  }
209
  }
210
  }
@@ -233,30 +234,30 @@ class SCF {
233
  * When group, Note the point that returned data are repetition
234
  *
235
  * @param WP_Post|WP_User|WP_Term|stdClass $object
236
- * @param Smart_Custom_Fields_Group $Group
237
  * @return mixed
238
  */
239
  protected static function get_values_by_group( $object, $Group ) {
240
- $is_repeatable = $Group->is_repeatable();
241
- $meta = array();
242
- $fields = $Group->get_fields();
243
  $value_by_fields = array();
244
  foreach ( $fields as $Field ) {
245
  if ( $Field->get_attribute( 'allow-multiple-data' ) ) {
246
- $meta[0][$Field->get( 'name' )] = array();
247
  } else {
248
- $meta[0][$Field->get( 'name' )] = '';
249
  }
250
  }
251
  $default_meta = $meta[0];
252
  foreach ( $fields as $Field ) {
253
  $value_by_field = self::get_value_by_field( $object, $Field, $is_repeatable );
254
  foreach ( $value_by_field as $i => $value ) {
255
- $meta[$i][$Field->get( 'name' )] = $value;
256
  }
257
  }
258
  foreach ( $meta as $i => $value ) {
259
- $meta[$i] = array_merge( $default_meta, $value );
260
  }
261
  return $meta;
262
  }
@@ -265,37 +266,37 @@ class SCF {
265
  * Getting the meta data of the field
266
  *
267
  * @param WP_Post|WP_User|WP_Term|stdClass $object
268
- * @param array $field
269
- * @param bool $is_repeatable Whether the group that this field belongs is repetition
270
  * @return mixed $post_meta
271
  */
272
  protected static function get_value_by_field( $object, $Field, $is_repeatable ) {
273
  $field_name = $Field->get( 'name' );
274
- if ( !$field_name ) {
275
  return;
276
  }
277
 
278
  $Meta = new Smart_Custom_Fields_Meta( $object );
279
 
280
  // In the case of multi-value items in the loop
281
- $field_type = $Field->get_attribute( 'type' );
282
  $repeat_multiple_data = self::get_repeat_multiple_data( $object );
283
- if ( is_array( $repeat_multiple_data ) && isset( $repeat_multiple_data[$field_name] ) ) {
284
  if ( $Meta->is_saved_the_key( $field_name ) ) {
285
  $_meta = $Meta->get( $field_name );
286
  } else {
287
  $_meta = self::get_default_value( $Field );
288
  }
289
  $start = 0;
290
- foreach ( $repeat_multiple_data[$field_name] as $repeat_multiple_key => $repeat_multiple_value ) {
291
  if ( $repeat_multiple_value === 0 ) {
292
  $value = array();
293
  } else {
294
  $value = array_slice( $_meta, $start, $repeat_multiple_value );
295
  $start += $repeat_multiple_value;
296
  }
297
- $value = apply_filters( SCF_Config::PREFIX . 'validate-get-value', $value, $field_type );
298
- $meta[$repeat_multiple_key] = $value;
299
  }
300
  }
301
  // Other than that
@@ -318,11 +319,11 @@ class SCF {
318
  * Return the default value
319
  *
320
  * @param Smart_Custom_Fields_Field_Base $Field
321
- * @param bool $single
322
  * @return array|strings
323
  */
324
  public static function get_default_value( $Field, $single = false ) {
325
- if ( !is_a( $Field, 'Smart_Custom_Fields_Field_Base' ) ) {
326
  if ( $single ) {
327
  return '';
328
  }
@@ -333,11 +334,11 @@ class SCF {
333
  $default = $Field->get( 'default' );
334
 
335
  if ( $Field->get_attribute( 'allow-multiple-data' ) ) {
336
- $choices = SCF::choices_eol_to_array( $choices );
337
- $default = SCF::choices_eol_to_array( $default );
338
  $default_sanitized = array();
339
 
340
- if ( SCF::is_assoc( $choices ) ) {
341
  $_choices = array_flip( $choices );
342
  } else {
343
  $_choices = $choices;
@@ -345,9 +346,9 @@ class SCF {
345
  foreach ( $default as $key => $value ) {
346
  if ( in_array( $value, $_choices ) ) {
347
  if ( preg_match( '/^\d+$/', $value ) ) {
348
- $value = (int)$value;
349
  }
350
- $default_sanitized[$key] = $value;
351
  }
352
  }
353
  return $default_sanitized;
@@ -365,7 +366,7 @@ class SCF {
365
  if ( $default === '' || $default === false || $default === null ) {
366
  return array();
367
  }
368
- return ( array ) $default;
369
  }
370
  }
371
 
@@ -376,32 +377,32 @@ class SCF {
376
  * @return array $settings
377
  */
378
  public static function get_settings_posts( $object ) {
379
- $Cache = Smart_Custom_Fields_Cache::getInstance();
380
  $settings_posts = array();
381
  if ( $Cache->get_settings_posts( $object ) !== null ) {
382
- self::debug_cache_message( "use settings posts cache." );
383
  return $Cache->get_settings_posts( $object );
384
  } else {
385
- self::debug_cache_message( "dont use settings posts cache..." );
386
  }
387
 
388
  $Meta = new Smart_Custom_Fields_Meta( $object );
389
  $types = $Meta->get_types( false );
390
 
391
  switch ( $Meta->get_meta_type() ) {
392
- case 'post' :
393
  $key = SCF_Config::PREFIX . 'condition';
394
  break;
395
- case 'user' :
396
  $key = SCF_Config::PREFIX . 'roles';
397
  break;
398
- case 'term' :
399
  $key = SCF_Config::PREFIX . 'taxonomies';
400
  break;
401
- case 'option' :
402
  $key = SCF_Config::PREFIX . 'options-pages';
403
  break;
404
- default :
405
  $key = '';
406
  }
407
 
@@ -415,7 +416,7 @@ class SCF {
415
  );
416
  }
417
  if ( $meta_query ) {
418
- $meta_query[ 'relation' ] = 'OR';
419
  }
420
 
421
  $args = array(
@@ -460,14 +461,11 @@ class SCF {
460
  $settings_posts = self::get_settings_posts( $object );
461
  if ( $meta_type === 'post' ) {
462
  $settings = self::get_settings_for_post( $object, $settings_posts );
463
- }
464
- elseif ( $meta_type === 'user' ) {
465
  $settings = self::get_settings_for_profile( $object, $settings_posts );
466
- }
467
- elseif ( $meta_type === 'term' ) {
468
  $settings = self::get_settings_for_term( $object, $settings_posts );
469
- }
470
- elseif ( $meta_type === 'option' ) {
471
  $settings = self::get_settings_for_option( $object, $settings_posts );
472
  }
473
  }
@@ -479,7 +477,7 @@ class SCF {
479
  $meta_type,
480
  $types
481
  );
482
- if ( !is_array( $settings ) ) {
483
  $settings = array();
484
  }
485
  return $settings;
@@ -489,18 +487,18 @@ class SCF {
489
  * Getting the Setting object for post
490
  *
491
  * @param WP_Post $object
492
- * @param array $settings_posts
493
  * @return array
494
  */
495
  protected static function get_settings_for_post( $object, $settings_posts ) {
496
- $Cache = Smart_Custom_Fields_Cache::getInstance();
497
  $settings = array();
498
  foreach ( $settings_posts as $settings_post ) {
499
  if ( $Cache->get_settings( $settings_post->ID ) !== null ) {
500
  self::debug_cache_message( "use settings cache. [id: {$settings_post->ID}]" );
501
  $Setting = $Cache->get_settings( $settings_post->ID, $object );
502
  if ( $Setting ) {
503
- $settings[$settings_post->ID] = $Setting;
504
  }
505
  continue;
506
  }
@@ -514,9 +512,9 @@ class SCF {
514
  $condition_post_ids_raw = explode( ',', $condition_post_ids_raw );
515
  foreach ( $condition_post_ids_raw as $condition_post_id ) {
516
  $condition_post_id = trim( $condition_post_id );
517
- $Setting = SCF::add_setting( $settings_post->ID, $settings_post->post_title );
518
  if ( $object->ID == $condition_post_id ) {
519
- $settings[$settings_post->ID] = $Setting;
520
  }
521
  $Post = get_post( $condition_post_id );
522
  if ( empty( $Post ) ) {
@@ -525,8 +523,8 @@ class SCF {
525
  $Cache->save_settings( $settings_post->ID, $Setting, $Post );
526
  }
527
  } else {
528
- $Setting = SCF::add_setting( $settings_post->ID, $settings_post->post_title );
529
- $settings[$settings_post->ID] = $Setting;
530
  $Cache->save_settings( $settings_post->ID, $Setting );
531
  }
532
  }
@@ -537,11 +535,11 @@ class SCF {
537
  * Getting the Setting object for user
538
  *
539
  * @param WP_User $object
540
- * @param array $settings_posts
541
  * @return array
542
  */
543
  protected static function get_settings_for_profile( $object, $settings_posts ) {
544
- $Cache = Smart_Custom_Fields_Cache::getInstance();
545
  $settings = array();
546
  foreach ( $settings_posts as $settings_post ) {
547
  if ( $Cache->get_settings( $settings_post->ID ) !== null ) {
@@ -550,7 +548,7 @@ class SCF {
550
  continue;
551
  }
552
  self::debug_cache_message( "dont use settings cache... [id: {$settings_post->ID}]" );
553
- $Setting = SCF::add_setting( $settings_post->ID, $settings_post->post_title );
554
  $settings[] = $Setting;
555
  $Cache->save_settings( $settings_post->ID, $Setting );
556
  }
@@ -561,7 +559,7 @@ class SCF {
561
  * Getting the Setting object for term
562
  *
563
  * @param WP_Term $object
564
- * @param array $settings_posts
565
  * @return array
566
  */
567
  protected static function get_settings_for_term( $object, $settings_posts ) {
@@ -572,7 +570,7 @@ class SCF {
572
  * Getting the Setting object for option
573
  *
574
  * @param WP_Term $object
575
- * @param array $settings_posts
576
  * @return array
577
  */
578
  protected static function get_settings_for_option( $object, $settings_posts ) {
@@ -586,15 +584,15 @@ class SCF {
586
  * @return array
587
  */
588
  public static function get_repeat_multiple_data( $object ) {
589
- $Cache = Smart_Custom_Fields_Cache::getInstance();
590
  $repeat_multiple_data = array();
591
  if ( $Cache->get_repeat_multiple_data( $object ) ) {
592
  return $Cache->get_repeat_multiple_data( $object );
593
  }
594
 
595
- $Meta = new Smart_Custom_Fields_Meta( $object );
596
  $_repeat_multiple_data = $Meta->get( SCF_Config::PREFIX . 'repeat-multiple-data', true );
597
- if ( !empty( $_repeat_multiple_data ) ) {
598
  $repeat_multiple_data = $_repeat_multiple_data;
599
  }
600
 
@@ -622,12 +620,12 @@ class SCF {
622
  * Whether the associative array or not
623
  *
624
  * @see http://qiita.com/ka215/items/a14e53547e717d2a564f
625
- * @param array $data This argument should be expected an array
626
  * @param boolean $multidimensional True if a multidimensional array is inclusion into associative array, the default value is false
627
  * @return boolean
628
  */
629
  public static function is_assoc( $data, $multidimensional = false ) {
630
- if ( !is_array( $data ) || empty( $data ) ) {
631
  return false;
632
  }
633
  $has_array = false;
@@ -636,7 +634,7 @@ class SCF {
636
  $has_array = true;
637
  }
638
 
639
- if ( !is_int( $key ) ) {
640
  return true;
641
  }
642
  }
@@ -650,20 +648,20 @@ class SCF {
650
  */
651
  public static function add_form_field_instance( Smart_Custom_Fields_Field_Base $instance ) {
652
  $type = $instance->get_attribute( 'type' );
653
- if ( !empty( $type ) ) {
654
- self::$fields[$type] = $instance;
655
  }
656
  }
657
 
658
  /**
659
  * Getting the available form field object
660
  *
661
- * @param string $type type of the form field
662
  * @param Smart_Custom_Fields_Field_Base
663
  */
664
  public static function get_form_field_instance( $type ) {
665
- if ( !empty( self::$fields[$type] ) ) {
666
- return clone self::$fields[$type];
667
  }
668
  }
669
 
@@ -675,7 +673,7 @@ class SCF {
675
  public static function get_form_field_instances() {
676
  $fields = array();
677
  foreach ( self::$fields as $type => $instance ) {
678
- $fields[$type] = self::get_form_field_instance( $type );
679
  }
680
  return $fields;
681
  }
@@ -685,15 +683,15 @@ class SCF {
685
  * Note that not return only one even define multiple fields with the same name of the field name
686
  *
687
  * @param WP_Post|WP_User|WP_Term|stdClass $object
688
- * @param string $field_name
689
  * @return Smart_Custom_Fields_Field_Base|null
690
  */
691
  public static function get_field( $object, $field_name ) {
692
  $settings = self::get_settings( $object );
693
  foreach ( $settings as $Setting ) {
694
  $fields = $Setting->get_fields();
695
- if ( !empty( $fields[$field_name] ) ) {
696
- return $fields[$field_name];
697
  }
698
  }
699
  }
@@ -705,17 +703,17 @@ class SCF {
705
  * @return array
706
  */
707
  public static function choices_eol_to_array( $choices ) {
708
- if ( !is_array( $choices ) ) {
709
  if ( $choices === '' || $choices === false || $choices === null ) {
710
  return array();
711
  }
712
  $_choices = str_replace( array( "\r\n", "\r", "\n" ), "\n", $choices );
713
  $_choices = explode( "\n", $_choices );
714
- $choices = array();
715
  foreach ( $_choices as $_choice ) {
716
  $_choice = array_map( 'trim', explode( '=>', $_choice ) );
717
  if ( count( $_choice ) === 2 ) {
718
- $choices[$_choice[0]] = $_choice[1];
719
  } else {
720
  $choices = array_merge( $choices, $_choice );
721
  }
@@ -744,11 +742,11 @@ class SCF {
744
  * @param string $capability
745
  * @param string $menu_slug
746
  * @param string $icon_url
747
- * @param int $position
748
  * @return $menu_slug
749
  */
750
  public static function add_options_page( $page_title, $menu_title, $capability, $menu_slug, $icon_url = '', $position = null ) {
751
- self::$options_pages[$menu_slug] = $menu_title;
752
  new Smart_Custom_Fields_Options_Page( $page_title, $menu_title, $capability, $menu_slug, $icon_url, $position );
753
  return $menu_slug;
754
  }
@@ -765,12 +763,12 @@ class SCF {
765
  /**
766
  * Generate WP_Post object
767
  *
768
- * @param int $post_id
769
  * @param string $post_type
770
  * @return WP_Post
771
  */
772
  public static function generate_post_object( $post_id, $post_type = null ) {
773
- $Post = new stdClass();
774
  $Post->ID = $post_id;
775
  $Post->post_type = $post_type;
776
  return new WP_Post( $Post );
@@ -783,13 +781,13 @@ class SCF {
783
  * @return stdClass
784
  */
785
  public static function generate_option_object( $menu_slug ) {
786
- $options_pages = SCF::get_options_pages();
787
- if ( !isset( $options_pages[$menu_slug] ) ) {
788
  return;
789
  }
790
- $Option = new stdClass();
791
  $Option->menu_slug = $menu_slug;
792
- $Option->menu_title = $options_pages[$menu_slug];
793
  return $Option;
794
  }
795
 
12
 
13
  /**
14
  * Array of the registered fields ( Smart_Custom_Fields_Field_Base )
15
+ *
16
  * @var array
17
  */
18
  protected static $fields = array();
19
 
20
  /**
21
  * Array of the custom options pages.
22
+ *
23
  * @var array
24
  */
25
  protected static $options_pages = array();
49
  * Getting the post meta data to feel good
50
  *
51
  * @param string $name group name or field name
52
+ * @param int $post_id
53
  * @return mixed
54
  */
55
  public static function get( $name, $post_id = null ) {
70
  /**
71
  * Getting the user meta data to feel good
72
  *
73
+ * @param int $user_id
74
  * @param string $name group name or field name
75
  * @return mixed
76
  */
92
  /**
93
  * Getting the term meta data to feel good
94
  *
95
+ * @param int $term_id
96
  * @param string $taxonomy_name
97
  * @param string $name group name or field name
98
  * @return mixed
124
  return;
125
  }
126
 
127
+ if ( ! isset( self::$options_pages[ $menu_slug ] ) ) {
128
  return;
129
  }
130
 
144
  * Getting any meta data to feel good
145
  *
146
  * @param WP_Post|WP_User|WP_Term|stdClass $object
147
+ * @param string $name group name or field name
148
  * @return mixed
149
  */
150
  protected static function get_meta( $object, $name ) {
171
  foreach ( $groups as $Group ) {
172
  $Field = $Group->get_field( $name );
173
  if ( $Field ) {
174
+ $is_repeatable = $Group->is_repeatable();
175
  $value_by_field = self::get_value_by_field( $object, $Field, $is_repeatable );
176
  $Cache->save_meta( $object, $name, $value_by_field );
177
  return $value_by_field;
181
  }
182
 
183
  /**
184
+ * Getting all of any meta data to feel good
185
  *
186
  * @param WP_Post|WP_User|WP_Term|stdClass $object
187
  * @return mixed
188
  */
189
  protected static function get_all_meta( $object ) {
190
+ $Cache = Smart_Custom_Fields_Cache::getInstance();
191
+ $settings = self::get_settings( $object );
192
  $post_meta = array();
193
  foreach ( $settings as $Setting ) {
194
  $groups = $Setting->get_groups();
198
  if ( $is_repeatable && $group_name ) {
199
  $values_by_group = self::get_values_by_group( $object, $Group );
200
  $Cache->save_meta( $object, $group_name, $values_by_group );
201
+ $post_meta[ $group_name ] = $values_by_group;
202
+ } else {
 
203
  $fields = $Group->get_fields();
204
  foreach ( $fields as $Field ) {
205
+ $field_name = $Field->get( 'name' );
206
  $value_by_field = self::get_value_by_field( $object, $Field, $is_repeatable );
207
  $Cache->save_meta( $object, $field_name, $value_by_field );
208
+ $post_meta[ $field_name ] = $value_by_field;
209
  }
210
  }
211
  }
234
  * When group, Note the point that returned data are repetition
235
  *
236
  * @param WP_Post|WP_User|WP_Term|stdClass $object
237
+ * @param Smart_Custom_Fields_Group $Group
238
  * @return mixed
239
  */
240
  protected static function get_values_by_group( $object, $Group ) {
241
+ $is_repeatable = $Group->is_repeatable();
242
+ $meta = array();
243
+ $fields = $Group->get_fields();
244
  $value_by_fields = array();
245
  foreach ( $fields as $Field ) {
246
  if ( $Field->get_attribute( 'allow-multiple-data' ) ) {
247
+ $meta[0][ $Field->get( 'name' ) ] = array();
248
  } else {
249
+ $meta[0][ $Field->get( 'name' ) ] = '';
250
  }
251
  }
252
  $default_meta = $meta[0];
253
  foreach ( $fields as $Field ) {
254
  $value_by_field = self::get_value_by_field( $object, $Field, $is_repeatable );
255
  foreach ( $value_by_field as $i => $value ) {
256
+ $meta[ $i ][ $Field->get( 'name' ) ] = $value;
257
  }
258
  }
259
  foreach ( $meta as $i => $value ) {
260
+ $meta[ $i ] = array_merge( $default_meta, $value );
261
  }
262
  return $meta;
263
  }
266
  * Getting the meta data of the field
267
  *
268
  * @param WP_Post|WP_User|WP_Term|stdClass $object
269
+ * @param array $field
270
+ * @param bool $is_repeatable Whether the group that this field belongs is repetition
271
  * @return mixed $post_meta
272
  */
273
  protected static function get_value_by_field( $object, $Field, $is_repeatable ) {
274
  $field_name = $Field->get( 'name' );
275
+ if ( ! $field_name ) {
276
  return;
277
  }
278
 
279
  $Meta = new Smart_Custom_Fields_Meta( $object );
280
 
281
  // In the case of multi-value items in the loop
282
+ $field_type = $Field->get_attribute( 'type' );
283
  $repeat_multiple_data = self::get_repeat_multiple_data( $object );
284
+ if ( is_array( $repeat_multiple_data ) && isset( $repeat_multiple_data[ $field_name ] ) ) {
285
  if ( $Meta->is_saved_the_key( $field_name ) ) {
286
  $_meta = $Meta->get( $field_name );
287
  } else {
288
  $_meta = self::get_default_value( $Field );
289
  }
290
  $start = 0;
291
+ foreach ( $repeat_multiple_data[ $field_name ] as $repeat_multiple_key => $repeat_multiple_value ) {
292
  if ( $repeat_multiple_value === 0 ) {
293
  $value = array();
294
  } else {
295
  $value = array_slice( $_meta, $start, $repeat_multiple_value );
296
  $start += $repeat_multiple_value;
297
  }
298
+ $value = apply_filters( SCF_Config::PREFIX . 'validate-get-value', $value, $field_type );
299
+ $meta[ $repeat_multiple_key ] = $value;
300
  }
301
  }
302
  // Other than that
319
  * Return the default value
320
  *
321
  * @param Smart_Custom_Fields_Field_Base $Field
322
+ * @param bool $single
323
  * @return array|strings
324
  */
325
  public static function get_default_value( $Field, $single = false ) {
326
+ if ( ! is_a( $Field, 'Smart_Custom_Fields_Field_Base' ) ) {
327
  if ( $single ) {
328
  return '';
329
  }
334
  $default = $Field->get( 'default' );
335
 
336
  if ( $Field->get_attribute( 'allow-multiple-data' ) ) {
337
+ $choices = self::choices_eol_to_array( $choices );
338
+ $default = self::choices_eol_to_array( $default );
339
  $default_sanitized = array();
340
 
341
+ if ( self::is_assoc( $choices ) ) {
342
  $_choices = array_flip( $choices );
343
  } else {
344
  $_choices = $choices;
346
  foreach ( $default as $key => $value ) {
347
  if ( in_array( $value, $_choices ) ) {
348
  if ( preg_match( '/^\d+$/', $value ) ) {
349
+ $value = (int) $value;
350
  }
351
+ $default_sanitized[ $key ] = $value;
352
  }
353
  }
354
  return $default_sanitized;
366
  if ( $default === '' || $default === false || $default === null ) {
367
  return array();
368
  }
369
+ return (array) $default;
370
  }
371
  }
372
 
377
  * @return array $settings
378
  */
379
  public static function get_settings_posts( $object ) {
380
+ $Cache = Smart_Custom_Fields_Cache::getInstance();
381
  $settings_posts = array();
382
  if ( $Cache->get_settings_posts( $object ) !== null ) {
383
+ self::debug_cache_message( 'use settings posts cache.' );
384
  return $Cache->get_settings_posts( $object );
385
  } else {
386
+ self::debug_cache_message( 'dont use settings posts cache...' );
387
  }
388
 
389
  $Meta = new Smart_Custom_Fields_Meta( $object );
390
  $types = $Meta->get_types( false );
391
 
392
  switch ( $Meta->get_meta_type() ) {
393
+ case 'post':
394
  $key = SCF_Config::PREFIX . 'condition';
395
  break;
396
+ case 'user':
397
  $key = SCF_Config::PREFIX . 'roles';
398
  break;
399
+ case 'term':
400
  $key = SCF_Config::PREFIX . 'taxonomies';
401
  break;
402
+ case 'option':
403
  $key = SCF_Config::PREFIX . 'options-pages';
404
  break;
405
+ default:
406
  $key = '';
407
  }
408
 
416
  );
417
  }
418
  if ( $meta_query ) {
419
+ $meta_query['relation'] = 'OR';
420
  }
421
 
422
  $args = array(
461
  $settings_posts = self::get_settings_posts( $object );
462
  if ( $meta_type === 'post' ) {
463
  $settings = self::get_settings_for_post( $object, $settings_posts );
464
+ } elseif ( $meta_type === 'user' ) {
 
465
  $settings = self::get_settings_for_profile( $object, $settings_posts );
466
+ } elseif ( $meta_type === 'term' ) {
 
467
  $settings = self::get_settings_for_term( $object, $settings_posts );
468
+ } elseif ( $meta_type === 'option' ) {
 
469
  $settings = self::get_settings_for_option( $object, $settings_posts );
470
  }
471
  }
477
  $meta_type,
478
  $types
479
  );
480
+ if ( ! is_array( $settings ) ) {
481
  $settings = array();
482
  }
483
  return $settings;
487
  * Getting the Setting object for post
488
  *
489
  * @param WP_Post $object
490
+ * @param array $settings_posts
491
  * @return array
492
  */
493
  protected static function get_settings_for_post( $object, $settings_posts ) {
494
+ $Cache = Smart_Custom_Fields_Cache::getInstance();
495
  $settings = array();
496
  foreach ( $settings_posts as $settings_post ) {
497
  if ( $Cache->get_settings( $settings_post->ID ) !== null ) {
498
  self::debug_cache_message( "use settings cache. [id: {$settings_post->ID}]" );
499
  $Setting = $Cache->get_settings( $settings_post->ID, $object );
500
  if ( $Setting ) {
501
+ $settings[ $settings_post->ID ] = $Setting;
502
  }
503
  continue;
504
  }
512
  $condition_post_ids_raw = explode( ',', $condition_post_ids_raw );
513
  foreach ( $condition_post_ids_raw as $condition_post_id ) {
514
  $condition_post_id = trim( $condition_post_id );
515
+ $Setting = self::add_setting( $settings_post->ID, $settings_post->post_title );
516
  if ( $object->ID == $condition_post_id ) {
517
+ $settings[ $settings_post->ID ] = $Setting;
518
  }
519
  $Post = get_post( $condition_post_id );
520
  if ( empty( $Post ) ) {
523
  $Cache->save_settings( $settings_post->ID, $Setting, $Post );
524
  }
525
  } else {
526
+ $Setting = self::add_setting( $settings_post->ID, $settings_post->post_title );
527
+ $settings[ $settings_post->ID ] = $Setting;
528
  $Cache->save_settings( $settings_post->ID, $Setting );
529
  }
530
  }
535
  * Getting the Setting object for user
536
  *
537
  * @param WP_User $object
538
+ * @param array $settings_posts
539
  * @return array
540
  */
541
  protected static function get_settings_for_profile( $object, $settings_posts ) {
542
+ $Cache = Smart_Custom_Fields_Cache::getInstance();
543
  $settings = array();
544
  foreach ( $settings_posts as $settings_post ) {
545
  if ( $Cache->get_settings( $settings_post->ID ) !== null ) {
548
  continue;
549
  }
550
  self::debug_cache_message( "dont use settings cache... [id: {$settings_post->ID}]" );
551
+ $Setting = self::add_setting( $settings_post->ID, $settings_post->post_title );
552
  $settings[] = $Setting;
553
  $Cache->save_settings( $settings_post->ID, $Setting );
554
  }
559
  * Getting the Setting object for term
560
  *
561
  * @param WP_Term $object
562
+ * @param array $settings_posts
563
  * @return array
564
  */
565
  protected static function get_settings_for_term( $object, $settings_posts ) {
570
  * Getting the Setting object for option
571
  *
572
  * @param WP_Term $object
573
+ * @param array $settings_posts
574
  * @return array
575
  */
576
  protected static function get_settings_for_option( $object, $settings_posts ) {
584
  * @return array
585
  */
586
  public static function get_repeat_multiple_data( $object ) {
587
+ $Cache = Smart_Custom_Fields_Cache::getInstance();
588
  $repeat_multiple_data = array();
589
  if ( $Cache->get_repeat_multiple_data( $object ) ) {
590
  return $Cache->get_repeat_multiple_data( $object );
591
  }
592
 
593
+ $Meta = new Smart_Custom_Fields_Meta( $object );
594
  $_repeat_multiple_data = $Meta->get( SCF_Config::PREFIX . 'repeat-multiple-data', true );
595
+ if ( ! empty( $_repeat_multiple_data ) ) {
596
  $repeat_multiple_data = $_repeat_multiple_data;
597
  }
598
 
620
  * Whether the associative array or not
621
  *
622
  * @see http://qiita.com/ka215/items/a14e53547e717d2a564f
623
+ * @param array $data This argument should be expected an array
624
  * @param boolean $multidimensional True if a multidimensional array is inclusion into associative array, the default value is false
625
  * @return boolean
626
  */
627
  public static function is_assoc( $data, $multidimensional = false ) {
628
+ if ( ! is_array( $data ) || empty( $data ) ) {
629
  return false;
630
  }
631
  $has_array = false;
634
  $has_array = true;
635
  }
636
 
637
+ if ( ! is_int( $key ) ) {
638
  return true;
639
  }
640
  }
648
  */
649
  public static function add_form_field_instance( Smart_Custom_Fields_Field_Base $instance ) {
650
  $type = $instance->get_attribute( 'type' );
651
+ if ( ! empty( $type ) ) {
652
+ self::$fields[ $type ] = $instance;
653
  }
654
  }
655
 
656
  /**
657
  * Getting the available form field object
658
  *
659
+ * @param string $type type of the form field
660
  * @param Smart_Custom_Fields_Field_Base
661
  */
662
  public static function get_form_field_instance( $type ) {
663
+ if ( ! empty( self::$fields[ $type ] ) ) {
664
+ return clone self::$fields[ $type ];
665
  }
666
  }
667
 
673
  public static function get_form_field_instances() {
674
  $fields = array();
675
  foreach ( self::$fields as $type => $instance ) {
676
+ $fields[ $type ] = self::get_form_field_instance( $type );
677
  }
678
  return $fields;
679
  }
683
  * Note that not return only one even define multiple fields with the same name of the field name
684
  *
685
  * @param WP_Post|WP_User|WP_Term|stdClass $object
686
+ * @param string $field_name
687
  * @return Smart_Custom_Fields_Field_Base|null
688
  */
689
  public static function get_field( $object, $field_name ) {
690
  $settings = self::get_settings( $object );
691
  foreach ( $settings as $Setting ) {
692
  $fields = $Setting->get_fields();
693
+ if ( ! empty( $fields[ $field_name ] ) ) {
694
+ return $fields[ $field_name ];
695
  }
696
  }
697
  }
703
  * @return array
704
  */
705
  public static function choices_eol_to_array( $choices ) {
706
+ if ( ! is_array( $choices ) ) {
707
  if ( $choices === '' || $choices === false || $choices === null ) {
708
  return array();
709
  }
710
  $_choices = str_replace( array( "\r\n", "\r", "\n" ), "\n", $choices );
711
  $_choices = explode( "\n", $_choices );
712
+ $choices = array();
713
  foreach ( $_choices as $_choice ) {
714
  $_choice = array_map( 'trim', explode( '=>', $_choice ) );
715
  if ( count( $_choice ) === 2 ) {
716
+ $choices[ $_choice[0] ] = $_choice[1];
717
  } else {
718
  $choices = array_merge( $choices, $_choice );
719
  }
742
  * @param string $capability
743
  * @param string $menu_slug
744
  * @param string $icon_url
745
+ * @param int $position
746
  * @return $menu_slug
747
  */
748
  public static function add_options_page( $page_title, $menu_title, $capability, $menu_slug, $icon_url = '', $position = null ) {
749
+ self::$options_pages[ $menu_slug ] = $menu_title;
750
  new Smart_Custom_Fields_Options_Page( $page_title, $menu_title, $capability, $menu_slug, $icon_url, $position );
751
  return $menu_slug;
752
  }
763
  /**
764
  * Generate WP_Post object
765
  *
766
+ * @param int $post_id
767
  * @param string $post_type
768
  * @return WP_Post
769
  */
770
  public static function generate_post_object( $post_id, $post_type = null ) {
771
+ $Post = new stdClass();
772
  $Post->ID = $post_id;
773
  $Post->post_type = $post_type;
774
  return new WP_Post( $Post );
781
  * @return stdClass
782
  */
783
  public static function generate_option_object( $menu_slug ) {
784
+ $options_pages = self::get_options_pages();
785
+ if ( ! isset( $options_pages[ $menu_slug ] ) ) {
786
  return;
787
  }
788
+ $Option = new stdClass();
789
  $Option->menu_slug = $menu_slug;
790
+ $Option->menu_title = $options_pages[ $menu_slug ];
791
  return $Option;
792
  }
793
 
classes/controller/class.controller-base.php CHANGED
@@ -12,6 +12,7 @@ class Smart_Custom_Fields_Controller_Base {
12
 
13
  /**
14
  * Array of the form field objects
 
15
  * @var array
16
  */
17
  protected $fields = array();
@@ -42,13 +43,17 @@ class Smart_Custom_Fields_Controller_Base {
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
- if ( !user_can_richedit() ) {
52
  wp_enqueue_script(
53
  'tinymce',
54
  includes_url( '/js/tinymce/tinymce.min.js' ),
@@ -63,7 +68,7 @@ class Smart_Custom_Fields_Controller_Base {
63
  * Display custom fields in edit page.
64
  *
65
  * @param WP_Post|WP_User|WP_Term|stdClass $object
66
- * @param array $callback_args custom field setting information
67
  */
68
  public function display_meta_box( $object, $callback_args ) {
69
  $groups = $callback_args['args'];
@@ -85,8 +90,8 @@ class Smart_Custom_Fields_Controller_Base {
85
  // If in the loop, count up the index.
86
  // If exit the loop, reset the count.
87
  if ( $is_repeatable &&
88
- isset( $tables[$group_key + 1 ] ) &&
89
- $tables[$group_key + 1 ]->get_name() === $Group->get_name() ) {
90
  $index ++;
91
  } else {
92
  $index = 0;
@@ -102,7 +107,7 @@ class Smart_Custom_Fields_Controller_Base {
102
  /**
103
  * Saving posted data
104
  *
105
- * @param array $data
106
  * @param WP_Post|WP_User|WP_Term|stdClass $object
107
  */
108
  protected function save( $data, $object ) {
@@ -119,31 +124,31 @@ class Smart_Custom_Fields_Controller_Base {
119
  * Generating array for displaying the custom fields
120
  *
121
  * @param WP_Post|WP_User|WP_Term|stdClass $object
122
- * @param array $groups Settings from custom field settings page
123
  * @return array $tables Array for displaying a table for custom fields
124
  */
125
  protected function get_tables( $object, $groups ) {
126
  $Meta = new Smart_Custom_Fields_Meta( $object );
127
 
128
  $repeat_multiple_data = SCF::get_repeat_multiple_data( $object );
129
- $tables = array();
130
  foreach ( $groups as $Group ) {
131
  // If in the loop, Added groupgs by the amount of the loop.
132
  // Added only one if setting is repetition but not loop (Ex, new registration)
133
  if ( $Group->is_repeatable() === true ) {
134
  $loop_count = 1;
135
- $fields = $Group->get_fields();
136
  foreach ( $fields as $Field ) {
137
  $field_name = $Field->get( 'name' );
138
- $meta = $Meta->get( $field_name );
139
  if ( is_array( $meta ) ) {
140
  $meta_count = count( $meta );
141
  // When the same name of the custom field is a multiple (checbox or loop)
142
  if ( $meta_count > 1 ) {
143
  // checkbox
144
  if ( $Field->get_attribute( 'allow-multiple-data' ) ) {
145
- if ( is_array( $repeat_multiple_data ) && isset( $repeat_multiple_data[$field_name] ) ) {
146
- $repeat_multiple_data_count = count( $repeat_multiple_data[$field_name] );
147
  if ( $loop_count < $repeat_multiple_data_count ) {
148
  $loop_count = $repeat_multiple_data_count;
149
  }
@@ -174,8 +179,8 @@ class Smart_Custom_Fields_Controller_Base {
174
  * Getting the multi-value field meta data.
175
  *
176
  * @param WP_Post|WP_User|WP_Term|stdClass $object
177
- * @param Smart_Custom_Fields_Field_Base $Field
178
- * @param int $index
179
  * @return array
180
  */
181
  public function get_multiple_data_field_value( $object, $Field, $index ) {
@@ -186,7 +191,7 @@ class Smart_Custom_Fields_Controller_Base {
186
  return SCF::get_default_value( $Field );
187
  }
188
 
189
- if ( !$Meta->is_saved_the_key( $field_name ) ) {
190
  return SCF::get_default_value( $Field );
191
  }
192
 
@@ -194,14 +199,14 @@ class Smart_Custom_Fields_Controller_Base {
194
 
195
  // in the loop
196
  $repeat_multiple_data = SCF::get_repeat_multiple_data( $object );
197
- if ( is_array( $repeat_multiple_data ) && isset( $repeat_multiple_data[$field_name] ) ) {
198
  $now_num = 0;
199
- if ( is_array( $repeat_multiple_data[$field_name] ) && isset( $repeat_multiple_data[$field_name][$index] ) ) {
200
- $now_num = $repeat_multiple_data[$field_name][$index];
201
  }
202
 
203
  // The index is starting point to refer to the total of the previous number than me ($index)
204
- $_temp = array_slice( $repeat_multiple_data[$field_name], 0, $index );
205
  $sum = array_sum( $_temp );
206
  $start = $sum;
207
 
@@ -218,8 +223,8 @@ class Smart_Custom_Fields_Controller_Base {
218
  * Getting the non multi-value field meta data.
219
  *
220
  * @param WP_Post|WP_User|WP_Term|stdClass $object
221
- * @param Smart_Custom_Fields_Field_Base $Field
222
- * @param int $index
223
  * @return string
224
  */
225
  public function get_single_data_field_value( $object, $Field, $index ) {
@@ -232,8 +237,8 @@ class Smart_Custom_Fields_Controller_Base {
232
 
233
  if ( $Meta->is_saved_the_key( $field_name ) ) {
234
  $value = $Meta->get( $field_name );
235
- if ( isset( $value[$index] ) ) {
236
- return $value[$index];
237
  }
238
  return '';
239
  }
@@ -244,9 +249,9 @@ class Smart_Custom_Fields_Controller_Base {
244
  * Displaying tr element for table of custom fields
245
  *
246
  * @param WP_Post|WP_User|WP_Term|stdClass $object
247
- * @param bool $is_repeat
248
- * @param array $fields
249
- * @param int, null $index
250
  */
251
  protected function display_tr( $object, $is_repeat, $fields, $index = null ) {
252
  $Meta = new Smart_Custom_Fields_Meta( $object );
@@ -257,8 +262,8 @@ class Smart_Custom_Fields_Controller_Base {
257
  '<span class="%s"></span>',
258
  esc_attr( SCF_Config::PREFIX . 'icon-handle dashicons dashicons-menu' )
259
  );
260
- $btn_repeat .= '<span class="btn-add-repeat-group dashicons dashicons-plus-alt '.SCF_Config::PREFIX.'repeat-btn"></span>';
261
- $btn_repeat .= ' <span class="btn-remove-repeat-group dashicons dashicons-dismiss '.SCF_Config::PREFIX.'repeat-btn"></span>';
262
  }
263
 
264
  $style = '';
@@ -279,7 +284,7 @@ class Smart_Custom_Fields_Controller_Base {
279
  $layout = $Field->get_attribute( 'layout' ); // get layout type
280
  $field_name = $Field->get( 'name' );
281
  $field_label = $Field->get( 'label' );
282
- if ( !$field_label ) {
283
  $field_label = $field_name;
284
  }
285
 
@@ -293,7 +298,7 @@ class Smart_Custom_Fields_Controller_Base {
293
  }
294
 
295
  $instruction = $Field->get( 'instruction' );
296
- if ( !empty( $instruction ) ) {
297
  if ( apply_filters( SCF_Config::PREFIX . 'instruction-apply-html', false ) === true ) {
298
  $instruction_html = $instruction;
299
  } else {
@@ -306,7 +311,7 @@ class Smart_Custom_Fields_Controller_Base {
306
  }
307
 
308
  $notes = $Field->get( 'notes' );
309
- if ( !empty( $notes ) ) {
310
  $notes = sprintf(
311
  '<p class="description">%s</p>',
312
  esc_html( $notes )
@@ -316,7 +321,7 @@ class Smart_Custom_Fields_Controller_Base {
316
  $form_field = $Field->get_field( $index, $value );
317
 
318
  // if the layout type is full-width, it hides the "Table Header" (th)
319
- $table_th = $layout != 'full-width' ? '<th>'.esc_html( $field_label ).'</th>' : '';
320
  printf(
321
  '<table class="%1$sfield-type-%6$s %1$slayout-type-%7$s"><tr>
322
  %2$s
12
 
13
  /**
14
  * Array of the form field objects
15
+ *
16
  * @var array
17
  */
18
  protected $fields = array();
43
  null,
44
  true
45
  );
46
+ wp_localize_script(
47
+ SCF_Config::PREFIX . 'editor',
48
+ 'smart_cf_uploader',
49
+ array(
50
+ 'image_uploader_title' => esc_html__( 'Image setting', 'smart-custom-fields' ),
51
+ 'file_uploader_title' => esc_html__( 'File setting', 'smart-custom-fields' ),
52
+ )
53
+ );
54
  do_action( SCF_Config::PREFIX . 'after-editor-enqueue-scripts' );
55
 
56
+ if ( ! user_can_richedit() ) {
57
  wp_enqueue_script(
58
  'tinymce',
59
  includes_url( '/js/tinymce/tinymce.min.js' ),
68
  * Display custom fields in edit page.
69
  *
70
  * @param WP_Post|WP_User|WP_Term|stdClass $object
71
+ * @param array $callback_args custom field setting information
72
  */
73
  public function display_meta_box( $object, $callback_args ) {
74
  $groups = $callback_args['args'];
90
  // If in the loop, count up the index.
91
  // If exit the loop, reset the count.
92
  if ( $is_repeatable &&
93
+ isset( $tables[ $group_key + 1 ] ) &&
94
+ $tables[ $group_key + 1 ]->get_name() === $Group->get_name() ) {
95
  $index ++;
96
  } else {
97
  $index = 0;
107
  /**
108
  * Saving posted data
109
  *
110
+ * @param array $data
111
  * @param WP_Post|WP_User|WP_Term|stdClass $object
112
  */
113
  protected function save( $data, $object ) {
124
  * Generating array for displaying the custom fields
125
  *
126
  * @param WP_Post|WP_User|WP_Term|stdClass $object
127
+ * @param array $groups Settings from custom field settings page
128
  * @return array $tables Array for displaying a table for custom fields
129
  */
130
  protected function get_tables( $object, $groups ) {
131
  $Meta = new Smart_Custom_Fields_Meta( $object );
132
 
133
  $repeat_multiple_data = SCF::get_repeat_multiple_data( $object );
134
+ $tables = array();
135
  foreach ( $groups as $Group ) {
136
  // If in the loop, Added groupgs by the amount of the loop.
137
  // Added only one if setting is repetition but not loop (Ex, new registration)
138
  if ( $Group->is_repeatable() === true ) {
139
  $loop_count = 1;
140
+ $fields = $Group->get_fields();
141
  foreach ( $fields as $Field ) {
142
  $field_name = $Field->get( 'name' );
143
+ $meta = $Meta->get( $field_name );
144
  if ( is_array( $meta ) ) {
145
  $meta_count = count( $meta );
146
  // When the same name of the custom field is a multiple (checbox or loop)
147
  if ( $meta_count > 1 ) {
148
  // checkbox
149
  if ( $Field->get_attribute( 'allow-multiple-data' ) ) {
150
+ if ( is_array( $repeat_multiple_data ) && isset( $repeat_multiple_data[ $field_name ] ) ) {
151
+ $repeat_multiple_data_count = count( $repeat_multiple_data[ $field_name ] );
152
  if ( $loop_count < $repeat_multiple_data_count ) {
153
  $loop_count = $repeat_multiple_data_count;
154
  }
179
  * Getting the multi-value field meta data.
180
  *
181
  * @param WP_Post|WP_User|WP_Term|stdClass $object
182
+ * @param Smart_Custom_Fields_Field_Base $Field
183
+ * @param int $index
184
  * @return array
185
  */
186
  public function get_multiple_data_field_value( $object, $Field, $index ) {
191
  return SCF::get_default_value( $Field );
192
  }
193
 
194
+ if ( ! $Meta->is_saved_the_key( $field_name ) ) {
195
  return SCF::get_default_value( $Field );
196
  }
197
 
199
 
200
  // in the loop
201
  $repeat_multiple_data = SCF::get_repeat_multiple_data( $object );
202
+ if ( is_array( $repeat_multiple_data ) && isset( $repeat_multiple_data[ $field_name ] ) ) {
203
  $now_num = 0;
204
+ if ( is_array( $repeat_multiple_data[ $field_name ] ) && isset( $repeat_multiple_data[ $field_name ][ $index ] ) ) {
205
+ $now_num = $repeat_multiple_data[ $field_name ][ $index ];
206
  }
207
 
208
  // The index is starting point to refer to the total of the previous number than me ($index)
209
+ $_temp = array_slice( $repeat_multiple_data[ $field_name ], 0, $index );
210
  $sum = array_sum( $_temp );
211
  $start = $sum;
212
 
223
  * Getting the non multi-value field meta data.
224
  *
225
  * @param WP_Post|WP_User|WP_Term|stdClass $object
226
+ * @param Smart_Custom_Fields_Field_Base $Field
227
+ * @param int $index
228
  * @return string
229
  */
230
  public function get_single_data_field_value( $object, $Field, $index ) {
237
 
238
  if ( $Meta->is_saved_the_key( $field_name ) ) {
239
  $value = $Meta->get( $field_name );
240
+ if ( isset( $value[ $index ] ) ) {
241
+ return $value[ $index ];
242
  }
243
  return '';
244
  }
249
  * Displaying tr element for table of custom fields
250
  *
251
  * @param WP_Post|WP_User|WP_Term|stdClass $object
252
+ * @param bool $is_repeat
253
+ * @param array $fields
254
+ * @param int, null $index
255
  */
256
  protected function display_tr( $object, $is_repeat, $fields, $index = null ) {
257
  $Meta = new Smart_Custom_Fields_Meta( $object );
262
  '<span class="%s"></span>',
263
  esc_attr( SCF_Config::PREFIX . 'icon-handle dashicons dashicons-menu' )
264
  );
265
+ $btn_repeat .= '<span class="btn-add-repeat-group dashicons dashicons-plus-alt ' . SCF_Config::PREFIX . 'repeat-btn"></span>';
266
+ $btn_repeat .= ' <span class="btn-remove-repeat-group dashicons dashicons-dismiss ' . SCF_Config::PREFIX . 'repeat-btn"></span>';
267
  }
268
 
269
  $style = '';
284
  $layout = $Field->get_attribute( 'layout' ); // get layout type
285
  $field_name = $Field->get( 'name' );
286
  $field_label = $Field->get( 'label' );
287
+ if ( ! $field_label ) {
288
  $field_label = $field_name;
289
  }
290
 
298
  }
299
 
300
  $instruction = $Field->get( 'instruction' );
301
+ if ( ! empty( $instruction ) ) {
302
  if ( apply_filters( SCF_Config::PREFIX . 'instruction-apply-html', false ) === true ) {
303
  $instruction_html = $instruction;
304
  } else {
311
  }
312
 
313
  $notes = $Field->get( 'notes' );
314
+ if ( ! empty( $notes ) ) {
315
  $notes = sprintf(
316
  '<p class="description">%s</p>',
317
  esc_html( $notes )
321
  $form_field = $Field->get_field( $index, $value );
322
 
323
  // if the layout type is full-width, it hides the "Table Header" (th)
324
+ $table_th = $layout != 'full-width' ? '<th>' . esc_html( $field_label ) . '</th>' : '';
325
  printf(
326
  '<table class="%1$sfield-type-%6$s %1$slayout-type-%7$s"><tr>
327
  %2$s
classes/controller/class.editor.php CHANGED
@@ -16,13 +16,13 @@ class Smart_Custom_Fields_Controller_Editor extends Smart_Custom_Fields_Controll
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
  /**
23
  * Displaying custom fields in post edit page
24
  *
25
- * @param string $post_type
26
  * @param WP_Post $post
27
  */
28
  public function add_meta_boxes( $post_type, $post ) {
@@ -42,17 +42,17 @@ class Smart_Custom_Fields_Controller_Editor extends Smart_Custom_Fields_Controll
42
 
43
  /**
44
  * Saving meta data from custom fields in post edit page
45
- *
46
  * @param int $post_id
47
  */
48
  public function save_post( $post_id ) {
49
  if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
50
  return;
51
  }
52
- if ( wp_is_post_autosave( $post_id ) || wp_is_post_revision( $post_id ) ){
53
  return;
54
  }
55
- if ( !isset( $_POST[SCF_Config::NAME] ) ) {
56
  return;
57
  }
58
 
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
  /**
23
  * Displaying custom fields in post edit page
24
  *
25
+ * @param string $post_type
26
  * @param WP_Post $post
27
  */
28
  public function add_meta_boxes( $post_type, $post ) {
42
 
43
  /**
44
  * Saving meta data from custom fields in post edit page
45
+ *
46
  * @param int $post_id
47
  */
48
  public function save_post( $post_id ) {
49
  if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
50
  return;
51
  }
52
+ if ( wp_is_post_autosave( $post_id ) || wp_is_post_revision( $post_id ) ) {
53
  return;
54
  }
55
+ if ( ! isset( $_POST[ SCF_Config::NAME ] ) ) {
56
  return;
57
  }
58
 
classes/controller/class.option.php CHANGED
@@ -39,7 +39,7 @@ class Smart_Custom_Fields_Controller_Option extends Smart_Custom_Fields_Controll
39
  */
40
  public function custom_options_page( $Option ) {
41
  $settings = SCF::get_settings( $Option );
42
- if ( !$settings ) {
43
  return;
44
  }
45
  ?>
@@ -66,7 +66,7 @@ class Smart_Custom_Fields_Controller_Option extends Smart_Custom_Fields_Controll
66
  * @param stdClass $Option
67
  */
68
  public function save_option( $Option ) {
69
- if ( !isset( $_POST[SCF_Config::NAME] ) ) {
70
  return;
71
  }
72
 
39
  */
40
  public function custom_options_page( $Option ) {
41
  $settings = SCF::get_settings( $Option );
42
+ if ( ! $settings ) {
43
  return;
44
  }
45
  ?>
66
  * @param stdClass $Option
67
  */
68
  public function save_option( $Option ) {
69
+ if ( ! isset( $_POST[ SCF_Config::NAME ] ) ) {
70
  return;
71
  }
72
 
classes/controller/class.profile.php CHANGED
@@ -61,10 +61,10 @@ class Smart_Custom_Fields_Controller_Profile extends Smart_Custom_Fields_Control
61
  * @param int $user_id
62
  */
63
  public function update( $user_id ) {
64
- if ( !current_user_can( 'edit_user', $user_id ) ) {
65
  return;
66
  }
67
- if ( !isset( $_POST[SCF_Config::NAME] ) ) {
68
  return;
69
  }
70
 
61
  * @param int $user_id
62
  */
63
  public function update( $user_id ) {
64
+ if ( ! current_user_can( 'edit_user', $user_id ) ) {
65
  return;
66
  }
67
+ if ( ! isset( $_POST[ SCF_Config::NAME ] ) ) {
68
  return;
69
  }
70
 
classes/controller/class.settings.php CHANGED
@@ -12,6 +12,7 @@ class Smart_Custom_Fields_Controller_Settings {
12
 
13
  /**
14
  * Selectbox choices of the field selection
 
15
  * @var array
16
  */
17
  private $optgroups = array();
@@ -26,11 +27,11 @@ class Smart_Custom_Fields_Controller_Settings {
26
  add_action( 'add_meta_boxes', array( $this, 'add_meta_boxes' ) );
27
 
28
  $this->optgroups = array(
29
- 'basic-fields' => array(
30
  'label' => esc_attr__( 'Basic fields', 'smart-custom-fields' ),
31
  'options' => array(),
32
  ),
33
- 'select-fields' => array(
34
  'label' => esc_attr__( 'Select fields', 'smart-custom-fields' ),
35
  'options' => array(),
36
  ),
@@ -38,7 +39,7 @@ class Smart_Custom_Fields_Controller_Settings {
38
  'label' => esc_attr__( 'Content fields', 'smart-custom-fields' ),
39
  'options' => array(),
40
  ),
41
- 'other-fields' => array(
42
  'label' => esc_attr__( 'Other fields', 'smart-custom-fields' ),
43
  'options' => array(),
44
  ),
@@ -54,17 +55,16 @@ class Smart_Custom_Fields_Controller_Settings {
54
  global $_wp_admin_css_colors;
55
 
56
  $user_admin_color_scheme = get_user_option( 'admin_color' );
57
- $colors_obj = $_wp_admin_css_colors[ $user_admin_color_scheme ];
58
 
59
  return $colors_obj;
60
  }
61
 
62
  /**
63
  * Add Custom Inline CSS on Admin Dashboard
64
- *
65
  */
66
- public function admin_inline_css(){
67
- $colors = $this->admin_color_scheme()->colors;
68
  $icon_colors = $this->admin_color_scheme()->icon_colors;
69
  ?>
70
  <style>
@@ -135,13 +135,17 @@ class Smart_Custom_Fields_Controller_Settings {
135
  true
136
  );
137
 
138
- wp_localize_script( SCF_Config::PREFIX . 'settings', 'smart_cf_settings', array(
139
- 'duplicate_alert' => esc_html__( 'Same name exists!', 'smart-custom-fields' ),
140
- 'autocomplete_placeholder' => esc_html__( 'Type to search a post or page', 'smart-custom-fields' ),
141
- 'loading' => esc_html__( 'Loading...', 'smart-custom-fields' ),
142
- 'load_more' => esc_html__( 'Load more', 'smart-custom-fields' ),
143
- 'rest_api_url' => rest_url( SCF_Config::PREFIX.'api/search/posts' ),
144
- ) );
 
 
 
 
145
 
146
  wp_enqueue_script( 'jquery-ui-sortable' );
147
  do_action( SCF_Config::PREFIX . 'after-settings-enqueue-scripts' );
@@ -193,7 +197,7 @@ class Smart_Custom_Fields_Controller_Settings {
193
  * @param string $key
194
  */
195
  private function add_hide_class( $key ) {
196
- if ( !$key ) {
197
  echo 'hide';
198
  }
199
  }
@@ -204,7 +208,7 @@ class Smart_Custom_Fields_Controller_Settings {
204
  public function display_meta_box() {
205
  $Setting = SCF::add_setting( get_the_ID(), get_the_title() );
206
  $Setting->add_group_unshift();
207
- $groups = $Setting->get_groups();
208
  ?>
209
  <div class="<?php echo esc_attr( SCF_Config::PREFIX . 'fields-wrapper' ); ?>">
210
  <div class="<?php echo esc_attr( SCF_Config::PREFIX . 'groups' ); ?>">
@@ -223,10 +227,10 @@ class Smart_Custom_Fields_Controller_Settings {
223
  <?php
224
  $field_name = $Field->get( 'name' );
225
  $field_label = $Field->get( 'label' );
226
- if ( !$field_label ) {
227
  $field_label = $field_name;
228
- if ( !$field_label ) {
229
- $field_label = "&nbsp;";
230
  }
231
  }
232
  ?>
@@ -238,7 +242,7 @@ class Smart_Custom_Fields_Controller_Settings {
238
  <small>[ <?php echo esc_html( $field_name ); ?> ]</small>
239
  <?php endif; ?>
240
  </div>
241
- <table class="<?php $this->add_hide_class( !$Field->get( 'name' ) ); ?>">
242
  <tr>
243
  <th><?php esc_html_e( 'Type', 'smart-custom-fields' ); ?><span class="<?php echo esc_attr( SCF_Config::PREFIX . 'require' ); ?>">*</span></th>
244
  <td>
@@ -247,7 +251,7 @@ class Smart_Custom_Fields_Controller_Settings {
247
  class="<?php echo esc_attr( SCF_Config::PREFIX . 'field-select' ); ?>" />
248
  <?php
249
  foreach ( $this->optgroups as $optgroup_name => $optgroup_values ) {
250
- $optgroup_fields = array();
251
  $optgroup_values['options'] = apply_filters(
252
  SCF_Config::PREFIX . 'field-select-' . $optgroup_name,
253
  $optgroup_values['options']
@@ -281,7 +285,7 @@ class Smart_Custom_Fields_Controller_Settings {
281
  </div>
282
  <div class="button button-primary btn-add-group"><?php esc_html_e( 'Add Field', 'smart-custom-fields' ); ?></div>
283
  </div>
284
- <?php wp_nonce_field( SCF_Config::NAME . '-settings', SCF_Config::PREFIX . 'settings-nonce' ) ?>
285
  <?php
286
  }
287
 
@@ -289,16 +293,19 @@ class Smart_Custom_Fields_Controller_Settings {
289
  * Displaying the meta box to set the display conditions for post edit page
290
  */
291
  public function display_meta_box_condition_post() {
292
- $post_types = get_post_types( array(
293
- 'show_ui' => true,
294
- ), 'objects' );
 
 
 
295
  unset( $post_types['attachment'] );
296
- unset( $post_types[SCF_Config::NAME] );
297
 
298
- $conditions = get_post_meta( get_the_ID(), SCF_Config::PREFIX . 'condition', true );
299
  $post_type_field = '';
300
  foreach ( $post_types as $post_type => $post_type_object ) {
301
- $current = ( is_array( $conditions ) && in_array( $post_type, $conditions ) ) ? $post_type : false;
302
  $post_type_field .= sprintf(
303
  '<label><input type="checkbox" name="%s" value="%s" %s /> %s</label>',
304
  esc_attr( SCF_Config::PREFIX . 'condition[]' ),
@@ -321,10 +328,10 @@ class Smart_Custom_Fields_Controller_Settings {
321
  if ( $saved_posts ) {
322
  $saved = array();
323
 
324
- foreach( $saved_posts as $k => $post_id ) {
325
- if($post_id != ''){
326
  $saved[ $k ]['id'] = $post_id;
327
- $saved[ $k ]['text'] = $post_id; //$post_id . ' - ' . get_the_title($post_id);
328
  }
329
  }
330
  }
@@ -355,11 +362,11 @@ class Smart_Custom_Fields_Controller_Settings {
355
  * Displaying the meta box to set the display conditions for profile edit page
356
  */
357
  public function display_meta_box_condition_profile() {
358
- $roles = get_editable_roles();
359
- $conditions = get_post_meta( get_the_ID(), SCF_Config::PREFIX . 'roles', true );
360
  $profile_field = '';
361
  foreach ( $roles as $name => $role ) {
362
- $current = ( is_array( $conditions ) && in_array( $name, $conditions ) ) ? $name : false;
363
  $profile_field .= sprintf(
364
  '<label><input type="checkbox" name="%s" value="%s" %s /> %s</label>',
365
  esc_attr( SCF_Config::PREFIX . 'roles[]' ),
@@ -379,13 +386,16 @@ class Smart_Custom_Fields_Controller_Settings {
379
  * Displaying the meta box to set the display conditions for term edit page
380
  */
381
  public function display_meta_box_condition_taxonomy() {
382
- $taxonomies = get_taxonomies( array(
383
- 'show_ui' => true,
384
- ), 'objects' );
385
- $conditions = get_post_meta( get_the_ID(), SCF_Config::PREFIX . 'taxonomies', true );
 
 
 
386
  $taxonomy_field = '';
387
  foreach ( $taxonomies as $name => $taxonomy ) {
388
- $current = ( is_array( $conditions ) && in_array( $name, $conditions ) ) ? $name : false;
389
  $taxonomy_field .= sprintf(
390
  '<label><input type="checkbox" name="%s" value="%s" %s /> %s</label>',
391
  esc_attr( SCF_Config::PREFIX . 'taxonomies[]' ),
@@ -405,11 +415,11 @@ class Smart_Custom_Fields_Controller_Settings {
405
  * Displaying the meta box to set the display conditions for custom options page
406
  */
407
  public function display_meta_box_condition_options_page() {
408
- $optinos_pages = SCF::get_options_pages();
409
- $conditions = get_post_meta( get_the_ID(), SCF_Config::PREFIX . 'options-pages', true );
410
  $options_page_field = '';
411
  foreach ( $optinos_pages as $name => $optinos_page ) {
412
- $current = ( is_array( $conditions ) && in_array( $name, $conditions ) ) ? $name : false;
413
  $options_page_field .= sprintf(
414
  '<label><input type="checkbox" name="%s" value="%s" %s /> %s</label>',
415
  esc_attr( SCF_Config::PREFIX . 'options-pages[]' ),
@@ -434,7 +444,7 @@ class Smart_Custom_Fields_Controller_Settings {
434
  if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
435
  return;
436
  }
437
- if ( !isset( $_POST[SCF_Config::NAME] ) ) {
438
  return;
439
  }
440
  check_admin_referer(
@@ -443,27 +453,27 @@ class Smart_Custom_Fields_Controller_Settings {
443
  );
444
 
445
  $data = array();
446
- foreach ( $_POST[SCF_Config::NAME] as $group_key => $group_value ) {
447
  // $group_key = 0 is hidden field so don't save
448
  if ( $group_key === 0 ) {
449
  continue;
450
  }
451
- if ( !empty( $group_value['fields'] ) && count( $group_value['fields'] ) > 1 ) {
452
  $fields = array();
453
  foreach ( $group_value['fields'] as $field_key => $field_value ) {
454
  // $field_key = 0 is hidden field so don't save
455
  if ( $field_key === 0 ) {
456
  continue;
457
  }
458
- if ( !empty( $field_value['name'] ) ) {
459
  $fields[] = $field_value;
460
  }
461
  }
462
- if ( !$fields ) {
463
  continue;
464
  }
465
 
466
- if ( !empty( $group_value['repeat'] ) && $group_value['repeat'] === 'true' ) {
467
  $group_value['repeat'] = true;
468
  } else {
469
  $group_value['repeat'] = false;
@@ -471,44 +481,44 @@ class Smart_Custom_Fields_Controller_Settings {
471
 
472
  // If "repeat" isn't true, empty name
473
  // If "repeat" is true and name is empty, assign index
474
- if ( !( isset( $group_value['repeat'] ) && $group_value['repeat'] === true && !empty( $group_value['group-name'] ) ) ) {
475
  $group_value['group-name'] = $group_key;
476
  }
477
 
478
  $group_value['fields'] = $fields;
479
- $data[] = $group_value;
480
  }
481
  }
482
  update_post_meta( $post_id, SCF_Config::PREFIX . 'setting', $data );
483
 
484
- if ( !isset( $_POST[SCF_Config::PREFIX . 'condition'] ) ) {
485
  delete_post_meta( $post_id, SCF_Config::PREFIX . 'condition' );
486
  } else {
487
- update_post_meta( $post_id, SCF_Config::PREFIX . 'condition', $_POST[SCF_Config::PREFIX . 'condition'] );
488
  }
489
 
490
- if ( !isset( $_POST[SCF_Config::PREFIX . 'condition-post-ids'] ) ) {
491
  delete_post_meta( $post_id, SCF_Config::PREFIX . 'condition-post-ids' );
492
  } else {
493
- update_post_meta( $post_id, SCF_Config::PREFIX . 'condition-post-ids', $_POST[SCF_Config::PREFIX . 'condition-post-ids'] );
494
  }
495
 
496
- if ( !isset( $_POST[SCF_Config::PREFIX . 'roles'] ) ) {
497
  delete_post_meta( $post_id, SCF_Config::PREFIX . 'roles' );
498
  } else {
499
- update_post_meta( $post_id, SCF_Config::PREFIX . 'roles', $_POST[SCF_Config::PREFIX . 'roles'] );
500
  }
501
 
502
- if ( !isset( $_POST[SCF_Config::PREFIX . 'taxonomies'] ) ) {
503
  delete_post_meta( $post_id, SCF_Config::PREFIX . 'taxonomies' );
504
  } else {
505
- update_post_meta( $post_id, SCF_Config::PREFIX . 'taxonomies', $_POST[SCF_Config::PREFIX . 'taxonomies'] );
506
  }
507
 
508
- if ( !isset( $_POST[SCF_Config::PREFIX . 'options-pages'] ) ) {
509
  delete_post_meta( $post_id, SCF_Config::PREFIX . 'options-pages' );
510
  } else {
511
- update_post_meta( $post_id, SCF_Config::PREFIX . 'options-pages', $_POST[SCF_Config::PREFIX . 'options-pages'] );
512
  }
513
  }
514
  }
12
 
13
  /**
14
  * Selectbox choices of the field selection
15
+ *
16
  * @var array
17
  */
18
  private $optgroups = array();
27
  add_action( 'add_meta_boxes', array( $this, 'add_meta_boxes' ) );
28
 
29
  $this->optgroups = array(
30
+ 'basic-fields' => array(
31
  'label' => esc_attr__( 'Basic fields', 'smart-custom-fields' ),
32
  'options' => array(),
33
  ),
34
+ 'select-fields' => array(
35
  'label' => esc_attr__( 'Select fields', 'smart-custom-fields' ),
36
  'options' => array(),
37
  ),
39
  'label' => esc_attr__( 'Content fields', 'smart-custom-fields' ),
40
  'options' => array(),
41
  ),
42
+ 'other-fields' => array(
43
  'label' => esc_attr__( 'Other fields', 'smart-custom-fields' ),
44
  'options' => array(),
45
  ),
55
  global $_wp_admin_css_colors;
56
 
57
  $user_admin_color_scheme = get_user_option( 'admin_color' );
58
+ $colors_obj = $_wp_admin_css_colors[ $user_admin_color_scheme ];
59
 
60
  return $colors_obj;
61
  }
62
 
63
  /**
64
  * Add Custom Inline CSS on Admin Dashboard
 
65
  */
66
+ public function admin_inline_css() {
67
+ $colors = $this->admin_color_scheme()->colors;
68
  $icon_colors = $this->admin_color_scheme()->icon_colors;
69
  ?>
70
  <style>
135
  true
136
  );
137
 
138
+ wp_localize_script(
139
+ SCF_Config::PREFIX . 'settings',
140
+ 'smart_cf_settings',
141
+ array(
142
+ 'duplicate_alert' => esc_html__( 'Same name exists!', 'smart-custom-fields' ),
143
+ 'autocomplete_placeholder' => esc_html__( 'Type to search a post or page', 'smart-custom-fields' ),
144
+ 'loading' => esc_html__( 'Loading...', 'smart-custom-fields' ),
145
+ 'load_more' => esc_html__( 'Load more', 'smart-custom-fields' ),
146
+ 'rest_api_url' => rest_url( SCF_Config::PREFIX . 'api/search/posts' ),
147
+ )
148
+ );
149
 
150
  wp_enqueue_script( 'jquery-ui-sortable' );
151
  do_action( SCF_Config::PREFIX . 'after-settings-enqueue-scripts' );
197
  * @param string $key
198
  */
199
  private function add_hide_class( $key ) {
200
+ if ( ! $key ) {
201
  echo 'hide';
202
  }
203
  }
208
  public function display_meta_box() {
209
  $Setting = SCF::add_setting( get_the_ID(), get_the_title() );
210
  $Setting->add_group_unshift();
211
+ $groups = $Setting->get_groups();
212
  ?>
213
  <div class="<?php echo esc_attr( SCF_Config::PREFIX . 'fields-wrapper' ); ?>">
214
  <div class="<?php echo esc_attr( SCF_Config::PREFIX . 'groups' ); ?>">
227
  <?php
228
  $field_name = $Field->get( 'name' );
229
  $field_label = $Field->get( 'label' );
230
+ if ( ! $field_label ) {
231
  $field_label = $field_name;
232
+ if ( ! $field_label ) {
233
+ $field_label = '&nbsp;';
234
  }
235
  }
236
  ?>
242
  <small>[ <?php echo esc_html( $field_name ); ?> ]</small>
243
  <?php endif; ?>
244
  </div>
245
+ <table class="<?php $this->add_hide_class( ! $Field->get( 'name' ) ); ?>">
246
  <tr>
247
  <th><?php esc_html_e( 'Type', 'smart-custom-fields' ); ?><span class="<?php echo esc_attr( SCF_Config::PREFIX . 'require' ); ?>">*</span></th>
248
  <td>
251
  class="<?php echo esc_attr( SCF_Config::PREFIX . 'field-select' ); ?>" />
252
  <?php
253
  foreach ( $this->optgroups as $optgroup_name => $optgroup_values ) {
254
+ $optgroup_fields = array();
255
  $optgroup_values['options'] = apply_filters(
256
  SCF_Config::PREFIX . 'field-select-' . $optgroup_name,
257
  $optgroup_values['options']
285
  </div>
286
  <div class="button button-primary btn-add-group"><?php esc_html_e( 'Add Field', 'smart-custom-fields' ); ?></div>
287
  </div>
288
+ <?php wp_nonce_field( SCF_Config::NAME . '-settings', SCF_Config::PREFIX . 'settings-nonce' ); ?>
289
  <?php
290
  }
291
 
293
  * Displaying the meta box to set the display conditions for post edit page
294
  */
295
  public function display_meta_box_condition_post() {
296
+ $post_types = get_post_types(
297
+ array(
298
+ 'show_ui' => true,
299
+ ),
300
+ 'objects'
301
+ );
302
  unset( $post_types['attachment'] );
303
+ unset( $post_types[ SCF_Config::NAME ] );
304
 
305
+ $conditions = get_post_meta( get_the_ID(), SCF_Config::PREFIX . 'condition', true );
306
  $post_type_field = '';
307
  foreach ( $post_types as $post_type => $post_type_object ) {
308
+ $current = ( is_array( $conditions ) && in_array( $post_type, $conditions ) ) ? $post_type : false;
309
  $post_type_field .= sprintf(
310
  '<label><input type="checkbox" name="%s" value="%s" %s /> %s</label>',
311
  esc_attr( SCF_Config::PREFIX . 'condition[]' ),
328
  if ( $saved_posts ) {
329
  $saved = array();
330
 
331
+ foreach ( $saved_posts as $k => $post_id ) {
332
+ if ( $post_id != '' ) {
333
  $saved[ $k ]['id'] = $post_id;
334
+ $saved[ $k ]['text'] = $post_id; // $post_id . ' - ' . get_the_title($post_id);
335
  }
336
  }
337
  }
362
  * Displaying the meta box to set the display conditions for profile edit page
363
  */
364
  public function display_meta_box_condition_profile() {
365
+ $roles = get_editable_roles();
366
+ $conditions = get_post_meta( get_the_ID(), SCF_Config::PREFIX . 'roles', true );
367
  $profile_field = '';
368
  foreach ( $roles as $name => $role ) {
369
+ $current = ( is_array( $conditions ) && in_array( $name, $conditions ) ) ? $name : false;
370
  $profile_field .= sprintf(
371
  '<label><input type="checkbox" name="%s" value="%s" %s /> %s</label>',
372
  esc_attr( SCF_Config::PREFIX . 'roles[]' ),
386
  * Displaying the meta box to set the display conditions for term edit page
387
  */
388
  public function display_meta_box_condition_taxonomy() {
389
+ $taxonomies = get_taxonomies(
390
+ array(
391
+ 'show_ui' => true,
392
+ ),
393
+ 'objects'
394
+ );
395
+ $conditions = get_post_meta( get_the_ID(), SCF_Config::PREFIX . 'taxonomies', true );
396
  $taxonomy_field = '';
397
  foreach ( $taxonomies as $name => $taxonomy ) {
398
+ $current = ( is_array( $conditions ) && in_array( $name, $conditions ) ) ? $name : false;
399
  $taxonomy_field .= sprintf(
400
  '<label><input type="checkbox" name="%s" value="%s" %s /> %s</label>',
401
  esc_attr( SCF_Config::PREFIX . 'taxonomies[]' ),
415
  * Displaying the meta box to set the display conditions for custom options page
416
  */
417
  public function display_meta_box_condition_options_page() {
418
+ $optinos_pages = SCF::get_options_pages();
419
+ $conditions = get_post_meta( get_the_ID(), SCF_Config::PREFIX . 'options-pages', true );
420
  $options_page_field = '';
421
  foreach ( $optinos_pages as $name => $optinos_page ) {
422
+ $current = ( is_array( $conditions ) && in_array( $name, $conditions ) ) ? $name : false;
423
  $options_page_field .= sprintf(
424
  '<label><input type="checkbox" name="%s" value="%s" %s /> %s</label>',
425
  esc_attr( SCF_Config::PREFIX . 'options-pages[]' ),
444
  if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
445
  return;
446
  }
447
+ if ( ! isset( $_POST[ SCF_Config::NAME ] ) ) {
448
  return;
449
  }
450
  check_admin_referer(
453
  );
454
 
455
  $data = array();
456
+ foreach ( $_POST[ SCF_Config::NAME ] as $group_key => $group_value ) {
457
  // $group_key = 0 is hidden field so don't save
458
  if ( $group_key === 0 ) {
459
  continue;
460
  }
461
+ if ( ! empty( $group_value['fields'] ) && count( $group_value['fields'] ) > 1 ) {
462
  $fields = array();
463
  foreach ( $group_value['fields'] as $field_key => $field_value ) {
464
  // $field_key = 0 is hidden field so don't save
465
  if ( $field_key === 0 ) {
466
  continue;
467
  }
468
+ if ( ! empty( $field_value['name'] ) ) {
469
  $fields[] = $field_value;
470
  }
471
  }
472
+ if ( ! $fields ) {
473
  continue;
474
  }
475
 
476
+ if ( ! empty( $group_value['repeat'] ) && $group_value['repeat'] === 'true' ) {
477
  $group_value['repeat'] = true;
478
  } else {
479
  $group_value['repeat'] = false;
481
 
482
  // If "repeat" isn't true, empty name
483
  // If "repeat" is true and name is empty, assign index
484
+ if ( ! ( isset( $group_value['repeat'] ) && $group_value['repeat'] === true && ! empty( $group_value['group-name'] ) ) ) {
485
  $group_value['group-name'] = $group_key;
486
  }
487
 
488
  $group_value['fields'] = $fields;
489
+ $data[] = $group_value;
490
  }
491
  }
492
  update_post_meta( $post_id, SCF_Config::PREFIX . 'setting', $data );
493
 
494
+ if ( ! isset( $_POST[ SCF_Config::PREFIX . 'condition' ] ) ) {
495
  delete_post_meta( $post_id, SCF_Config::PREFIX . 'condition' );
496
  } else {
497
+ update_post_meta( $post_id, SCF_Config::PREFIX . 'condition', $_POST[ SCF_Config::PREFIX . 'condition' ] );
498
  }
499
 
500
+ if ( ! isset( $_POST[ SCF_Config::PREFIX . 'condition-post-ids' ] ) ) {
501
  delete_post_meta( $post_id, SCF_Config::PREFIX . 'condition-post-ids' );
502
  } else {
503
+ update_post_meta( $post_id, SCF_Config::PREFIX . 'condition-post-ids', $_POST[ SCF_Config::PREFIX . 'condition-post-ids' ] );
504
  }
505
 
506
+ if ( ! isset( $_POST[ SCF_Config::PREFIX . 'roles' ] ) ) {
507
  delete_post_meta( $post_id, SCF_Config::PREFIX . 'roles' );
508
  } else {
509
+ update_post_meta( $post_id, SCF_Config::PREFIX . 'roles', $_POST[ SCF_Config::PREFIX . 'roles' ] );
510
  }
511
 
512
+ if ( ! isset( $_POST[ SCF_Config::PREFIX . 'taxonomies' ] ) ) {
513
  delete_post_meta( $post_id, SCF_Config::PREFIX . 'taxonomies' );
514
  } else {
515
+ update_post_meta( $post_id, SCF_Config::PREFIX . 'taxonomies', $_POST[ SCF_Config::PREFIX . 'taxonomies' ] );
516
  }
517
 
518
+ if ( ! isset( $_POST[ SCF_Config::PREFIX . 'options-pages' ] ) ) {
519
  delete_post_meta( $post_id, SCF_Config::PREFIX . 'options-pages' );
520
  } else {
521
+ update_post_meta( $post_id, SCF_Config::PREFIX . 'options-pages', $_POST[ SCF_Config::PREFIX . 'options-pages' ] );
522
  }
523
  }
524
  }
classes/controller/class.taxonomy.php CHANGED
@@ -17,8 +17,8 @@ class Smart_Custom_Fields_Controller_Taxonomy extends Smart_Custom_Fields_Contro
17
  parent::__construct();
18
 
19
  add_action( $_REQUEST['taxonomy'] . '_edit_form_fields', array( $this, 'edit_form_fields' ) );
20
- add_action( 'edited_terms' , array( $this, 'update' ), 10, 2 );
21
- add_action( 'delete_term' , array( $this, 'delete' ), 10, 4 );
22
  }
23
 
24
  /**
@@ -57,14 +57,14 @@ class Smart_Custom_Fields_Controller_Taxonomy extends Smart_Custom_Fields_Contro
57
  /**
58
  * Saving meta data from custom fields in term edit page
59
  *
60
- * @param int $term_id
61
  * @param string $taxonomy
62
  */
63
  public function update( $term_id, $taxonomy ) {
64
- if ( !current_user_can( 'manage_categories' ) ) {
65
  return;
66
  }
67
- if ( !isset( $_POST[SCF_Config::NAME] ) ) {
68
  return;
69
  }
70
 
@@ -75,8 +75,8 @@ class Smart_Custom_Fields_Controller_Taxonomy extends Smart_Custom_Fields_Contro
75
  /**
76
  * Delete meta data
77
  *
78
- * @param int $term_id
79
- * @param int $term_taxonomy_id
80
  * @param string $taxonomy
81
  * @param object $deleted_term
82
  */
17
  parent::__construct();
18
 
19
  add_action( $_REQUEST['taxonomy'] . '_edit_form_fields', array( $this, 'edit_form_fields' ) );
20
+ add_action( 'edited_terms', array( $this, 'update' ), 10, 2 );
21
+ add_action( 'delete_term', array( $this, 'delete' ), 10, 4 );
22
  }
23
 
24
  /**
57
  /**
58
  * Saving meta data from custom fields in term edit page
59
  *
60
+ * @param int $term_id
61
  * @param string $taxonomy
62
  */
63
  public function update( $term_id, $taxonomy ) {
64
+ if ( ! current_user_can( 'manage_categories' ) ) {
65
  return;
66
  }
67
+ if ( ! isset( $_POST[ SCF_Config::NAME ] ) ) {
68
  return;
69
  }
70
 
75
  /**
76
  * Delete meta data
77
  *
78
+ * @param int $term_id
79
+ * @param int $term_taxonomy_id
80
  * @param string $taxonomy
81
  * @param object $deleted_term
82
  */
classes/fields/class.field-boolean.php CHANGED
@@ -143,24 +143,24 @@ class Smart_Custom_Fields_Field_Boolean extends Smart_Custom_Fields_Field_Base {
143
  />
144
  </td>
145
  </tr>
146
- <?php
147
  }
148
 
149
  /**
150
  * Validating when displaying meta data
151
  *
152
  * @param int|string $value
153
- * @param string $field_type
154
  * @return boolean
155
  */
156
  public function validate_get_value( $value, $field_type ) {
157
  if ( $field_type === $this->get_attribute( 'type' ) ) {
158
  if ( is_array( $value ) ) {
159
  foreach ( $value as $key => $val ) {
160
- $value[$key] = !!$val;
161
  }
162
  } else {
163
- $value = !!$value;
164
  }
165
  }
166
  return $value;
143
  />
144
  </td>
145
  </tr>
146
+ <?php
147
  }
148
 
149
  /**
150
  * Validating when displaying meta data
151
  *
152
  * @param int|string $value
153
+ * @param string $field_type
154
  * @return boolean
155
  */
156
  public function validate_get_value( $value, $field_type ) {
157
  if ( $field_type === $this->get_attribute( 'type' ) ) {
158
  if ( is_array( $value ) ) {
159
  foreach ( $value as $key => $val ) {
160
+ $value[ $key ] = ! ! $val;
161
  }
162
  } else {
163
+ $value = ! ! $value;
164
  }
165
  }
166
  return $value;
classes/fields/class.field-check.php CHANGED
@@ -42,7 +42,7 @@ class Smart_Custom_Fields_Field_Check extends Smart_Custom_Fields_Field_Base {
42
  /**
43
  * Getting the field
44
  *
45
- * @param int $index
46
  * @param array $value
47
  * @return string html
48
  */
@@ -59,7 +59,7 @@ class Smart_Custom_Fields_Field_Check extends Smart_Custom_Fields_Field_Base {
59
  );
60
  foreach ( $choices as $key => $choice ) {
61
  $choice = trim( $choice );
62
- if ( !SCF::is_assoc( $choices ) ) {
63
  $key = $choice;
64
  }
65
  $form_field .= sprintf(
@@ -101,7 +101,7 @@ class Smart_Custom_Fields_Field_Check extends Smart_Custom_Fields_Field_Base {
101
  <?php
102
  $directions = array(
103
  'horizontal' => __( 'horizontal', 'smart-custom-fields' ),
104
- 'vertical' => __( 'vertical' , 'smart-custom-fields' ),
105
  );
106
  foreach ( $directions as $key => $value ) {
107
  printf(
42
  /**
43
  * Getting the field
44
  *
45
+ * @param int $index
46
  * @param array $value
47
  * @return string html
48
  */
59
  );
60
  foreach ( $choices as $key => $choice ) {
61
  $choice = trim( $choice );
62
+ if ( ! SCF::is_assoc( $choices ) ) {
63
  $key = $choice;
64
  }
65
  $form_field .= sprintf(
101
  <?php
102
  $directions = array(
103
  'horizontal' => __( 'horizontal', 'smart-custom-fields' ),
104
+ 'vertical' => __( 'vertical', 'smart-custom-fields' ),
105
  );
106
  foreach ( $directions as $key => $value ) {
107
  printf(
classes/fields/class.field-colorpicker.php CHANGED
@@ -77,7 +77,7 @@ class Smart_Custom_Fields_Field_Colorpicker extends Smart_Custom_Fields_Field_Ba
77
  /**
78
  * Getting the field
79
  *
80
- * @param int $index
81
  * @param string $value
82
  * @return string html
83
  */
77
  /**
78
  * Getting the field
79
  *
80
+ * @param int $index
81
  * @param string $value
82
  * @return string html
83
  */
classes/fields/class.field-datepicker.php CHANGED
@@ -97,7 +97,7 @@ class Smart_Custom_Fields_Field_Datepicker extends Smart_Custom_Fields_Field_Bas
97
  /**
98
  * Getting the field
99
  *
100
- * @param int $index
101
  * @param string $value
102
  * @return string html
103
  */
@@ -146,11 +146,13 @@ class Smart_Custom_Fields_Field_Datepicker extends Smart_Custom_Fields_Field_Bas
146
  /><br />
147
  <span class="<?php echo esc_attr( SCF_Config::PREFIX ); ?>notes">
148
  <?php esc_html_e( 'e.g dd/mm/yy', 'smart-custom-fields' ); ?>
149
- <?php printf(
 
150
  esc_html( 'Prease see %sdateFormat%s', 'smart-custom-fields' ),
151
  '<a href="http://api.jqueryui.com/datepicker/#option-dateFormat" target="_blank">',
152
  '</a>'
153
- ); ?>
 
154
  </span>
155
  </td>
156
  </tr>
@@ -164,11 +166,13 @@ class Smart_Custom_Fields_Field_Datepicker extends Smart_Custom_Fields_Field_Bas
164
  /><br />
165
  <span class="<?php echo esc_attr( SCF_Config::PREFIX ); ?>notes">
166
  <?php esc_html_e( 'e.g +1m +1w', 'smart-custom-fields' ); ?>
167
- <?php printf(
 
168
  esc_html( 'Prease see %smaxData%s', 'smart-custom-fields' ),
169
  '<a href="http://api.jqueryui.com/datepicker/#option-maxDate" target="_blank">',
170
  '</a>'
171
- ); ?>
 
172
  </span>
173
  </td>
174
  </tr>
@@ -182,11 +186,13 @@ class Smart_Custom_Fields_Field_Datepicker extends Smart_Custom_Fields_Field_Bas
182
  /><br />
183
  <span class="<?php echo esc_attr( SCF_Config::PREFIX ); ?>notes">
184
  <?php esc_html_e( 'e.g +1m +1w', 'smart-custom-fields' ); ?>
185
- <?php printf(
 
186
  esc_html( 'Prease see %sminData%s', 'smart-custom-fields' ),
187
  '<a href="http://api.jqueryui.com/datepicker/#option-minDate" target="_blank">',
188
  '</a>'
189
- ); ?>
 
190
  </span>
191
  </td>
192
  </tr>
@@ -224,25 +230,68 @@ class Smart_Custom_Fields_Field_Datepicker extends Smart_Custom_Fields_Field_Bas
224
 
225
  // If locale is Japanese, change in Japanese notation
226
  if ( get_locale() === 'ja' ) {
227
- $js = array_merge( $js, array(
228
- 'yearSuffix' => '年',
229
- 'dateFormat' => 'yy-mm-dd',
230
- 'dayNames' => array(
231
- '日曜日', '月曜日', '火曜日', '水曜日', '木曜日', '金曜日', '土曜日',
232
- ),
233
- 'dayNamesMin' => array(
234
- '', '月', '火', '水', '木', '金', '土',
235
- ),
236
- 'dayNamesShort' => array(
237
- '日曜', '月曜', '火曜', '水曜', '木曜', '金曜', '土曜',
238
- ),
239
- 'monthNames' => array(
240
- '1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月',
241
- ),
242
- 'monthNamesShort' => array(
243
- '1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月',
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
244
  )
245
- ) );
246
  }
247
 
248
  if ( $this->get( 'date_format' ) ) {
97
  /**
98
  * Getting the field
99
  *
100
+ * @param int $index
101
  * @param string $value
102
  * @return string html
103
  */
146
  /><br />
147
  <span class="<?php echo esc_attr( SCF_Config::PREFIX ); ?>notes">
148
  <?php esc_html_e( 'e.g dd/mm/yy', 'smart-custom-fields' ); ?>
149
+ <?php
150
+ printf(
151
  esc_html( 'Prease see %sdateFormat%s', 'smart-custom-fields' ),
152
  '<a href="http://api.jqueryui.com/datepicker/#option-dateFormat" target="_blank">',
153
  '</a>'
154
+ );
155
+ ?>
156
  </span>
157
  </td>
158
  </tr>
166
  /><br />
167
  <span class="<?php echo esc_attr( SCF_Config::PREFIX ); ?>notes">
168
  <?php esc_html_e( 'e.g +1m +1w', 'smart-custom-fields' ); ?>
169
+ <?php
170
+ printf(
171
  esc_html( 'Prease see %smaxData%s', 'smart-custom-fields' ),
172
  '<a href="http://api.jqueryui.com/datepicker/#option-maxDate" target="_blank">',
173
  '</a>'
174
+ );
175
+ ?>
176
  </span>
177
  </td>
178
  </tr>
186
  /><br />
187
  <span class="<?php echo esc_attr( SCF_Config::PREFIX ); ?>notes">
188
  <?php esc_html_e( 'e.g +1m +1w', 'smart-custom-fields' ); ?>
189
+ <?php
190
+ printf(
191
  esc_html( 'Prease see %sminData%s', 'smart-custom-fields' ),
192
  '<a href="http://api.jqueryui.com/datepicker/#option-minDate" target="_blank">',
193
  '</a>'
194
+ );
195
+ ?>
196
  </span>
197
  </td>
198
  </tr>
230
 
231
  // If locale is Japanese, change in Japanese notation
232
  if ( get_locale() === 'ja' ) {
233
+ $js = array_merge(
234
+ $js,
235
+ array(
236
+ 'yearSuffix' => '年',
237
+ 'dateFormat' => 'yy-mm-dd',
238
+ 'dayNames' => array(
239
+ '日曜日',
240
+ '月曜日',
241
+ '火曜日',
242
+ '水曜日',
243
+ '木曜日',
244
+ '金曜日',
245
+ '土曜日',
246
+ ),
247
+ 'dayNamesMin' => array(
248
+ '',
249
+ '月',
250
+ '火',
251
+ '水',
252
+ '木',
253
+ '金',
254
+ '土',
255
+ ),
256
+ 'dayNamesShort' => array(
257
+ '日曜',
258
+ '月曜',
259
+ '火曜',
260
+ '水曜',
261
+ '木曜',
262
+ '金曜',
263
+ '土曜',
264
+ ),
265
+ 'monthNames' => array(
266
+ '1月',
267
+ '2月',
268
+ '3月',
269
+ '4月',
270
+ '5月',
271
+ '6月',
272
+ '7月',
273
+ '8月',
274
+ '9月',
275
+ '10月',
276
+ '11月',
277
+ '12月',
278
+ ),
279
+ 'monthNamesShort' => array(
280
+ '1月',
281
+ '2月',
282
+ '3月',
283
+ '4月',
284
+ '5月',
285
+ '6月',
286
+ '7月',
287
+ '8月',
288
+ '9月',
289
+ '10月',
290
+ '11月',
291
+ '12月',
292
+ ),
293
  )
294
+ );
295
  }
296
 
297
  if ( $this->get( 'date_format' ) ) {
classes/fields/class.field-datetime-picker.php CHANGED
@@ -135,7 +135,7 @@ class Smart_Custom_Fields_Field_Datetime_Picker extends Smart_Custom_Fields_Fiel
135
 
136
  return '<input
137
  type="text"
138
- name="' . esc_attr( $name ) . '"
139
  value="' . esc_attr( $value ) . '"
140
  class="' . esc_attr( SCF_Config::PREFIX . 'datetime_picker' ) . '"
141
  data-js=\'' . $data_js . '\'
@@ -357,7 +357,8 @@ class Smart_Custom_Fields_Field_Datetime_Picker extends Smart_Custom_Fields_Fiel
357
 
358
  $wp_locale = get_locale();
359
  if ( strpos( $wp_locale, '_' ) ) {
360
- $user_lang = explode( $wp_locale, '_' )[0];
 
361
  } else {
362
  $user_lang = $wp_locale;
363
  }
135
 
136
  return '<input
137
  type="text"
138
+ name="' . esc_attr( $name ) . '"
139
  value="' . esc_attr( $value ) . '"
140
  class="' . esc_attr( SCF_Config::PREFIX . 'datetime_picker' ) . '"
141
  data-js=\'' . $data_js . '\'
357
 
358
  $wp_locale = get_locale();
359
  if ( strpos( $wp_locale, '_' ) ) {
360
+ $_user_lang = explode( $wp_locale, '_' );
361
+ $user_lang = $_user_lang[0];
362
  } else {
363
  $user_lang = $wp_locale;
364
  }
classes/fields/class.field-file.php CHANGED
@@ -38,7 +38,7 @@ class Smart_Custom_Fields_Field_File extends Smart_Custom_Fields_Field_Base {
38
  /**
39
  * Getting the field
40
  *
41
- * @param int $index
42
  * @param string $value
43
  * @return string html
44
  */
@@ -52,20 +52,20 @@ class Smart_Custom_Fields_Field_File extends Smart_Custom_Fields_Field_Base {
52
  );
53
 
54
  $hide_class = 'hide';
55
- $image = $btn_remove;
56
  if ( $value ) {
57
  // Usually, $value is attachment ID.
58
  // If a customized, for example, $value is not an ID,
59
  // Regarded the $value is file URL.
60
  if ( preg_match( '/^\d+$/', $value ) ) {
61
  $image_src = wp_get_attachment_image_src( $value, 'thumbnail', true );
62
- $image_alt = get_the_title($value);
63
  if ( is_array( $image_src ) && isset( $image_src[0] ) ) {
64
  $image_src = $image_src[0];
65
  }
66
  } else {
67
- $imag_url = $value;
68
- $path = str_replace( home_url(), '', $value );
69
  $image_path = ABSPATH . untrailingslashit( $path );
70
  if ( file_exists( $image_path ) ) {
71
  $wp_check_filetype = wp_check_filetype( $image_path );
@@ -76,12 +76,12 @@ class Smart_Custom_Fields_Field_File extends Smart_Custom_Fields_Field_Base {
76
  }
77
 
78
  if ( $image_src && ! is_array( $image_src ) ) {
79
- $attachment = get_post( $value );
80
- $attachment_name = $attachment->post_name;
81
- $attachment_url = get_attached_file( $attachment->ID );
82
- $filetype = wp_check_filetype( $attachment_url );
83
- $filename = $attachment_name . '.' . $filetype['ext'];
84
- $image = sprintf(
85
  '<a href="%s" target="_blank"><img src="%s" alt="%s" />%s</a>%s',
86
  wp_get_attachment_url( $value ),
87
  esc_url( $image_src ),
@@ -89,7 +89,7 @@ class Smart_Custom_Fields_Field_File extends Smart_Custom_Fields_Field_Base {
89
  esc_attr( $filename ),
90
  $btn_remove
91
  );
92
- $hide_class = '';
93
  }
94
  }
95
 
38
  /**
39
  * Getting the field
40
  *
41
+ * @param int $index
42
  * @param string $value
43
  * @return string html
44
  */
52
  );
53
 
54
  $hide_class = 'hide';
55
+ $image = $btn_remove;
56
  if ( $value ) {
57
  // Usually, $value is attachment ID.
58
  // If a customized, for example, $value is not an ID,
59
  // Regarded the $value is file URL.
60
  if ( preg_match( '/^\d+$/', $value ) ) {
61
  $image_src = wp_get_attachment_image_src( $value, 'thumbnail', true );
62
+ $image_alt = get_the_title( $value );
63
  if ( is_array( $image_src ) && isset( $image_src[0] ) ) {
64
  $image_src = $image_src[0];
65
  }
66
  } else {
67
+ $imag_url = $value;
68
+ $path = str_replace( home_url(), '', $value );
69
  $image_path = ABSPATH . untrailingslashit( $path );
70
  if ( file_exists( $image_path ) ) {
71
  $wp_check_filetype = wp_check_filetype( $image_path );
76
  }
77
 
78
  if ( $image_src && ! is_array( $image_src ) ) {
79
+ $attachment = get_post( $value );
80
+ $attachment_name = $attachment->post_name;
81
+ $attachment_url = get_attached_file( $attachment->ID );
82
+ $filetype = wp_check_filetype( $attachment_url );
83
+ $filename = $attachment_name . '.' . $filetype['ext'];
84
+ $image = sprintf(
85
  '<a href="%s" target="_blank"><img src="%s" alt="%s" />%s</a>%s',
86
  wp_get_attachment_url( $value ),
87
  esc_url( $image_src ),
89
  esc_attr( $filename ),
90
  $btn_remove
91
  );
92
+ $hide_class = '';
93
  }
94
  }
95
 
classes/fields/class.field-image.php CHANGED
@@ -39,7 +39,7 @@ class Smart_Custom_Fields_Field_Image extends Smart_Custom_Fields_Field_Base {
39
  /**
40
  * Getting the field
41
  *
42
- * @param int $index
43
  * @param string $value
44
  * @return string html
45
  */
@@ -53,20 +53,20 @@ class Smart_Custom_Fields_Field_Image extends Smart_Custom_Fields_Field_Base {
53
  );
54
 
55
  $hide_class = 'hide';
56
- $image = $btn_remove;
57
  if ( $value ) {
58
  // Usually, $value is attachment ID.
59
  // If a customized, for example, $value is not an ID,
60
  // Regarded the $value is file URL.
61
  if ( preg_match( '/^\d+$/', $value ) ) {
62
  $image_src = wp_get_attachment_image_src( $value, $this->get( 'size' ) );
63
- $image_alt = get_the_title($value);
64
  if ( is_array( $image_src ) && isset( $image_src[0] ) ) {
65
  $image_src = $image_src[0];
66
  }
67
  } else {
68
- $image_url = $value;
69
- $path = str_replace( home_url(), '', $value );
70
  $image_path = ABSPATH . untrailingslashit( $path );
71
  if ( file_exists( $image_path ) ) {
72
  $wp_check_filetype = wp_check_filetype( $image_path );
@@ -77,7 +77,7 @@ class Smart_Custom_Fields_Field_Image extends Smart_Custom_Fields_Field_Base {
77
  }
78
 
79
  if ( $image_src && ! is_array( $image_src ) ) {
80
- $image = sprintf(
81
  '<img src="%s" alt="%s" />%s',
82
  esc_url( $image_src ),
83
  $image_alt,
@@ -133,10 +133,10 @@ class Smart_Custom_Fields_Field_Image extends Smart_Custom_Fields_Field_Base {
133
  <th><?php esc_html_e( 'Preview Size', 'smart-custom-fields' ); ?></th>
134
  <td>
135
  <select name="<?php echo esc_attr( $this->get_field_name_in_setting( $group_key, $field_key, 'size' ) ); ?>">
136
- <option value="full" <?php selected( $this->get( 'size' ), 'full' );?> >full</option>
137
  <?php foreach ( get_intermediate_image_sizes() as $size ) : ?>
138
- <option value="<?php echo esc_attr( $size );?>" <?php selected( $this->get( 'size' ), $size );?>><?php echo esc_html( $size );?></option>
139
- <?php endforeach;?>
140
  </select>
141
  </td>
142
  </tr>
39
  /**
40
  * Getting the field
41
  *
42
+ * @param int $index
43
  * @param string $value
44
  * @return string html
45
  */
53
  );
54
 
55
  $hide_class = 'hide';
56
+ $image = $btn_remove;
57
  if ( $value ) {
58
  // Usually, $value is attachment ID.
59
  // If a customized, for example, $value is not an ID,
60
  // Regarded the $value is file URL.
61
  if ( preg_match( '/^\d+$/', $value ) ) {
62
  $image_src = wp_get_attachment_image_src( $value, $this->get( 'size' ) );
63
+ $image_alt = get_the_title( $value );
64
  if ( is_array( $image_src ) && isset( $image_src[0] ) ) {
65
  $image_src = $image_src[0];
66
  }
67
  } else {
68
+ $image_url = $value;
69
+ $path = str_replace( home_url(), '', $value );
70
  $image_path = ABSPATH . untrailingslashit( $path );
71
  if ( file_exists( $image_path ) ) {
72
  $wp_check_filetype = wp_check_filetype( $image_path );
77
  }
78
 
79
  if ( $image_src && ! is_array( $image_src ) ) {
80
+ $image = sprintf(
81
  '<img src="%s" alt="%s" />%s',
82
  esc_url( $image_src ),
83
  $image_alt,
133
  <th><?php esc_html_e( 'Preview Size', 'smart-custom-fields' ); ?></th>
134
  <td>
135
  <select name="<?php echo esc_attr( $this->get_field_name_in_setting( $group_key, $field_key, 'size' ) ); ?>">
136
+ <option value="full" <?php selected( $this->get( 'size' ), 'full' ); ?> >full</option>
137
  <?php foreach ( get_intermediate_image_sizes() as $size ) : ?>
138
+ <option value="<?php echo esc_attr( $size ); ?>" <?php selected( $this->get( 'size' ), $size ); ?>><?php echo esc_html( $size ); ?></option>
139
+ <?php endforeach; ?>
140
  </select>
141
  </td>
142
  </tr>
classes/fields/class.field-message.php CHANGED
@@ -21,7 +21,7 @@ class Smart_Custom_Fields_Field_Message extends Smart_Custom_Fields_Field_Base {
21
  'display-name' => __( 'Message', 'smart-custom-fields' ),
22
  'optgroup' => 'basic-fields',
23
  'allow-multiple-data' => false,
24
- 'layout' => 'full-width'
25
  );
26
  }
27
 
@@ -32,15 +32,15 @@ class Smart_Custom_Fields_Field_Message extends Smart_Custom_Fields_Field_Base {
32
  */
33
  protected function options() {
34
  return array(
35
- 'default' => '',
36
- 'notes' => ''
37
  );
38
  }
39
 
40
  /**
41
  * Getting the field
42
  *
43
- * @param int $index
44
  * @param string $value
45
  * @return string html
46
  */
21
  'display-name' => __( 'Message', 'smart-custom-fields' ),
22
  'optgroup' => 'basic-fields',
23
  'allow-multiple-data' => false,
24
+ 'layout' => 'full-width',
25
  );
26
  }
27
 
32
  */
33
  protected function options() {
34
  return array(
35
+ 'default' => '',
36
+ 'notes' => '',
37
  );
38
  }
39
 
40
  /**
41
  * Getting the field
42
  *
43
+ * @param int $index
44
  * @param string $value
45
  * @return string html
46
  */
classes/fields/class.field-radio.php CHANGED
@@ -41,7 +41,7 @@ class Smart_Custom_Fields_Field_Radio extends Smart_Custom_Fields_Field_Base {
41
  /**
42
  * Getting the field
43
  *
44
- * @param int $index
45
  * @param string $value
46
  * @return string html
47
  */
@@ -58,7 +58,7 @@ class Smart_Custom_Fields_Field_Radio extends Smart_Custom_Fields_Field_Base {
58
  );
59
  foreach ( $choices as $key => $choice ) {
60
  $choice = trim( $choice );
61
- if ( !SCF::is_assoc( $choices ) ) {
62
  $key = $choice;
63
  }
64
  $form_field .= sprintf(
@@ -100,7 +100,7 @@ class Smart_Custom_Fields_Field_Radio extends Smart_Custom_Fields_Field_Base {
100
  <?php
101
  $directions = array(
102
  'horizontal' => __( 'horizontal', 'smart-custom-fields' ),
103
- 'vertical' => __( 'vertical' , 'smart-custom-fields' ),
104
  );
105
  foreach ( $directions as $key => $value ) {
106
  printf(
41
  /**
42
  * Getting the field
43
  *
44
+ * @param int $index
45
  * @param string $value
46
  * @return string html
47
  */
58
  );
59
  foreach ( $choices as $key => $choice ) {
60
  $choice = trim( $choice );
61
+ if ( ! SCF::is_assoc( $choices ) ) {
62
  $key = $choice;
63
  }
64
  $form_field .= sprintf(
100
  <?php
101
  $directions = array(
102
  'horizontal' => __( 'horizontal', 'smart-custom-fields' ),
103
+ 'vertical' => __( 'vertical', 'smart-custom-fields' ),
104
  );
105
  foreach ( $directions as $key => $value ) {
106
  printf(
classes/fields/class.field-related-posts.php CHANGED
@@ -63,11 +63,15 @@ class Smart_Custom_Fields_Field_Related_Posts extends Smart_Custom_Fields_Field_
63
  true
64
  );
65
 
66
- wp_localize_script( SCF_Config::PREFIX . 'editor-relation-post-types', 'smart_cf_relation_post_types', array(
67
- 'endpoint' => admin_url( 'admin-ajax.php' ),
68
- 'action' => SCF_Config::PREFIX . 'relational-posts-search',
69
- 'nonce' => wp_create_nonce( SCF_Config::NAME . '-relation-post-types' )
70
- ) );
 
 
 
 
71
  }
72
 
73
  /**
@@ -78,10 +82,10 @@ class Smart_Custom_Fields_Field_Related_Posts extends Smart_Custom_Fields_Field_
78
  $_posts = array();
79
  if ( isset( $_POST['post_types'] ) ) {
80
  $post_type = explode( ',', $_POST['post_types'] );
81
- $args = array(
82
- 'post_type' => $post_type,
83
- 'order' => 'ASC',
84
- 'orderby' => 'ID',
85
  'posts_per_page' => -1,
86
  'post_status' => 'any',
87
  );
@@ -107,7 +111,7 @@ class Smart_Custom_Fields_Field_Related_Posts extends Smart_Custom_Fields_Field_
107
  );
108
  }
109
 
110
- $field_name = sanitize_text_field( $_POST['field_name'] );
111
  /**
112
  * This filter will be always applied when it queries posts in related posts field.
113
  */
@@ -128,7 +132,7 @@ class Smart_Custom_Fields_Field_Related_Posts extends Smart_Custom_Fields_Field_
128
  /**
129
  * Getting the field
130
  *
131
- * @param int $index
132
  * @param array $value
133
  * @return string html
134
  */
@@ -181,17 +185,17 @@ class Smart_Custom_Fields_Field_Related_Posts extends Smart_Custom_Fields_Field_
181
 
182
  // selected
183
  $selected_posts = array();
184
- if ( !empty( $value ) && is_array( $value ) ) {
185
  foreach ( $value as $post_id ) {
186
  $post_title = get_the_title( $post_id );
187
  if ( empty( $post_title ) ) {
188
  $post_title = '&nbsp;';
189
  }
190
- $selected_posts[$post_id] = $post_title;
191
  }
192
  }
193
  $selected_li = array();
194
- $hidden = array();
195
  foreach ( $selected_posts as $post_id => $post_title ) {
196
  $selected_li[] = sprintf(
197
  '<li data-id="%d" data-status="%s"><span class="%s"></span>%s<span class="relation-remove">-</li></li>',
@@ -200,7 +204,7 @@ class Smart_Custom_Fields_Field_Related_Posts extends Smart_Custom_Fields_Field_
200
  esc_attr( SCF_Config::PREFIX . 'icon-handle dashicons dashicons-menu' ),
201
  $post_title
202
  );
203
- $hidden[] = sprintf(
204
  '<input type="hidden" name="%s" value="%d" %s />',
205
  esc_attr( $name . '[]' ),
206
  $post_id,
@@ -259,16 +263,20 @@ class Smart_Custom_Fields_Field_Related_Posts extends Smart_Custom_Fields_Field_
259
  <th><?php esc_html_e( 'Post Types', 'smart-custom-fields' ); ?></th>
260
  <td>
261
  <?php
262
- $post_types = get_post_types( array(
263
- 'show_ui' => true,
264
- ), 'objects' );
 
 
 
265
  unset( $post_types['attachment'] );
266
- unset( $post_types[SCF_Config::NAME] );
267
  ?>
268
  <?php foreach ( $post_types as $post_type => $post_type_object ) : ?>
269
- <?php
270
- $save_post_types = $this->get( 'post-type' );
271
- $checked = ( is_array( $save_post_types ) && in_array( $post_type, $save_post_types ) ) ? 'checked="checked"' : ''; ?>
 
272
  <input type="checkbox"
273
  name="<?php echo esc_attr( $this->get_field_name_in_setting( $group_key, $field_key, 'post-type' ) ); ?>[]"
274
  value="<?php echo esc_attr( $post_type ); ?>"
@@ -307,7 +315,7 @@ class Smart_Custom_Fields_Field_Related_Posts extends Smart_Custom_Fields_Field_
307
  /**
308
  * Validating when displaying meta data
309
  *
310
- * @param array $value
311
  * @param string $field_type
312
  * @return array
313
  */
63
  true
64
  );
65
 
66
+ wp_localize_script(
67
+ SCF_Config::PREFIX . 'editor-relation-post-types',
68
+ 'smart_cf_relation_post_types',
69
+ array(
70
+ 'endpoint' => admin_url( 'admin-ajax.php' ),
71
+ 'action' => SCF_Config::PREFIX . 'relational-posts-search',
72
+ 'nonce' => wp_create_nonce( SCF_Config::NAME . '-relation-post-types' ),
73
+ )
74
+ );
75
  }
76
 
77
  /**
82
  $_posts = array();
83
  if ( isset( $_POST['post_types'] ) ) {
84
  $post_type = explode( ',', $_POST['post_types'] );
85
+ $args = array(
86
+ 'post_type' => $post_type,
87
+ 'order' => 'ASC',
88
+ 'orderby' => 'ID',
89
  'posts_per_page' => -1,
90
  'post_status' => 'any',
91
  );
111
  );
112
  }
113
 
114
+ $field_name = sanitize_text_field( $_POST['field_name'] );
115
  /**
116
  * This filter will be always applied when it queries posts in related posts field.
117
  */
132
  /**
133
  * Getting the field
134
  *
135
+ * @param int $index
136
  * @param array $value
137
  * @return string html
138
  */
185
 
186
  // selected
187
  $selected_posts = array();
188
+ if ( ! empty( $value ) && is_array( $value ) ) {
189
  foreach ( $value as $post_id ) {
190
  $post_title = get_the_title( $post_id );
191
  if ( empty( $post_title ) ) {
192
  $post_title = '&nbsp;';
193
  }
194
+ $selected_posts[ $post_id ] = $post_title;
195
  }
196
  }
197
  $selected_li = array();
198
+ $hidden = array();
199
  foreach ( $selected_posts as $post_id => $post_title ) {
200
  $selected_li[] = sprintf(
201
  '<li data-id="%d" data-status="%s"><span class="%s"></span>%s<span class="relation-remove">-</li></li>',
204
  esc_attr( SCF_Config::PREFIX . 'icon-handle dashicons dashicons-menu' ),
205
  $post_title
206
  );
207
+ $hidden[] = sprintf(
208
  '<input type="hidden" name="%s" value="%d" %s />',
209
  esc_attr( $name . '[]' ),
210
  $post_id,
263
  <th><?php esc_html_e( 'Post Types', 'smart-custom-fields' ); ?></th>
264
  <td>
265
  <?php
266
+ $post_types = get_post_types(
267
+ array(
268
+ 'show_ui' => true,
269
+ ),
270
+ 'objects'
271
+ );
272
  unset( $post_types['attachment'] );
273
+ unset( $post_types[ SCF_Config::NAME ] );
274
  ?>
275
  <?php foreach ( $post_types as $post_type => $post_type_object ) : ?>
276
+ <?php
277
+ $save_post_types = $this->get( 'post-type' );
278
+ $checked = ( is_array( $save_post_types ) && in_array( $post_type, $save_post_types ) ) ? 'checked="checked"' : '';
279
+ ?>
280
  <input type="checkbox"
281
  name="<?php echo esc_attr( $this->get_field_name_in_setting( $group_key, $field_key, 'post-type' ) ); ?>[]"
282
  value="<?php echo esc_attr( $post_type ); ?>"
315
  /**
316
  * Validating when displaying meta data
317
  *
318
+ * @param array $value
319
  * @param string $field_type
320
  * @return array
321
  */
classes/fields/class.field-related-terms.php CHANGED
@@ -63,11 +63,15 @@ class Smart_Custom_Fields_Field_Related_Terms extends Smart_Custom_Fields_Field_
63
  true
64
  );
65
 
66
- wp_localize_script( SCF_Config::PREFIX . 'editor-relation-taxonomies', 'smart_cf_relation_taxonomies', array(
67
- 'endpoint' => admin_url( 'admin-ajax.php' ),
68
- 'action' => SCF_Config::PREFIX . 'relational-terms-search',
69
- 'nonce' => wp_create_nonce( SCF_Config::NAME . '-relation-taxonomies' )
70
- ) );
 
 
 
 
71
  }
72
 
73
  /**
@@ -76,10 +80,10 @@ class Smart_Custom_Fields_Field_Related_Terms extends Smart_Custom_Fields_Field_
76
  public function relational_terms_search() {
77
  check_ajax_referer( SCF_Config::NAME . '-relation-taxonomies', 'nonce' );
78
  $_terms = array();
79
- $args = array();
80
  if ( isset( $_POST['taxonomies'] ) ) {
81
  $taxonomies = explode( ',', $_POST['taxonomies'] );
82
- $args = array(
83
  'order' => 'ASC',
84
  'orderby' => 'ID',
85
  'number' => '',
@@ -90,7 +94,7 @@ class Smart_Custom_Fields_Field_Related_Terms extends Smart_Custom_Fields_Field_
90
  if ( isset( $_POST['click_count'] ) ) {
91
  $number = get_option( 'posts_per_page' );
92
  $offset = $_POST['click_count'] * $number;
93
- $args = array_merge(
94
  $args,
95
  array(
96
  'offset' => $offset,
@@ -117,7 +121,7 @@ class Smart_Custom_Fields_Field_Related_Terms extends Smart_Custom_Fields_Field_
117
  /**
118
  * Getting the field
119
  *
120
- * @param int $index
121
  * @param array $value
122
  * @return string html
123
  */
@@ -135,14 +139,17 @@ class Smart_Custom_Fields_Field_Related_Terms extends Smart_Custom_Fields_Field_
135
  $number = get_option( 'posts_per_page' );
136
 
137
  // choicse
138
- $choices_terms = get_terms( $taxonomies, array(
139
- 'order' => 'ASC',
140
- 'orderby' => 'ID',
141
- 'hide_empty' => false,
142
- 'hierarchical' => false,
143
- 'number' => $number,
144
- ) );
145
- $choices_li = array();
 
 
 
146
  foreach ( $choices_terms as $_term ) {
147
  $term_name = $_term->name;
148
  if ( empty( $term_name ) ) {
@@ -157,17 +164,17 @@ class Smart_Custom_Fields_Field_Related_Terms extends Smart_Custom_Fields_Field_
157
 
158
  // selected
159
  $selected_terms = array();
160
- if ( !empty( $value ) && is_array( $value ) ) {
161
  foreach ( $value as $term_id ) {
162
  $term_name = get_term( $term_id )->name;
163
  if ( empty( $term_name ) ) {
164
  $term_name = '&nbsp;';
165
  }
166
- $selected_terms[$term_id] = $term_name;
167
  }
168
  }
169
  $selected_li = array();
170
- $hidden = array();
171
  foreach ( $selected_terms as $term_id => $term_name ) {
172
  $selected_li[] = sprintf(
173
  '<li data-id="%d"><span class="%s"></span>%s<span class="relation-remove">-</li></li>',
@@ -175,7 +182,7 @@ class Smart_Custom_Fields_Field_Related_Terms extends Smart_Custom_Fields_Field_
175
  esc_attr( SCF_Config::PREFIX . 'icon-handle dashicons dashicons-menu' ),
176
  $term_name
177
  );
178
- $hidden[] = sprintf(
179
  '<input type="hidden" name="%s" value="%d" %s />',
180
  esc_attr( $name . '[]' ),
181
  $term_id,
@@ -233,14 +240,18 @@ class Smart_Custom_Fields_Field_Related_Terms extends Smart_Custom_Fields_Field_
233
  <th><?php esc_html_e( 'Taxonomies', 'smart-custom-fields' ); ?></th>
234
  <td>
235
  <?php
236
- $tasonomies = get_taxonomies( array(
237
- 'show_ui' => true,
238
- ), 'objects' );
 
 
 
239
  ?>
240
  <?php foreach ( $tasonomies as $taxonomy => $taxonomy_object ) : ?>
241
- <?php
242
- $save_taxonomies = $this->get( 'taxonomy' );
243
- $checked = ( is_array( $save_taxonomies ) && in_array( $taxonomy, $save_taxonomies ) ) ? 'checked="checked"' : ''; ?>
 
244
  <input type="checkbox"
245
  name="<?php echo esc_attr( $this->get_field_name_in_setting( $group_key, $field_key, 'taxonomy' ) ); ?>[]"
246
  value="<?php echo esc_attr( $taxonomy ); ?>"
@@ -279,7 +290,7 @@ class Smart_Custom_Fields_Field_Related_Terms extends Smart_Custom_Fields_Field_
279
  /**
280
  * Validating when displaying meta data
281
  *
282
- * @param array $value
283
  * @param string $field_type
284
  * @return array
285
  */
63
  true
64
  );
65
 
66
+ wp_localize_script(
67
+ SCF_Config::PREFIX . 'editor-relation-taxonomies',
68
+ 'smart_cf_relation_taxonomies',
69
+ array(
70
+ 'endpoint' => admin_url( 'admin-ajax.php' ),
71
+ 'action' => SCF_Config::PREFIX . 'relational-terms-search',
72
+ 'nonce' => wp_create_nonce( SCF_Config::NAME . '-relation-taxonomies' ),
73
+ )
74
+ );
75
  }
76
 
77
  /**
80
  public function relational_terms_search() {
81
  check_ajax_referer( SCF_Config::NAME . '-relation-taxonomies', 'nonce' );
82
  $_terms = array();
83
+ $args = array();
84
  if ( isset( $_POST['taxonomies'] ) ) {
85
  $taxonomies = explode( ',', $_POST['taxonomies'] );
86
+ $args = array(
87
  'order' => 'ASC',
88
  'orderby' => 'ID',
89
  'number' => '',
94
  if ( isset( $_POST['click_count'] ) ) {
95
  $number = get_option( 'posts_per_page' );
96
  $offset = $_POST['click_count'] * $number;
97
+ $args = array_merge(
98
  $args,
99
  array(
100
  'offset' => $offset,
121
  /**
122
  * Getting the field
123
  *
124
+ * @param int $index
125
  * @param array $value
126
  * @return string html
127
  */
139
  $number = get_option( 'posts_per_page' );
140
 
141
  // choicse
142
+ $choices_terms = get_terms(
143
+ $taxonomies,
144
+ array(
145
+ 'order' => 'ASC',
146
+ 'orderby' => 'ID',
147
+ 'hide_empty' => false,
148
+ 'hierarchical' => false,
149
+ 'number' => $number,
150
+ )
151
+ );
152
+ $choices_li = array();
153
  foreach ( $choices_terms as $_term ) {
154
  $term_name = $_term->name;
155
  if ( empty( $term_name ) ) {
164
 
165
  // selected
166
  $selected_terms = array();
167
+ if ( ! empty( $value ) && is_array( $value ) ) {
168
  foreach ( $value as $term_id ) {
169
  $term_name = get_term( $term_id )->name;
170
  if ( empty( $term_name ) ) {
171
  $term_name = '&nbsp;';
172
  }
173
+ $selected_terms[ $term_id ] = $term_name;
174
  }
175
  }
176
  $selected_li = array();
177
+ $hidden = array();
178
  foreach ( $selected_terms as $term_id => $term_name ) {
179
  $selected_li[] = sprintf(
180
  '<li data-id="%d"><span class="%s"></span>%s<span class="relation-remove">-</li></li>',
182
  esc_attr( SCF_Config::PREFIX . 'icon-handle dashicons dashicons-menu' ),
183
  $term_name
184
  );
185
+ $hidden[] = sprintf(
186
  '<input type="hidden" name="%s" value="%d" %s />',
187
  esc_attr( $name . '[]' ),
188
  $term_id,
240
  <th><?php esc_html_e( 'Taxonomies', 'smart-custom-fields' ); ?></th>
241
  <td>
242
  <?php
243
+ $tasonomies = get_taxonomies(
244
+ array(
245
+ 'show_ui' => true,
246
+ ),
247
+ 'objects'
248
+ );
249
  ?>
250
  <?php foreach ( $tasonomies as $taxonomy => $taxonomy_object ) : ?>
251
+ <?php
252
+ $save_taxonomies = $this->get( 'taxonomy' );
253
+ $checked = ( is_array( $save_taxonomies ) && in_array( $taxonomy, $save_taxonomies ) ) ? 'checked="checked"' : '';
254
+ ?>
255
  <input type="checkbox"
256
  name="<?php echo esc_attr( $this->get_field_name_in_setting( $group_key, $field_key, 'taxonomy' ) ); ?>[]"
257
  value="<?php echo esc_attr( $taxonomy ); ?>"
290
  /**
291
  * Validating when displaying meta data
292
  *
293
+ * @param array $value
294
  * @param string $field_type
295
  * @return array
296
  */
classes/fields/class.field-select.php CHANGED
@@ -40,22 +40,23 @@ class Smart_Custom_Fields_Field_Select extends Smart_Custom_Fields_Field_Base {
40
  /**
41
  * Getting the field
42
  *
43
- * @param int $index
44
  * @param string $value
45
  * @return string html
46
  */
47
  public function get_field( $index, $value ) {
48
- $name = $this->get_field_name_in_editor( $index );
49
  $disabled = $this->get_disable_attribute( $index );
50
- $choices = SCF::choices_eol_to_array( $this->get( 'choices' ) );
51
 
52
  $form_field = '';
53
  foreach ( $choices as $key => $choice ) {
54
  $choice = trim( $choice );
55
- if ( !SCF::is_assoc( $choices ) ) {
56
  $key = $choice;
57
  }
58
- $form_field .= sprintf( '<option value="%1$s" %2$s>%3$s</option>',
 
59
  esc_attr( $key ),
60
  selected( $value, $key, false ),
61
  esc_html( $choice )
40
  /**
41
  * Getting the field
42
  *
43
+ * @param int $index
44
  * @param string $value
45
  * @return string html
46
  */
47
  public function get_field( $index, $value ) {
48
+ $name = $this->get_field_name_in_editor( $index );
49
  $disabled = $this->get_disable_attribute( $index );
50
+ $choices = SCF::choices_eol_to_array( $this->get( 'choices' ) );
51
 
52
  $form_field = '';
53
  foreach ( $choices as $key => $choice ) {
54
  $choice = trim( $choice );
55
+ if ( ! SCF::is_assoc( $choices ) ) {
56
  $key = $choice;
57
  }
58
+ $form_field .= sprintf(
59
+ '<option value="%1$s" %2$s>%3$s</option>',
60
  esc_attr( $key ),
61
  selected( $value, $key, false ),
62
  esc_html( $choice )
classes/fields/class.field-text.php CHANGED
@@ -39,7 +39,7 @@ class Smart_Custom_Fields_Field_Text extends Smart_Custom_Fields_Field_Base {
39
  /**
40
  * Getting the field
41
  *
42
- * @param int $index
43
  * @param string $value
44
  * @return string html
45
  */
39
  /**
40
  * Getting the field
41
  *
42
+ * @param int $index
43
  * @param string $value
44
  * @return string html
45
  */
classes/fields/class.field-textarea.php CHANGED
@@ -40,7 +40,7 @@ class Smart_Custom_Fields_Field_Textarea extends Smart_Custom_Fields_Field_Base
40
  /**
41
  * Getting the field
42
  *
43
- * @param int $index
44
  * @param string $value
45
  * @return string html
46
  */
40
  /**
41
  * Getting the field
42
  *
43
+ * @param int $index
44
  * @param string $value
45
  * @return string html
46
  */
classes/fields/class.field-wysiwyg.php CHANGED
@@ -72,7 +72,7 @@ class Smart_Custom_Fields_Field_Wysiwyg extends Smart_Custom_Fields_Field_Base {
72
  /**
73
  * Getting the field
74
  *
75
- * @param int $index
76
  * @param string $value
77
  * @return string html
78
  */
@@ -106,7 +106,6 @@ class Smart_Custom_Fields_Field_Wysiwyg extends Smart_Custom_Fields_Field_Base {
106
  $value,
107
  esc_html__( 'Visual', 'smart-custom-fields' ),
108
  esc_html__( 'Text', 'smart-custom-fields' )
109
-
110
  );
111
  }
112
 
@@ -157,7 +156,8 @@ class Smart_Custom_Fields_Field_Wysiwyg extends Smart_Custom_Fields_Field_Base {
157
  */
158
  protected function media_buttons( $editor_id = 'content' ) {
159
  $img = '<span class="wp-media-buttons-icon"></span> ';
160
- return sprintf( '<a href="#" class="button insert-media add_media" data-editor="%s" title="%s">%s</a>',
 
161
  esc_attr( $editor_id ),
162
  esc_attr__( 'Add Media' ),
163
  $img . __( 'Add Media' )
@@ -167,7 +167,7 @@ class Smart_Custom_Fields_Field_Wysiwyg extends Smart_Custom_Fields_Field_Base {
167
  /**
168
  * Validating when displaying meta data
169
  *
170
- * @param mixed $value
171
  * @param string $field_type
172
  * @return string|array
173
  */
@@ -176,7 +176,7 @@ class Smart_Custom_Fields_Field_Wysiwyg extends Smart_Custom_Fields_Field_Base {
176
  if ( is_array( $value ) ) {
177
  $validated_value = array();
178
  foreach ( $value as $k => $v ) {
179
- $validated_value[$k] = $this->add_the_content_filter( $v );
180
  }
181
  $value = $validated_value;
182
  } else {
72
  /**
73
  * Getting the field
74
  *
75
+ * @param int $index
76
  * @param string $value
77
  * @return string html
78
  */
106
  $value,
107
  esc_html__( 'Visual', 'smart-custom-fields' ),
108
  esc_html__( 'Text', 'smart-custom-fields' )
 
109
  );
110
  }
111
 
156
  */
157
  protected function media_buttons( $editor_id = 'content' ) {
158
  $img = '<span class="wp-media-buttons-icon"></span> ';
159
+ return sprintf(
160
+ '<a href="#" class="button insert-media add_media" data-editor="%s" title="%s">%s</a>',
161
  esc_attr( $editor_id ),
162
  esc_attr__( 'Add Media' ),
163
  $img . __( 'Add Media' )
167
  /**
168
  * Validating when displaying meta data
169
  *
170
+ * @param mixed $value
171
  * @param string $field_type
172
  * @return string|array
173
  */
176
  if ( is_array( $value ) ) {
177
  $validated_value = array();
178
  foreach ( $value as $k => $v ) {
179
+ $validated_value[ $k ] = $this->add_the_content_filter( $v );
180
  }
181
  $value = $validated_value;
182
  } else {
classes/models/class.abstract-field-base.php CHANGED
@@ -12,6 +12,7 @@ abstract class Smart_Custom_Fields_Field_Base {
12
 
13
  /**
14
  * Internal attribute value of this field
 
15
  * @var array
16
  */
17
  protected $attributes = array(
@@ -24,6 +25,7 @@ abstract class Smart_Custom_Fields_Field_Base {
24
 
25
  /**
26
  * Options of this field
 
27
  * @var array
28
  */
29
  protected $options = array(
@@ -77,7 +79,7 @@ abstract class Smart_Custom_Fields_Field_Base {
77
  /**
78
  * Getting the field
79
  *
80
- * @param int $index
81
  * @param mixed $value
82
  * @return string html
83
  */
@@ -90,7 +92,7 @@ abstract class Smart_Custom_Fields_Field_Base {
90
  * @return array
91
  */
92
  public function field_select( $attributes ) {
93
- $attributes[$this->get_attribute( 'type' )] = $this->get_attribute( 'display-name' );
94
  return $attributes;
95
  }
96
 
@@ -197,8 +199,8 @@ abstract class Smart_Custom_Fields_Field_Base {
197
  /**
198
  * Getting the name attribute in custom field settings page
199
  *
200
- * @param int $group_key
201
- * @param int $field_key
202
  * @param string $name
203
  * @return string
204
  */
@@ -220,7 +222,7 @@ abstract class Smart_Custom_Fields_Field_Base {
220
  */
221
  public function get( $key ) {
222
  if ( array_key_exists( $key, $this->options ) ) {
223
- return $this->options[$key];
224
  }
225
  }
226
 
@@ -228,11 +230,11 @@ abstract class Smart_Custom_Fields_Field_Base {
228
  * Set option value
229
  *
230
  * @param string $key
231
- * @param mixed $value
232
  */
233
  public function set( $key, $value ) {
234
  if ( array_key_exists( $key, $this->options ) ) {
235
- $this->options[$key] = $value;
236
  }
237
  }
238
 
@@ -244,7 +246,7 @@ abstract class Smart_Custom_Fields_Field_Base {
244
  */
245
  public function get_attribute( $key ) {
246
  if ( array_key_exists( $key, $this->attributes ) ) {
247
- return $this->attributes[$key];
248
  }
249
  }
250
  }
12
 
13
  /**
14
  * Internal attribute value of this field
15
+ *
16
  * @var array
17
  */
18
  protected $attributes = array(
25
 
26
  /**
27
  * Options of this field
28
+ *
29
  * @var array
30
  */
31
  protected $options = array(
79
  /**
80
  * Getting the field
81
  *
82
+ * @param int $index
83
  * @param mixed $value
84
  * @return string html
85
  */
92
  * @return array
93
  */
94
  public function field_select( $attributes ) {
95
+ $attributes[ $this->get_attribute( 'type' ) ] = $this->get_attribute( 'display-name' );
96
  return $attributes;
97
  }
98
 
199
  /**
200
  * Getting the name attribute in custom field settings page
201
  *
202
+ * @param int $group_key
203
+ * @param int $field_key
204
  * @param string $name
205
  * @return string
206
  */
222
  */
223
  public function get( $key ) {
224
  if ( array_key_exists( $key, $this->options ) ) {
225
+ return $this->options[ $key ];
226
  }
227
  }
228
 
230
  * Set option value
231
  *
232
  * @param string $key
233
+ * @param mixed $value
234
  */
235
  public function set( $key, $value ) {
236
  if ( array_key_exists( $key, $this->options ) ) {
237
+ $this->options[ $key ] = $value;
238
  }
239
  }
240
 
246
  */
247
  public function get_attribute( $key ) {
248
  if ( array_key_exists( $key, $this->attributes ) ) {
249
+ return $this->attributes[ $key ];
250
  }
251
  }
252
  }
classes/models/class.ajax.php CHANGED
@@ -22,8 +22,8 @@ class Smart_Custom_Fields_Ajax {
22
  /**
23
  * Deleting term meta
24
  *
25
- * @param int $term_id
26
- * @param int $term_taxonomy_id
27
  * @param string $taxonomy
28
  * @param object $deleted_term
29
  */
22
  /**
23
  * Deleting term meta
24
  *
25
+ * @param int $term_id
26
+ * @param int $term_taxonomy_id
27
  * @param string $taxonomy
28
  * @param object $deleted_term
29
  */
classes/models/class.cache.php CHANGED
@@ -12,6 +12,7 @@ class Smart_Custom_Fields_Cache {
12
 
13
  /**
14
  * Singleton instance
 
15
  * @var Smart_Custom_Fields_Cache
16
  */
17
  private static $instance;
@@ -19,6 +20,7 @@ class Smart_Custom_Fields_Cache {
19
  /**
20
  * Getting data proccesses is heavy. So saved getted data to $meta.
21
  * Using post_id as key.
 
22
  * @var array
23
  */
24
  protected $meta = array();
@@ -26,6 +28,7 @@ class Smart_Custom_Fields_Cache {
26
  /**
27
  * Getting data proccesses is heavy. So saved getted data to $settings_posts.
28
  * Using post_type as key.
 
29
  * @var array
30
  */
31
  protected $settings_posts = array();
@@ -33,6 +36,7 @@ class Smart_Custom_Fields_Cache {
33
  /**
34
  * Getting data proccesses is heavy. So saved getted data to $settings.
35
  * Using post_type as key.
 
36
  * @var array
37
  */
38
  protected $settings = array();
@@ -40,6 +44,7 @@ class Smart_Custom_Fields_Cache {
40
  /**
41
  * Getting data proccesses is heavy. So saved getted data to $repeat_multiple_data.
42
  * Using post_id as key.
 
43
  * @var array
44
  */
45
  protected $repeat_multiple_data = array();
@@ -47,7 +52,7 @@ class Smart_Custom_Fields_Cache {
47
  private function __construct() {}
48
 
49
  public static function getInstance() {
50
- if ( !self::$instance ) {
51
  self::$instance = new Smart_Custom_Fields_Cache();
52
  }
53
  return self::$instance;
@@ -67,16 +72,16 @@ class Smart_Custom_Fields_Cache {
67
  * Saving to cache
68
  *
69
  * @param WP_Post|WP_User|WP_Term|stdClass $object
70
- * @param string $name
71
- * @param mixed $data
72
  */
73
  public function save_meta( $object, $name, $data ) {
74
  $Meta = new Smart_Custom_Fields_Meta( $object );
75
  $id = $Meta->get_id();
76
  $type = $Meta->get_type();
77
  $meta_type = $Meta->get_meta_type();
78
- if ( !empty( $id ) && !empty( $type ) && !empty( $meta_type ) ) {
79
- $this->meta[$meta_type . '_' . $type . '_' . $id][$name] = $data;
80
  }
81
  }
82
 
@@ -84,7 +89,7 @@ class Smart_Custom_Fields_Cache {
84
  * Getting the cache
85
  *
86
  * @param WP_Post|WP_User|WP_Term|stdClass $object
87
- * @param string $name
88
  * @return mixed
89
  */
90
  public function get_meta( $object, $name = null ) {
@@ -92,14 +97,14 @@ class Smart_Custom_Fields_Cache {
92
  $id = $Meta->get_id();
93
  $type = $Meta->get_type();
94
  $meta_type = $Meta->get_meta_type();
95
- if ( !empty( $id ) && !empty( $type ) && !empty( $meta_type ) ) {
96
  if ( is_null( $name ) ) {
97
- if ( isset( $this->meta[$meta_type . '_' . $type . '_' . $id] ) ) {
98
- return $this->meta[$meta_type . '_' . $type . '_' . $id];
99
  }
100
  } else {
101
- if ( isset( $this->meta[$meta_type . '_' . $type . '_' . $id][$name] ) ) {
102
- return $this->meta[$meta_type . '_' . $type . '_' . $id][$name];
103
  }
104
  }
105
  }
@@ -116,13 +121,13 @@ class Smart_Custom_Fields_Cache {
116
  * Saving to cache that enabled custom field settings in the post type or the role or the term.
117
  *
118
  * @param WP_Post|WP_User|WP_Term|stdClass $object
119
- * @param array $settings_posts
120
  */
121
  public function save_settings_posts( $object, $settings_posts ) {
122
  $Meta = new Smart_Custom_Fields_Meta( $object );
123
  $type = $Meta->get_type( false );
124
  $meta_type = $Meta->get_meta_type();
125
- $this->settings_posts[$meta_type . '_' . $type] = $settings_posts;
126
  }
127
 
128
  /**
@@ -135,8 +140,8 @@ class Smart_Custom_Fields_Cache {
135
  $Meta = new Smart_Custom_Fields_Meta( $object );
136
  $type = $Meta->get_type( false );
137
  $meta_type = $Meta->get_meta_type();
138
- if ( isset( $this->settings_posts[$meta_type . '_' . $type] ) ) {
139
- return $this->settings_posts[$meta_type . '_' . $type];
140
  }
141
  }
142
 
@@ -150,20 +155,20 @@ class Smart_Custom_Fields_Cache {
150
  /**
151
  * Saving the Setting object to cache
152
  *
153
- * @param int $settings_post_id
154
- * @param Smart_Custom_Fields_Setting $Setting
155
  * @param WP_Post|WP_User|WP_Term|stdClass $object
156
  */
157
  public function save_settings( $settings_post_id, $Setting, $object = null ) {
158
- if ( !is_null( $object ) ) {
159
  $Meta = new Smart_Custom_Fields_Meta( $object );
160
  $id = $Meta->get_id();
161
  $meta_type = $Meta->get_meta_type();
162
  }
163
- if ( !empty( $meta_type ) && !empty( $id ) ) {
164
- $this->settings[$settings_post_id][$meta_type . '_' . $id] = $Setting;
165
  } else {
166
- $this->settings[$settings_post_id][0] = $Setting;
167
  }
168
  }
169
 
@@ -176,21 +181,21 @@ class Smart_Custom_Fields_Cache {
176
  * There isn't a thing of the General ... false
177
  * If there the data for the specified $meta_type + $id ... Smart_Custom_Fields_Setting
178
  *
179
- * @param int $settings_post_id
180
  * @param WP_Post|WP_User|WP_Term|stdClass $object
181
  * @return Smart_Custom_Fields_Setting|false|null
182
  */
183
  public function get_settings( $settings_post_id, $object = null ) {
184
- if ( !is_null( $object ) ) {
185
  $Meta = new Smart_Custom_Fields_Meta( $object );
186
  $id = $Meta->get_id();
187
  $meta_type = $Meta->get_meta_type();
188
  }
189
 
190
- if ( isset( $this->settings[$settings_post_id] ) ) {
191
- $settings = $this->settings[$settings_post_id];
192
- if ( !empty( $id ) && !empty( $meta_type ) && isset( $settings[$meta_type . '_' . $id] ) ) {
193
- return $settings[$meta_type . '_' . $id];
194
  }
195
  if ( isset( $settings[0] ) ) {
196
  return $settings[0];
@@ -210,15 +215,15 @@ class Smart_Custom_Fields_Cache {
210
  * Saving the delimited identification data of the repeated multi-value items to cache
211
  *
212
  * @param WP_Post|WP_User|WP_Term|stdClass $object
213
- * @param mixed $repeat_multiple_data
214
  */
215
  public function save_repeat_multiple_data( $object, $repeat_multiple_data ) {
216
  $Meta = new Smart_Custom_Fields_Meta( $object );
217
  $id = $Meta->get_id();
218
  $type = $Meta->get_type();
219
  $meta_type = $Meta->get_meta_type();
220
- if ( !empty( $id ) && !empty( $type ) && !empty( $meta_type ) ) {
221
- $this->repeat_multiple_data[$meta_type . '_' . $type . '_' . $id] = $repeat_multiple_data;
222
  }
223
  }
224
 
@@ -233,9 +238,9 @@ class Smart_Custom_Fields_Cache {
233
  $id = $Meta->get_id();
234
  $type = $Meta->get_type();
235
  $meta_type = $Meta->get_meta_type();
236
- if ( !empty( $id ) && !empty( $type ) ) {
237
- if ( isset( $this->repeat_multiple_data[$meta_type . '_' . $type . '_' . $id] ) ) {
238
- return $this->repeat_multiple_data[$meta_type . '_' . $type . '_' . $id];
239
  }
240
  }
241
  }
12
 
13
  /**
14
  * Singleton instance
15
+ *
16
  * @var Smart_Custom_Fields_Cache
17
  */
18
  private static $instance;
20
  /**
21
  * Getting data proccesses is heavy. So saved getted data to $meta.
22
  * Using post_id as key.
23
+ *
24
  * @var array
25
  */
26
  protected $meta = array();
28
  /**
29
  * Getting data proccesses is heavy. So saved getted data to $settings_posts.
30
  * Using post_type as key.
31
+ *
32
  * @var array
33
  */
34
  protected $settings_posts = array();
36
  /**
37
  * Getting data proccesses is heavy. So saved getted data to $settings.
38
  * Using post_type as key.
39
+ *
40
  * @var array
41
  */
42
  protected $settings = array();
44
  /**
45
  * Getting data proccesses is heavy. So saved getted data to $repeat_multiple_data.
46
  * Using post_id as key.
47
+ *
48
  * @var array
49
  */
50
  protected $repeat_multiple_data = array();
52
  private function __construct() {}
53
 
54
  public static function getInstance() {
55
+ if ( ! self::$instance ) {
56
  self::$instance = new Smart_Custom_Fields_Cache();
57
  }
58
  return self::$instance;
72
  * Saving to cache
73
  *
74
  * @param WP_Post|WP_User|WP_Term|stdClass $object
75
+ * @param string $name
76
+ * @param mixed $data
77
  */
78
  public function save_meta( $object, $name, $data ) {
79
  $Meta = new Smart_Custom_Fields_Meta( $object );
80
  $id = $Meta->get_id();
81
  $type = $Meta->get_type();
82
  $meta_type = $Meta->get_meta_type();
83
+ if ( ! empty( $id ) && ! empty( $type ) && ! empty( $meta_type ) ) {
84
+ $this->meta[ $meta_type . '_' . $type . '_' . $id ][ $name ] = $data;
85
  }
86
  }
87
 
89
  * Getting the cache
90
  *
91
  * @param WP_Post|WP_User|WP_Term|stdClass $object
92
+ * @param string $name
93
  * @return mixed
94
  */
95
  public function get_meta( $object, $name = null ) {
97
  $id = $Meta->get_id();
98
  $type = $Meta->get_type();
99
  $meta_type = $Meta->get_meta_type();
100
+ if ( ! empty( $id ) && ! empty( $type ) && ! empty( $meta_type ) ) {
101
  if ( is_null( $name ) ) {
102
+ if ( isset( $this->meta[ $meta_type . '_' . $type . '_' . $id ] ) ) {
103
+ return $this->meta[ $meta_type . '_' . $type . '_' . $id ];
104
  }
105
  } else {
106
+ if ( isset( $this->meta[ $meta_type . '_' . $type . '_' . $id ][ $name ] ) ) {
107
+ return $this->meta[ $meta_type . '_' . $type . '_' . $id ][ $name ];
108
  }
109
  }
110
  }
121
  * Saving to cache that enabled custom field settings in the post type or the role or the term.
122
  *
123
  * @param WP_Post|WP_User|WP_Term|stdClass $object
124
+ * @param array $settings_posts
125
  */
126
  public function save_settings_posts( $object, $settings_posts ) {
127
  $Meta = new Smart_Custom_Fields_Meta( $object );
128
  $type = $Meta->get_type( false );
129
  $meta_type = $Meta->get_meta_type();
130
+ $this->settings_posts[ $meta_type . '_' . $type ] = $settings_posts;
131
  }
132
 
133
  /**
140
  $Meta = new Smart_Custom_Fields_Meta( $object );
141
  $type = $Meta->get_type( false );
142
  $meta_type = $Meta->get_meta_type();
143
+ if ( isset( $this->settings_posts[ $meta_type . '_' . $type ] ) ) {
144
+ return $this->settings_posts[ $meta_type . '_' . $type ];
145
  }
146
  }
147
 
155
  /**
156
  * Saving the Setting object to cache
157
  *
158
+ * @param int $settings_post_id
159
+ * @param Smart_Custom_Fields_Setting $Setting
160
  * @param WP_Post|WP_User|WP_Term|stdClass $object
161
  */
162
  public function save_settings( $settings_post_id, $Setting, $object = null ) {
163
+ if ( ! is_null( $object ) ) {
164
  $Meta = new Smart_Custom_Fields_Meta( $object );
165
  $id = $Meta->get_id();
166
  $meta_type = $Meta->get_meta_type();
167
  }
168
+ if ( ! empty( $meta_type ) && ! empty( $id ) ) {
169
+ $this->settings[ $settings_post_id ][ $meta_type . '_' . $id ] = $Setting;
170
  } else {
171
+ $this->settings[ $settings_post_id ][0] = $Setting;
172
  }
173
  }
174
 
181
  * There isn't a thing of the General ... false
182
  * If there the data for the specified $meta_type + $id ... Smart_Custom_Fields_Setting
183
  *
184
+ * @param int $settings_post_id
185
  * @param WP_Post|WP_User|WP_Term|stdClass $object
186
  * @return Smart_Custom_Fields_Setting|false|null
187
  */
188
  public function get_settings( $settings_post_id, $object = null ) {
189
+ if ( ! is_null( $object ) ) {
190
  $Meta = new Smart_Custom_Fields_Meta( $object );
191
  $id = $Meta->get_id();
192
  $meta_type = $Meta->get_meta_type();
193
  }
194
 
195
+ if ( isset( $this->settings[ $settings_post_id ] ) ) {
196
+ $settings = $this->settings[ $settings_post_id ];
197
+ if ( ! empty( $id ) && ! empty( $meta_type ) && isset( $settings[ $meta_type . '_' . $id ] ) ) {
198
+ return $settings[ $meta_type . '_' . $id ];
199
  }
200
  if ( isset( $settings[0] ) ) {
201
  return $settings[0];
215
  * Saving the delimited identification data of the repeated multi-value items to cache
216
  *
217
  * @param WP_Post|WP_User|WP_Term|stdClass $object
218
+ * @param mixed $repeat_multiple_data
219
  */
220
  public function save_repeat_multiple_data( $object, $repeat_multiple_data ) {
221
  $Meta = new Smart_Custom_Fields_Meta( $object );
222
  $id = $Meta->get_id();
223
  $type = $Meta->get_type();
224
  $meta_type = $Meta->get_meta_type();
225
+ if ( ! empty( $id ) && ! empty( $type ) && ! empty( $meta_type ) ) {
226
+ $this->repeat_multiple_data[ $meta_type . '_' . $type . '_' . $id ] = $repeat_multiple_data;
227
  }
228
  }
229
 
238
  $id = $Meta->get_id();
239
  $type = $Meta->get_type();
240
  $meta_type = $Meta->get_meta_type();
241
+ if ( ! empty( $id ) && ! empty( $type ) ) {
242
+ if ( isset( $this->repeat_multiple_data[ $meta_type . '_' . $type . '_' . $id ] ) ) {
243
+ return $this->repeat_multiple_data[ $meta_type . '_' . $type . '_' . $id ];
244
  }
245
  }
246
  }
classes/models/class.group.php CHANGED
@@ -12,18 +12,21 @@ class Smart_Custom_Fields_Group {
12
 
13
  /**
14
  * Group name
 
15
  * @var string
16
  */
17
  protected $name = null;
18
 
19
  /**
20
  * Array of field objects
 
21
  * @var array
22
  */
23
  protected $fields = array();
24
 
25
  /**
26
  * Whether repeating group
 
27
  * @var bool
28
  */
29
  protected $repeat = false;
@@ -32,24 +35,24 @@ class Smart_Custom_Fields_Group {
32
  * __construct
33
  *
34
  * @param string $group_name
35
- * @param bool $repeat
36
- * @param array $_fields
37
  */
38
  public function __construct( $group_name = null, $repeat = false, array $_fields = array() ) {
39
  $this->name = $group_name;
40
  $this->repeat = ( $repeat === true ) ? true : false;
41
- $fields = array();
42
  foreach ( $_fields as $field_attributes ) {
43
  $Field = SCF::get_form_field_instance( $field_attributes['type'] );
44
- if ( !is_a( $Field, 'Smart_Custom_Fields_Field_Base' ) ) {
45
  continue;
46
  }
47
  foreach ( $field_attributes as $key => $value ) {
48
  $Field->set( $key, $value );
49
  }
50
-
51
- if ( !empty( $Field ) ) {
52
- $fields[$Field->get( 'name' )] = $Field;
53
  }
54
  }
55
  $this->fields = $fields;
@@ -57,7 +60,7 @@ class Smart_Custom_Fields_Group {
57
 
58
  /**
59
  * Getting group name
60
- *
61
  * @return string
62
  */
63
  public function get_name() {
@@ -75,7 +78,7 @@ class Smart_Custom_Fields_Group {
75
  public function get_fields() {
76
  return $this->fields;
77
  }
78
-
79
  /**
80
  * Getting the field
81
  *
@@ -84,8 +87,8 @@ class Smart_Custom_Fields_Group {
84
  */
85
  public function get_field( $field_name ) {
86
  $fields = $this->get_fields();
87
- if ( isset( $fields[$field_name] ) ) {
88
- return $fields[$field_name];
89
  }
90
  }
91
 
@@ -100,18 +103,18 @@ class Smart_Custom_Fields_Group {
100
 
101
  /**
102
  * Displaying "hide" if $key isn't empty
103
- *
104
  * @param string $key
105
  */
106
  private function add_hide_class( $key ) {
107
- if ( !$key ) {
108
  echo 'hide';
109
  }
110
  }
111
 
112
  /**
113
  * Displaying the option fields in custom field settings page ( Common )
114
- *
115
  * @param int $group_key
116
  */
117
  public function display_options( $group_key ) {
12
 
13
  /**
14
  * Group name
15
+ *
16
  * @var string
17
  */
18
  protected $name = null;
19
 
20
  /**
21
  * Array of field objects
22
+ *
23
  * @var array
24
  */
25
  protected $fields = array();
26
 
27
  /**
28
  * Whether repeating group
29
+ *
30
  * @var bool
31
  */
32
  protected $repeat = false;
35
  * __construct
36
  *
37
  * @param string $group_name
38
+ * @param bool $repeat
39
+ * @param array $_fields
40
  */
41
  public function __construct( $group_name = null, $repeat = false, array $_fields = array() ) {
42
  $this->name = $group_name;
43
  $this->repeat = ( $repeat === true ) ? true : false;
44
+ $fields = array();
45
  foreach ( $_fields as $field_attributes ) {
46
  $Field = SCF::get_form_field_instance( $field_attributes['type'] );
47
+ if ( ! is_a( $Field, 'Smart_Custom_Fields_Field_Base' ) ) {
48
  continue;
49
  }
50
  foreach ( $field_attributes as $key => $value ) {
51
  $Field->set( $key, $value );
52
  }
53
+
54
+ if ( ! empty( $Field ) ) {
55
+ $fields[ $Field->get( 'name' ) ] = $Field;
56
  }
57
  }
58
  $this->fields = $fields;
60
 
61
  /**
62
  * Getting group name
63
+ *
64
  * @return string
65
  */
66
  public function get_name() {
78
  public function get_fields() {
79
  return $this->fields;
80
  }
81
+
82
  /**
83
  * Getting the field
84
  *
87
  */
88
  public function get_field( $field_name ) {
89
  $fields = $this->get_fields();
90
+ if ( isset( $fields[ $field_name ] ) ) {
91
+ return $fields[ $field_name ];
92
  }
93
  }
94
 
103
 
104
  /**
105
  * Displaying "hide" if $key isn't empty
106
+ *
107
  * @param string $key
108
  */
109
  private function add_hide_class( $key ) {
110
+ if ( ! $key ) {
111
  echo 'hide';
112
  }
113
  }
114
 
115
  /**
116
  * Displaying the option fields in custom field settings page ( Common )
117
+ *
118
  * @param int $group_key
119
  */
120
  public function display_options( $group_key ) {
classes/models/class.meta.php CHANGED
@@ -17,18 +17,21 @@ class Smart_Custom_Fields_Meta {
17
 
18
  /**
19
  * What meta data
 
20
  * @var string post or user or term or option
21
  */
22
  protected $meta_type = 'post';
23
 
24
  /**
25
  * Post ID or User ID or Term ID or Menu slug
 
26
  * @var int
27
  */
28
  protected $id;
29
 
30
  /**
31
  * Post Type or Role or Taxonomy or Menu slug
 
32
  * @var string
33
  * @deprecated
34
  */
@@ -36,6 +39,7 @@ class Smart_Custom_Fields_Meta {
36
 
37
  /**
38
  * Post Type or Roles or Taxonomy or Menu slug
 
39
  * @var array
40
  */
41
  protected $types = array();
@@ -46,36 +50,31 @@ class Smart_Custom_Fields_Meta {
46
  public function __construct( $object ) {
47
  $this->object = $object;
48
  if ( is_a( $object, 'WP_Post' ) ) {
49
- $this->id = $object->ID;
50
- $this->type = $object->post_type;
51
- $this->types = array( $object->post_type );
52
  $this->meta_type = 'post';
53
- }
54
- elseif ( is_a( $object, 'WP_User' ) ) {
55
- $this->id = $object->ID;
56
- $this->type = $object->roles[0];
57
- $this->types = array_unique( array_merge( $object->roles, array_keys( $object->caps ) ) );
58
  $this->meta_type = 'user';
59
- }
60
- elseif ( isset( $object->term_id ) ) {
61
- $this->id = $object->term_id;
62
- $this->type = $object->taxonomy;
63
- $this->types = array( $object->taxonomy );
64
  $this->meta_type = 'term';
65
- }
66
- elseif ( isset( $object->menu_slug ) ) {
67
- $this->id = $object->menu_slug;
68
- $this->type = $object->menu_slug;
69
- $this->types = array( $object->menu_slug );
70
  $this->meta_type = 'option';
71
- }
72
- elseif( empty( $object ) || is_wp_error( $object ) ) {
73
- $this->id = null;
74
- $this->type = null;
75
- $this->types = null;
76
  $this->meta_type = null;
77
- }
78
- else {
79
  throw new Exception( sprintf( 'Invalid $object type error. $object is "%s".', get_class( $object ) ) );
80
  }
81
  }
@@ -106,7 +105,7 @@ class Smart_Custom_Fields_Meta {
106
  * @return string
107
  */
108
  public function get_type( $accept_revision = true ) {
109
- if ( $this->meta_type === 'post' && !$accept_revision ) {
110
  $public_post_type = $this->get_public_post_type( $this->id );
111
  return $public_post_type[0];
112
  }
@@ -139,7 +138,7 @@ class Smart_Custom_Fields_Meta {
139
  } else {
140
  $post = get_post( $post_id );
141
  }
142
- if ( !empty( $post->post_type ) ) {
143
  return array( $post->post_type );
144
  }
145
  return $this->types;
@@ -158,7 +157,7 @@ class Smart_Custom_Fields_Meta {
158
  if ( $this->meta_type === 'post' && get_post_status( $this->get_id() ) === 'auto-draft' ) {
159
  return false;
160
  }
161
- if ( !$this->get() ) {
162
  return false;
163
  }
164
  return true;
@@ -175,7 +174,7 @@ class Smart_Custom_Fields_Meta {
175
  return false;
176
  }
177
 
178
- if ( _get_meta_table( $this->meta_type ) && !$this->maybe_4_3_term_meta() ) {
179
  return metadata_exists( $this->meta_type, $this->id, $key );
180
  }
181
 
@@ -194,7 +193,7 @@ class Smart_Custom_Fields_Meta {
194
  */
195
  public function maybe_4_3_term_meta() {
196
  if ( $this->meta_type == 'term' ) {
197
- if ( !get_metadata( $this->meta_type, $this->id ) && get_option( $this->get_option_name() ) ) {
198
  return true;
199
  }
200
  }
@@ -205,11 +204,11 @@ class Smart_Custom_Fields_Meta {
205
  * Getting the meta data
206
  *
207
  * @param string|null $key
208
- * @param bool $single false ... return array, true ... return string
209
  * @return string|array
210
  */
211
  public function get( $key = '', $single = false ) {
212
- if ( _get_meta_table( $this->meta_type ) && !$this->maybe_4_3_term_meta() ) {
213
  $meta = get_metadata( $this->meta_type, $this->id, $key, $single );
214
  } else {
215
  $meta = $this->get_option_metadata( $key, $single );
@@ -223,7 +222,7 @@ class Smart_Custom_Fields_Meta {
223
  if ( $key ) {
224
  foreach ( $settings as $Setting ) {
225
  $fields = $Setting->get_fields();
226
- if ( !empty( $fields[$key] ) ) {
227
  return $meta;
228
  }
229
  }
@@ -232,8 +231,8 @@ class Smart_Custom_Fields_Meta {
232
  foreach ( $settings as $Setting ) {
233
  $fields = $Setting->get_fields();
234
  foreach ( $meta as $meta_key => $meta_value ) {
235
- if ( isset( $fields[$meta_key] ) ) {
236
- $metas[$meta_key] = $meta[$meta_key];
237
  }
238
  }
239
  }
@@ -252,23 +251,23 @@ class Smart_Custom_Fields_Meta {
252
  * Getting option like meta data.
253
  *
254
  * @param string|null $key
255
- * @param bool $single false ... return array, true ... return string
256
  * @return string|array
257
  */
258
  protected function get_option_metadata( $key, $single ) {
259
  $option = get_option( $this->get_option_name() );
260
 
261
- if ( !$key ) {
262
  return $option;
263
  }
264
 
265
- if ( isset( $option[$key] ) ) {
266
- if ( $single && is_array( $option[$key] ) ) {
267
- if ( isset( $option[$key][0] ) ) {
268
- return $option[$key][0];
269
  }
270
  } else {
271
- return $option[$key];
272
  }
273
  }
274
 
@@ -282,8 +281,8 @@ class Smart_Custom_Fields_Meta {
282
  * Updating meta data. If the meta data not exist, adding it.
283
  *
284
  * @param string $key
285
- * @param mixed $value
286
- * @param mixed $prev_value If specified, it overwrites the only ones of this value
287
  * @return int|false Meta ID
288
  */
289
  public function update( $key, $value, $prev_value = '' ) {
@@ -305,28 +304,28 @@ class Smart_Custom_Fields_Meta {
305
  * Updating the option like meta data. If the meta data not exist, adding it.
306
  *
307
  * @param string $key
308
- * @param mixed $value
309
- * @param mixed $prev_value If specified, it overwrites the only ones of this value
310
  * @return bool
311
  */
312
  protected function update_option_metadata( $key, $value, $prev_value ) {
313
  $option_name = $this->get_option_name();
314
- $option = get_option( $option_name );
315
- if ( isset( $option[$key] ) ) {
316
  if ( $prev_value !== '' ) {
317
- foreach( $option[$key] as $option_key => $option_value ) {
318
  if ( $prev_value === $option_value ) {
319
- $option[$key][$option_key] = $value;
320
  break;
321
  }
322
  }
323
  } else {
324
- foreach( $option[$key] as $option_key => $option_value ) {
325
- $option[$key][$option_key] = $value;
326
  }
327
  }
328
  } else {
329
- $option[$key][] = $value;
330
  }
331
  $option = stripslashes_deep( $option );
332
  return update_option( $option_name, $option, false );
@@ -336,8 +335,8 @@ class Smart_Custom_Fields_Meta {
336
  * Adding the meta data
337
  *
338
  * @param string $key
339
- * @param mixed $value
340
- * @param bool $unique Whether the key to the unique
341
  * @return int|false Meta ID
342
  */
343
  public function add( $key, $value, $unique = false ) {
@@ -359,17 +358,17 @@ class Smart_Custom_Fields_Meta {
359
  * Adding the option like meta data
360
  *
361
  * @param string $key
362
- * @param mixed $value
363
- * @param bool $unique Whether the key to the unique
364
  * @return bool
365
  */
366
  protected function add_option_metadata( $key, $value, $unique ) {
367
  $option_name = $this->get_option_name();
368
- $option = get_option( $option_name );
369
- if ( !$unique || !isset( $option[$key] ) ) {
370
- $option[$key][] = $value;
371
- $option = stripslashes_deep( $option );
372
- $return = update_option( $option_name, $option, false );
373
  }
374
  return false;
375
  }
@@ -378,7 +377,7 @@ class Smart_Custom_Fields_Meta {
378
  * Deleting the meta data
379
  *
380
  * @param string $key
381
- * @param mixed $value If specified, it deletes the only ones of this value
382
  * @return bool
383
  */
384
  public function delete( $key = '', $value = '' ) {
@@ -398,22 +397,22 @@ class Smart_Custom_Fields_Meta {
398
  * Deleting the option like meta data
399
  *
400
  * @param string $key
401
- * @param mixed $value If specified, it deletes the only ones of this value
402
  * @return bool
403
  */
404
  protected function delete_option_metadata( $key, $value ) {
405
  $option_name = $this->get_option_name();
406
- $option = get_option( $option_name );
407
 
408
- if ( isset( $option[$key] ) && $value === '' ) {
409
- unset( $option[$key] );
410
  return update_option( $option_name, $option );
411
  }
412
 
413
- if ( isset( $option[$key] ) && $value !== '' ) {
414
- foreach ( $option[$key] as $option_key => $option_value ) {
415
  if ( $option_value === $value ) {
416
- unset( $option[$key][$option_key] );
417
  }
418
  }
419
  return update_option( $option_name, $option );
@@ -447,11 +446,11 @@ class Smart_Custom_Fields_Meta {
447
 
448
  $this->delete( SCF_Config::PREFIX . 'repeat-multiple-data' );
449
 
450
- if ( !isset( $POST[SCF_Config::NAME] ) ) {
451
  return;
452
  }
453
 
454
- $settings = SCF::get_settings( $this->object );
455
  $saved_data = array();
456
 
457
  foreach ( $settings as $Setting ) {
@@ -460,10 +459,10 @@ class Smart_Custom_Fields_Meta {
460
  $fields = $Group->get_fields();
461
  foreach ( $fields as $Field ) {
462
  $field_name = $Field->get( 'name' );
463
- if ( !isset( $POST[SCF_Config::NAME][$field_name] ) ) {
464
  continue;
465
  }
466
- $saved_data[$field_name] = $POST[SCF_Config::NAME][$field_name];
467
 
468
  $this->delete( $field_name );
469
  if ( $Field->get_attribute( 'allow-multiple-data' ) ) {
@@ -471,12 +470,12 @@ class Smart_Custom_Fields_Meta {
471
  }
472
 
473
  if ( $Group->is_repeatable() && $Field->get_attribute( 'allow-multiple-data' ) ) {
474
- $repeat_multiple_data_fields = $saved_data[$field_name];
475
  foreach ( $repeat_multiple_data_fields as $values ) {
476
  if ( is_array( $values ) ) {
477
- $repeat_multiple_data[$field_name][] = count( $values );
478
  } else {
479
- $repeat_multiple_data[$field_name][] = 0;
480
  }
481
  }
482
  }
@@ -493,7 +492,7 @@ class Smart_Custom_Fields_Meta {
493
  if ( in_array( $name, $multiple_data_fields ) && $value === '' ) {
494
  continue;
495
  }
496
- if ( !is_array( $value ) ) {
497
  $this->add( $name, $value );
498
  } else {
499
  foreach ( $value as $val ) {
@@ -510,7 +509,7 @@ class Smart_Custom_Fields_Meta {
510
  * @param WP_Post $revision
511
  */
512
  public function restore( $revision ) {
513
- if ( $this->meta_type !== 'post' || is_null( $this->object ) || !is_a( $revision, 'WP_Post' ) ) {
514
  return;
515
  }
516
 
@@ -540,7 +539,7 @@ class Smart_Custom_Fields_Meta {
540
  }
541
  }
542
 
543
- $repeat_multiple_data = SCF::get_repeat_multiple_data( $revision );
544
  $repeat_multiple_data_name = SCF_Config::PREFIX . 'repeat-multiple-data';
545
  $this->delete( $repeat_multiple_data_name );
546
  $this->update( $repeat_multiple_data_name, $repeat_multiple_data );
17
 
18
  /**
19
  * What meta data
20
+ *
21
  * @var string post or user or term or option
22
  */
23
  protected $meta_type = 'post';
24
 
25
  /**
26
  * Post ID or User ID or Term ID or Menu slug
27
+ *
28
  * @var int
29
  */
30
  protected $id;
31
 
32
  /**
33
  * Post Type or Role or Taxonomy or Menu slug
34
+ *
35
  * @var string
36
  * @deprecated
37
  */
39
 
40
  /**
41
  * Post Type or Roles or Taxonomy or Menu slug
42
+ *
43
  * @var array
44
  */
45
  protected $types = array();
50
  public function __construct( $object ) {
51
  $this->object = $object;
52
  if ( is_a( $object, 'WP_Post' ) ) {
53
+ $this->id = $object->ID;
54
+ $this->type = $object->post_type;
55
+ $this->types = array( $object->post_type );
56
  $this->meta_type = 'post';
57
+ } elseif ( is_a( $object, 'WP_User' ) ) {
58
+ $this->id = $object->ID;
59
+ $this->type = $object->roles[0];
60
+ $this->types = array_unique( array_merge( $object->roles, array_keys( $object->caps ) ) );
 
61
  $this->meta_type = 'user';
62
+ } elseif ( isset( $object->term_id ) ) {
63
+ $this->id = $object->term_id;
64
+ $this->type = $object->taxonomy;
65
+ $this->types = array( $object->taxonomy );
 
66
  $this->meta_type = 'term';
67
+ } elseif ( isset( $object->menu_slug ) ) {
68
+ $this->id = $object->menu_slug;
69
+ $this->type = $object->menu_slug;
70
+ $this->types = array( $object->menu_slug );
 
71
  $this->meta_type = 'option';
72
+ } elseif ( empty( $object ) || is_wp_error( $object ) ) {
73
+ $this->id = null;
74
+ $this->type = null;
75
+ $this->types = null;
 
76
  $this->meta_type = null;
77
+ } else {
 
78
  throw new Exception( sprintf( 'Invalid $object type error. $object is "%s".', get_class( $object ) ) );
79
  }
80
  }
105
  * @return string
106
  */
107
  public function get_type( $accept_revision = true ) {
108
+ if ( $this->meta_type === 'post' && ! $accept_revision ) {
109
  $public_post_type = $this->get_public_post_type( $this->id );
110
  return $public_post_type[0];
111
  }
138
  } else {
139
  $post = get_post( $post_id );
140
  }
141
+ if ( ! empty( $post->post_type ) ) {
142
  return array( $post->post_type );
143
  }
144
  return $this->types;
157
  if ( $this->meta_type === 'post' && get_post_status( $this->get_id() ) === 'auto-draft' ) {
158
  return false;
159
  }
160
+ if ( ! $this->get() ) {
161
  return false;
162
  }
163
  return true;
174
  return false;
175
  }
176
 
177
+ if ( _get_meta_table( $this->meta_type ) && ! $this->maybe_4_3_term_meta() ) {
178
  return metadata_exists( $this->meta_type, $this->id, $key );
179
  }
180
 
193
  */
194
  public function maybe_4_3_term_meta() {
195
  if ( $this->meta_type == 'term' ) {
196
+ if ( ! get_metadata( $this->meta_type, $this->id ) && get_option( $this->get_option_name() ) ) {
197
  return true;
198
  }
199
  }
204
  * Getting the meta data
205
  *
206
  * @param string|null $key
207
+ * @param bool $single false ... return array, true ... return string
208
  * @return string|array
209
  */
210
  public function get( $key = '', $single = false ) {
211
+ if ( _get_meta_table( $this->meta_type ) && ! $this->maybe_4_3_term_meta() ) {
212
  $meta = get_metadata( $this->meta_type, $this->id, $key, $single );
213
  } else {
214
  $meta = $this->get_option_metadata( $key, $single );
222
  if ( $key ) {
223
  foreach ( $settings as $Setting ) {
224
  $fields = $Setting->get_fields();
225
+ if ( ! empty( $fields[ $key ] ) ) {
226
  return $meta;
227
  }
228
  }
231
  foreach ( $settings as $Setting ) {
232
  $fields = $Setting->get_fields();
233
  foreach ( $meta as $meta_key => $meta_value ) {
234
+ if ( isset( $fields[ $meta_key ] ) ) {
235
+ $metas[ $meta_key ] = $meta[ $meta_key ];
236
  }
237
  }
238
  }
251
  * Getting option like meta data.
252
  *
253
  * @param string|null $key
254
+ * @param bool $single false ... return array, true ... return string
255
  * @return string|array
256
  */
257
  protected function get_option_metadata( $key, $single ) {
258
  $option = get_option( $this->get_option_name() );
259
 
260
+ if ( ! $key ) {
261
  return $option;
262
  }
263
 
264
+ if ( isset( $option[ $key ] ) ) {
265
+ if ( $single && is_array( $option[ $key ] ) ) {
266
+ if ( isset( $option[ $key ][0] ) ) {
267
+ return $option[ $key ][0];
268
  }
269
  } else {
270
+ return $option[ $key ];
271
  }
272
  }
273
 
281
  * Updating meta data. If the meta data not exist, adding it.
282
  *
283
  * @param string $key
284
+ * @param mixed $value
285
+ * @param mixed $prev_value If specified, it overwrites the only ones of this value
286
  * @return int|false Meta ID
287
  */
288
  public function update( $key, $value, $prev_value = '' ) {
304
  * Updating the option like meta data. If the meta data not exist, adding it.
305
  *
306
  * @param string $key
307
+ * @param mixed $value
308
+ * @param mixed $prev_value If specified, it overwrites the only ones of this value
309
  * @return bool
310
  */
311
  protected function update_option_metadata( $key, $value, $prev_value ) {
312
  $option_name = $this->get_option_name();
313
+ $option = get_option( $option_name );
314
+ if ( isset( $option[ $key ] ) ) {
315
  if ( $prev_value !== '' ) {
316
+ foreach ( $option[ $key ] as $option_key => $option_value ) {
317
  if ( $prev_value === $option_value ) {
318
+ $option[ $key ][ $option_key ] = $value;
319
  break;
320
  }
321
  }
322
  } else {
323
+ foreach ( $option[ $key ] as $option_key => $option_value ) {
324
+ $option[ $key ][ $option_key ] = $value;
325
  }
326
  }
327
  } else {
328
+ $option[ $key ][] = $value;
329
  }
330
  $option = stripslashes_deep( $option );
331
  return update_option( $option_name, $option, false );
335
  * Adding the meta data
336
  *
337
  * @param string $key
338
+ * @param mixed $value
339
+ * @param bool $unique Whether the key to the unique
340
  * @return int|false Meta ID
341
  */
342
  public function add( $key, $value, $unique = false ) {
358
  * Adding the option like meta data
359
  *
360
  * @param string $key
361
+ * @param mixed $value
362
+ * @param bool $unique Whether the key to the unique
363
  * @return bool
364
  */
365
  protected function add_option_metadata( $key, $value, $unique ) {
366
  $option_name = $this->get_option_name();
367
+ $option = get_option( $option_name );
368
+ if ( ! $unique || ! isset( $option[ $key ] ) ) {
369
+ $option[ $key ][] = $value;
370
+ $option = stripslashes_deep( $option );
371
+ $return = update_option( $option_name, $option, false );
372
  }
373
  return false;
374
  }
377
  * Deleting the meta data
378
  *
379
  * @param string $key
380
+ * @param mixed $value If specified, it deletes the only ones of this value
381
  * @return bool
382
  */
383
  public function delete( $key = '', $value = '' ) {
397
  * Deleting the option like meta data
398
  *
399
  * @param string $key
400
+ * @param mixed $value If specified, it deletes the only ones of this value
401
  * @return bool
402
  */
403
  protected function delete_option_metadata( $key, $value ) {
404
  $option_name = $this->get_option_name();
405
+ $option = get_option( $option_name );
406
 
407
+ if ( isset( $option[ $key ] ) && $value === '' ) {
408
+ unset( $option[ $key ] );
409
  return update_option( $option_name, $option );
410
  }
411
 
412
+ if ( isset( $option[ $key ] ) && $value !== '' ) {
413
+ foreach ( $option[ $key ] as $option_key => $option_value ) {
414
  if ( $option_value === $value ) {
415
+ unset( $option[ $key ][ $option_key ] );
416
  }
417
  }
418
  return update_option( $option_name, $option );
446
 
447
  $this->delete( SCF_Config::PREFIX . 'repeat-multiple-data' );
448
 
449
+ if ( ! isset( $POST[ SCF_Config::NAME ] ) ) {
450
  return;
451
  }
452
 
453
+ $settings = SCF::get_settings( $this->object );
454
  $saved_data = array();
455
 
456
  foreach ( $settings as $Setting ) {
459
  $fields = $Group->get_fields();
460
  foreach ( $fields as $Field ) {
461
  $field_name = $Field->get( 'name' );
462
+ if ( ! isset( $POST[ SCF_Config::NAME ][ $field_name ] ) ) {
463
  continue;
464
  }
465
+ $saved_data[ $field_name ] = $POST[ SCF_Config::NAME ][ $field_name ];
466
 
467
  $this->delete( $field_name );
468
  if ( $Field->get_attribute( 'allow-multiple-data' ) ) {
470
  }
471
 
472
  if ( $Group->is_repeatable() && $Field->get_attribute( 'allow-multiple-data' ) ) {
473
+ $repeat_multiple_data_fields = $saved_data[ $field_name ];
474
  foreach ( $repeat_multiple_data_fields as $values ) {
475
  if ( is_array( $values ) ) {
476
+ $repeat_multiple_data[ $field_name ][] = count( $values );
477
  } else {
478
+ $repeat_multiple_data[ $field_name ][] = 0;
479
  }
480
  }
481
  }
492
  if ( in_array( $name, $multiple_data_fields ) && $value === '' ) {
493
  continue;
494
  }
495
+ if ( ! is_array( $value ) ) {
496
  $this->add( $name, $value );
497
  } else {
498
  foreach ( $value as $val ) {
509
  * @param WP_Post $revision
510
  */
511
  public function restore( $revision ) {
512
+ if ( $this->meta_type !== 'post' || is_null( $this->object ) || ! is_a( $revision, 'WP_Post' ) ) {
513
  return;
514
  }
515
 
539
  }
540
  }
541
 
542
+ $repeat_multiple_data = SCF::get_repeat_multiple_data( $revision );
543
  $repeat_multiple_data_name = SCF_Config::PREFIX . 'repeat-multiple-data';
544
  $this->delete( $repeat_multiple_data_name );
545
  $this->update( $repeat_multiple_data_name, $repeat_multiple_data );
classes/models/class.options-page.php CHANGED
@@ -47,7 +47,7 @@ class Smart_Custom_Fields_Options_Page {
47
  * @param string $capability
48
  * @param string $menu_slug
49
  * @param string $icon_url
50
- * @param int $position
51
  */
52
  public function __construct( $page_title, $menu_title, $capability, $menu_slug, $icon_url = '', $position = null ) {
53
  $this->page_title = $page_title;
@@ -73,7 +73,7 @@ class Smart_Custom_Fields_Options_Page {
73
 
74
  public function display() {
75
  $Option = SCF::generate_option_object( $_GET['page'] );
76
- if ( !$Option ) {
77
  return;
78
  }
79
  ?>
47
  * @param string $capability
48
  * @param string $menu_slug
49
  * @param string $icon_url
50
+ * @param int $position
51
  */
52
  public function __construct( $page_title, $menu_title, $capability, $menu_slug, $icon_url = '', $position = null ) {
53
  $this->page_title = $page_title;
73
 
74
  public function display() {
75
  $Option = SCF::generate_option_object( $_GET['page'] );
76
+ if ( ! $Option ) {
77
  return;
78
  }
79
  ?>
classes/models/class.revisions.php CHANGED
@@ -27,10 +27,10 @@ class Smart_Custom_Fields_Revisions {
27
  3
28
  );
29
  add_filter( '_wp_post_revision_fields', array( $this, '_wp_post_revision_fields' ) );
30
- add_filter( 'get_post_metadata' , array( $this, 'get_post_metadata' ), 10, 4 );
31
- add_action( 'edit_form_after_title' , array( $this, 'edit_form_after_title' ) );
32
  add_action( 'wp_restore_post_revision', array( $this, 'wp_restore_post_revision' ), 10, 2 );
33
- add_action( 'wp_insert_post' , array( $this, 'wp_insert_post' ) );
34
  }
35
 
36
  /**
@@ -54,14 +54,14 @@ class Smart_Custom_Fields_Revisions {
54
  * @param int $post_id リビジョンの投稿ID
55
  */
56
  public function wp_insert_post( $post_id ) {
57
- if ( !isset( $_POST[SCF_Config::NAME] ) ) {
58
  return;
59
  }
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
  }
67
 
@@ -77,10 +77,10 @@ class Smart_Custom_Fields_Revisions {
77
  /**
78
  * プレビューのときはプレビューのメタデータを返す。ただし、アイキャッチはリビジョンが無いので除外する
79
  *
80
- * @param mixed $value
81
- * @param int $post_id
82
  * @param string $meta_key
83
- * @param bool $single
84
  * @return mixed $value
85
  */
86
  public function get_post_metadata( $value, $post_id, $meta_key, $single ) {
@@ -124,8 +124,8 @@ class Smart_Custom_Fields_Revisions {
124
  * @param array $fields
125
  * @return array $fields
126
  */
127
- public function _wp_post_revision_fields( $fields ){
128
- $fields[SCF_Config::PREFIX . 'debug-preview'] = esc_html__( 'Smart Custom Fields', 'smart-custom-fields' );
129
  return $fields;
130
  }
131
 
@@ -144,7 +144,7 @@ class Smart_Custom_Fields_Revisions {
144
  *
145
  * @param $value
146
  * @param $column
147
- * @param array $post
148
  * @return string
149
  */
150
  public function _wp_post_revision_field_debug_preview( $value, $column, $post ) {
@@ -157,7 +157,7 @@ class Smart_Custom_Fields_Revisions {
157
  foreach ( $value as $i => $repeat_data_values ) {
158
  $output .= sprintf( "- #%s\n", $i );
159
  foreach ( $repeat_data_values as $field_name => $repeat_data_value ) {
160
- $output .= sprintf( " %s: ", $field_name );
161
  if ( is_array( $repeat_data_value ) ) {
162
  $output .= sprintf( "[%s]\n", implode( ', ', $repeat_data_value ) );
163
  } else {
@@ -178,24 +178,24 @@ class Smart_Custom_Fields_Revisions {
178
  /**
179
  * false ならリビジョンとして保存される
180
  *
181
- * @param bool $check_for_changes
182
  * @param WP_Post $last_revision 最新のリビジョン
183
  * @param WP_Post $post 現在の投稿
184
  * @return bool
185
  */
186
  public function wp_save_post_revision_check_for_changes( $check_for_changes, $last_revision, $post ) {
187
  $post_meta = array();
188
- $p = get_post_custom( $post->ID );
189
  foreach ( $p as $key => $value ) {
190
  $v = SCF::get( $key );
191
- if ( !is_null( $v ) ) {
192
- $post_meta[$key][] = $v;
193
  }
194
  }
195
 
196
- if ( isset( $_POST[SCF_Config::NAME] ) ) {
197
  $serialized_post_meta = serialize( $post_meta );
198
- $serialized_send_data = $_POST[SCF_Config::NAME];
199
  if ( $serialized_post_meta != $serialized_send_data ) {
200
  return false;
201
  }
27
  3
28
  );
29
  add_filter( '_wp_post_revision_fields', array( $this, '_wp_post_revision_fields' ) );
30
+ add_filter( 'get_post_metadata', array( $this, 'get_post_metadata' ), 10, 4 );
31
+ add_action( 'edit_form_after_title', array( $this, 'edit_form_after_title' ) );
32
  add_action( 'wp_restore_post_revision', array( $this, 'wp_restore_post_revision' ), 10, 2 );
33
+ add_action( 'wp_insert_post', array( $this, 'wp_insert_post' ) );
34
  }
35
 
36
  /**
54
  * @param int $post_id リビジョンの投稿ID
55
  */
56
  public function wp_insert_post( $post_id ) {
57
+ if ( ! isset( $_POST[ SCF_Config::NAME ] ) ) {
58
  return;
59
  }
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
  }
67
 
77
  /**
78
  * プレビューのときはプレビューのメタデータを返す。ただし、アイキャッチはリビジョンが無いので除外する
79
  *
80
+ * @param mixed $value
81
+ * @param int $post_id
82
  * @param string $meta_key
83
+ * @param bool $single
84
  * @return mixed $value
85
  */
86
  public function get_post_metadata( $value, $post_id, $meta_key, $single ) {
124
  * @param array $fields
125
  * @return array $fields
126
  */
127
+ public function _wp_post_revision_fields( $fields ) {
128
+ $fields[ SCF_Config::PREFIX . 'debug-preview' ] = esc_html__( 'Smart Custom Fields', 'smart-custom-fields' );
129
  return $fields;
130
  }
131
 
144
  *
145
  * @param $value
146
  * @param $column
147
+ * @param array $post
148
  * @return string
149
  */
150
  public function _wp_post_revision_field_debug_preview( $value, $column, $post ) {
157
  foreach ( $value as $i => $repeat_data_values ) {
158
  $output .= sprintf( "- #%s\n", $i );
159
  foreach ( $repeat_data_values as $field_name => $repeat_data_value ) {
160
+ $output .= sprintf( ' %s: ', $field_name );
161
  if ( is_array( $repeat_data_value ) ) {
162
  $output .= sprintf( "[%s]\n", implode( ', ', $repeat_data_value ) );
163
  } else {
178
  /**
179
  * false ならリビジョンとして保存される
180
  *
181
+ * @param bool $check_for_changes
182
  * @param WP_Post $last_revision 最新のリビジョン
183
  * @param WP_Post $post 現在の投稿
184
  * @return bool
185
  */
186
  public function wp_save_post_revision_check_for_changes( $check_for_changes, $last_revision, $post ) {
187
  $post_meta = array();
188
+ $p = get_post_custom( $post->ID );
189
  foreach ( $p as $key => $value ) {
190
  $v = SCF::get( $key );
191
+ if ( ! is_null( $v ) ) {
192
+ $post_meta[ $key ][] = $v;
193
  }
194
  }
195
 
196
+ if ( isset( $_POST[ SCF_Config::NAME ] ) ) {
197
  $serialized_post_meta = serialize( $post_meta );
198
+ $serialized_send_data = $_POST[ SCF_Config::NAME ];
199
  if ( $serialized_post_meta != $serialized_send_data ) {
200
  return false;
201
  }
classes/models/class.setting.php CHANGED
@@ -12,42 +12,48 @@ class Smart_Custom_Fields_Setting {
12
 
13
  /**
14
  * Post ID of custom field settings page
 
15
  * @var string
16
  */
17
  protected $id;
18
 
19
  /**
20
  * Title of custom field settings page
 
21
  * @var title
22
  */
23
  protected $title;
24
 
25
  /**
26
  * Array of the saved group objects
 
27
  * @var array
28
  */
29
  protected $groups = array();
30
 
31
  /**
32
  * __construct
33
- *
34
  * @param int $post_id
35
  */
36
  public function __construct( $id, $title ) {
37
  $this->id = $id;
38
  $this->title = $title;
39
- $post_meta = get_post_meta(
40
  $this->get_id(),
41
  SCF_Config::PREFIX . 'setting',
42
  true
43
  );
44
  if ( is_array( $post_meta ) ) {
45
  foreach ( $post_meta as $group ) {
46
- $group = shortcode_atts( array(
47
- 'group-name' => '',
48
- 'repeat' => false,
49
- 'fields' => array(),
50
- ), $group );
 
 
 
51
  $this->add_group(
52
  $group['group-name'],
53
  $group['repeat'],
@@ -59,7 +65,7 @@ class Smart_Custom_Fields_Setting {
59
 
60
  /**
61
  * Getting the post ID
62
- *
63
  * @return string
64
  */
65
  public function get_id() {
@@ -77,13 +83,13 @@ class Smart_Custom_Fields_Setting {
77
 
78
  /**
79
  * Getting the group objects
80
- *
81
  * @return array
82
  */
83
  public function get_groups() {
84
  return $this->groups;
85
  }
86
-
87
  /**
88
  * Getting together the fields in each group
89
  *
@@ -101,21 +107,21 @@ class Smart_Custom_Fields_Setting {
101
  /**
102
  * Adding group to the tail
103
  * If the argument is not, adding an empty group
104
- *
105
  * @param string $group_name
106
- * @param bool $repeat
107
- * @param array $_fields
108
  */
109
  public function add_group( $group_name = null, $repeat = false, array $fields = array() ) {
110
- $Group = $this->new_group( $group_name, $repeat, $fields );
111
  $group_name = $Group->get_name();
112
  if ( $group_name ) {
113
- $this->groups[$group_name] = $Group;
114
  } else {
115
  $this->groups[] = $Group;
116
  }
117
  }
118
-
119
  /**
120
  * Getting group
121
  *
@@ -124,8 +130,8 @@ class Smart_Custom_Fields_Setting {
124
  */
125
  public function get_group( $group_name ) {
126
  $groups = $this->get_groups();
127
- if ( isset( $groups[$group_name] ) && $groups[$group_name]->is_repeatable() ) {
128
- return $groups[$group_name];
129
  }
130
  }
131
 
@@ -134,8 +140,8 @@ class Smart_Custom_Fields_Setting {
134
  * If the argument is not, adding an empty group
135
  *
136
  * @param string $group_name
137
- * @param bool $repeat
138
- * @param array $_fields
139
  */
140
  public function add_group_unshift( $group_name = null, $repeat = false, array $fields = array() ) {
141
  $Group = $this->new_group( $group_name, $repeat, $fields );
@@ -144,10 +150,10 @@ class Smart_Custom_Fields_Setting {
144
 
145
  /**
146
  * Getting generated new group
147
- *
148
  * @param string $group_name
149
- * @param bool $repeat
150
- * @param array $_fields
151
  */
152
  protected function new_group( $group_name, $repeat, $fields ) {
153
  return new Smart_Custom_Fields_Group( $group_name, $repeat, $fields );
12
 
13
  /**
14
  * Post ID of custom field settings page
15
+ *
16
  * @var string
17
  */
18
  protected $id;
19
 
20
  /**
21
  * Title of custom field settings page
22
+ *
23
  * @var title
24
  */
25
  protected $title;
26
 
27
  /**
28
  * Array of the saved group objects
29
+ *
30
  * @var array
31
  */
32
  protected $groups = array();
33
 
34
  /**
35
  * __construct
36
+ *
37
  * @param int $post_id
38
  */
39
  public function __construct( $id, $title ) {
40
  $this->id = $id;
41
  $this->title = $title;
42
+ $post_meta = get_post_meta(
43
  $this->get_id(),
44
  SCF_Config::PREFIX . 'setting',
45
  true
46
  );
47
  if ( is_array( $post_meta ) ) {
48
  foreach ( $post_meta as $group ) {
49
+ $group = shortcode_atts(
50
+ array(
51
+ 'group-name' => '',
52
+ 'repeat' => false,
53
+ 'fields' => array(),
54
+ ),
55
+ $group
56
+ );
57
  $this->add_group(
58
  $group['group-name'],
59
  $group['repeat'],
65
 
66
  /**
67
  * Getting the post ID
68
+ *
69
  * @return string
70
  */
71
  public function get_id() {
83
 
84
  /**
85
  * Getting the group objects
86
+ *
87
  * @return array
88
  */
89
  public function get_groups() {
90
  return $this->groups;
91
  }
92
+
93
  /**
94
  * Getting together the fields in each group
95
  *
107
  /**
108
  * Adding group to the tail
109
  * If the argument is not, adding an empty group
110
+ *
111
  * @param string $group_name
112
+ * @param bool $repeat
113
+ * @param array $_fields
114
  */
115
  public function add_group( $group_name = null, $repeat = false, array $fields = array() ) {
116
+ $Group = $this->new_group( $group_name, $repeat, $fields );
117
  $group_name = $Group->get_name();
118
  if ( $group_name ) {
119
+ $this->groups[ $group_name ] = $Group;
120
  } else {
121
  $this->groups[] = $Group;
122
  }
123
  }
124
+
125
  /**
126
  * Getting group
127
  *
130
  */
131
  public function get_group( $group_name ) {
132
  $groups = $this->get_groups();
133
+ if ( isset( $groups[ $group_name ] ) && $groups[ $group_name ]->is_repeatable() ) {
134
+ return $groups[ $group_name ];
135
  }
136
  }
137
 
140
  * If the argument is not, adding an empty group
141
  *
142
  * @param string $group_name
143
+ * @param bool $repeat
144
+ * @param array $_fields
145
  */
146
  public function add_group_unshift( $group_name = null, $repeat = false, array $fields = array() ) {
147
  $Group = $this->new_group( $group_name, $repeat, $fields );
150
 
151
  /**
152
  * Getting generated new group
153
+ *
154
  * @param string $group_name
155
+ * @param bool $repeat
156
+ * @param array $_fields
157
  */
158
  protected function new_group( $group_name, $repeat, $fields ) {
159
  return new Smart_Custom_Fields_Group( $group_name, $repeat, $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.9.8
7
- Stable tag: 4.1.0
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -129,6 +129,9 @@ You can translate this plugin into your language by using [GlotPress](https://tr
129
 
130
  == Changelog ==
131
 
 
 
 
132
  = 4.1.0 =
133
  * feat: Implement new field datetime picker
134
  * feat: Add filters for related posts fields with name and post types
4
  Tags: plugin, custom field, custom, field, meta, meta field, repeat, repeatable
5
  Requires at least: 3.9
6
  Tested up to: 4.9.8
7
+ Stable tag: 4.1.2
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
129
 
130
  == Changelog ==
131
 
132
+ = 4.1.2 =
133
+ * Fix PHP syntax error.
134
+
135
  = 4.1.0 =
136
  * feat: Implement new field datetime picker
137
  * feat: Add filters for related posts fields with name and post types
smart-custom-fields.php CHANGED
@@ -3,7 +3,7 @@
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: 4.1.0
7
  * Author: inc2734
8
  * Author URI: https://2inc.org
9
  * Text Domain: smart-custom-fields
@@ -29,7 +29,7 @@ class Smart_Custom_Fields {
29
  * Loading translation files
30
  */
31
  public function plugins_loaded() {
32
- load_plugin_textdomain (
33
  'smart-custom-fields',
34
  false,
35
  dirname( plugin_basename( __FILE__ ) ) . '/languages'
@@ -63,10 +63,10 @@ class Smart_Custom_Fields {
63
  }
64
 
65
  add_action( 'after_setup_theme', array( $this, 'after_setup_theme' ) );
66
- add_action( 'init' , array( $this, 'register_post_type' ) );
67
- add_action( 'init' , array( $this, 'ajax_request' ) );
68
- add_action( 'admin_menu' , array( $this, 'admin_menu' ) );
69
- add_action( 'current_screen' , array( $this, 'current_screen' ) );
70
  }
71
 
72
  /**
@@ -81,11 +81,13 @@ class Smart_Custom_Fields {
81
  * Uninstall proccesses
82
  */
83
  public static function uninstall() {
84
- $cf_posts = get_posts( array(
85
- 'post_type' => SCF_Config::NAME,
86
- 'posts_per_page' => -1,
87
- 'post_status' => 'any',
88
- ) );
 
 
89
  foreach ( $cf_posts as $post ) {
90
  wp_delete_post( $post->ID, true );
91
  }
@@ -151,7 +153,7 @@ class Smart_Custom_Fields {
151
  }
152
  // オプションページ
153
  else {
154
- $menu_slug = preg_replace( '/^toplevel_page_(.+)$/', '$1', $screen->id );
155
  $options_pages = SCF::get_options_pages();
156
 
157
  if ( array_key_exists( $menu_slug, $options_pages ) ) {
@@ -183,7 +185,7 @@ class Smart_Custom_Fields {
183
  'search_items' => __( 'Search Fields', 'smart-custom-fields' ),
184
  'parent_item_colon' => __( 'Parent Fields:', 'smart-custom-fields' ),
185
  'not_found' => __( 'No Fields found.', 'smart-custom-fields' ),
186
- 'not_found_in_trash' => __( 'No Fields found in Trash.', 'smart-custom-fields' )
187
  );
188
  register_post_type(
189
  SCF_Config::NAME,
@@ -235,9 +237,9 @@ class Smart_Custom_Fields {
235
  */
236
  protected function get_post_id_in_admin() {
237
  $post_id = false;
238
- if ( !empty( $_GET['post'] ) ) {
239
  $post_id = $_GET['post'];
240
- } elseif ( !empty( $_POST['post_ID'] ) ) {
241
  $post_id = $_POST['post_ID'];
242
  }
243
  return $post_id;
@@ -249,11 +251,11 @@ class Smart_Custom_Fields {
249
  * @return int
250
  */
251
  protected function get_user_id_in_admin() {
252
- $screen = get_current_screen();
253
  $user_id = false;
254
- if ( !empty( $_GET['user_id'] ) ) {
255
  $user_id = $_GET['user_id'];
256
- } elseif ( !empty( $_POST['user_id'] ) ) {
257
  $user_id = $_POST['user_id'];
258
  } elseif ( $screen->id === 'profile' ) {
259
  $current_user = wp_get_current_user();
@@ -269,9 +271,9 @@ class Smart_Custom_Fields {
269
  */
270
  protected function get_term_id_in_admin() {
271
  $term_id = false;
272
- if ( !empty( $_GET['tag_ID'] ) ) {
273
  $term_id = $_GET['tag_ID'];
274
- } elseif ( !empty( $_POST['tag_ID'] ) ) {
275
  $term_id = $_POST['tag_ID'];
276
  }
277
  return $term_id;
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: 4.1.2
7
  * Author: inc2734
8
  * Author URI: https://2inc.org
9
  * Text Domain: smart-custom-fields
29
  * Loading translation files
30
  */
31
  public function plugins_loaded() {
32
+ load_plugin_textdomain(
33
  'smart-custom-fields',
34
  false,
35
  dirname( plugin_basename( __FILE__ ) ) . '/languages'
63
  }
64
 
65
  add_action( 'after_setup_theme', array( $this, 'after_setup_theme' ) );
66
+ add_action( 'init', array( $this, 'register_post_type' ) );
67
+ add_action( 'init', array( $this, 'ajax_request' ) );
68
+ add_action( 'admin_menu', array( $this, 'admin_menu' ) );
69
+ add_action( 'current_screen', array( $this, 'current_screen' ) );
70
  }
71
 
72
  /**
81
  * Uninstall proccesses
82
  */
83
  public static function uninstall() {
84
+ $cf_posts = get_posts(
85
+ array(
86
+ 'post_type' => SCF_Config::NAME,
87
+ 'posts_per_page' => -1,
88
+ 'post_status' => 'any',
89
+ )
90
+ );
91
  foreach ( $cf_posts as $post ) {
92
  wp_delete_post( $post->ID, true );
93
  }
153
  }
154
  // オプションページ
155
  else {
156
+ $menu_slug = preg_replace( '/^toplevel_page_(.+)$/', '$1', $screen->id );
157
  $options_pages = SCF::get_options_pages();
158
 
159
  if ( array_key_exists( $menu_slug, $options_pages ) ) {
185
  'search_items' => __( 'Search Fields', 'smart-custom-fields' ),
186
  'parent_item_colon' => __( 'Parent Fields:', 'smart-custom-fields' ),
187
  'not_found' => __( 'No Fields found.', 'smart-custom-fields' ),
188
+ 'not_found_in_trash' => __( 'No Fields found in Trash.', 'smart-custom-fields' ),
189
  );
190
  register_post_type(
191
  SCF_Config::NAME,
237
  */
238
  protected function get_post_id_in_admin() {
239
  $post_id = false;
240
+ if ( ! empty( $_GET['post'] ) ) {
241
  $post_id = $_GET['post'];
242
+ } elseif ( ! empty( $_POST['post_ID'] ) ) {
243
  $post_id = $_POST['post_ID'];
244
  }
245
  return $post_id;
251
  * @return int
252
  */
253
  protected function get_user_id_in_admin() {
254
+ $screen = get_current_screen();
255
  $user_id = false;
256
+ if ( ! empty( $_GET['user_id'] ) ) {
257
  $user_id = $_GET['user_id'];
258
+ } elseif ( ! empty( $_POST['user_id'] ) ) {
259
  $user_id = $_POST['user_id'];
260
  } elseif ( $screen->id === 'profile' ) {
261
  $current_user = wp_get_current_user();
271
  */
272
  protected function get_term_id_in_admin() {
273
  $term_id = false;
274
+ if ( ! empty( $_GET['tag_ID'] ) ) {
275
  $term_id = $_GET['tag_ID'];
276
+ } elseif ( ! empty( $_POST['tag_ID'] ) ) {
277
  $term_id = $_POST['tag_ID'];
278
  }
279
  return $term_id;