Smart Custom Fields - Version 3.0.0

Version Description

  • Support multiple user roles.
  • Update filter hook smart-cf-register-fields
Download this release

Release Info

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

Code changes from version 2.3.0 to 3.0.0

classes/class.scf.php CHANGED
@@ -1,10 +1,10 @@
1
  <?php
2
  /**
3
  * SCF
4
- * Version : 1.5.0
5
  * Author : inc2734
6
  * Created : September 23, 2014
7
- * Modified : June 4, 2016
8
  * License : GPLv2 or later
9
  * License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
  */
@@ -185,8 +185,8 @@ class SCF {
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();
@@ -385,8 +385,8 @@ class SCF {
385
  self::debug_cache_message( "dont use settings posts cache..." );
386
  }
387
 
388
- $Meta = new Smart_Custom_Fields_Meta( $object );
389
- $type = $Meta->get_type( false );
390
 
391
  switch ( $Meta->get_meta_type() ) {
392
  case 'post' :
@@ -405,20 +405,28 @@ class SCF {
405
  $key = '';
406
  }
407
 
408
- if ( !empty( $key ) && !empty( $type ) ) {
409
- $settings_posts = get_posts( array(
 
 
 
 
 
 
 
 
 
 
 
 
410
  'post_type' => SCF_Config::NAME,
411
  'posts_per_page' => -1,
412
  'order' => 'ASC',
413
  'order_by' => 'menu_order',
414
- 'meta_query' => array(
415
- array(
416
- 'key' => $key,
417
- 'compare' => 'LIKE',
418
- 'value' => sprintf( '"%s"', $type ),
419
- ),
420
- ),
421
- ) );
422
  }
423
 
424
  $Cache = Smart_Custom_Fields_Cache::getInstance();
@@ -436,6 +444,7 @@ class SCF {
436
  $Meta = new Smart_Custom_Fields_Meta( $object );
437
  $id = $Meta->get_id();
438
  $type = $Meta->get_type( false );
 
439
  $meta_type = $Meta->get_meta_type();
440
 
441
  // IF the post that has custom field settings according to post ID,
@@ -446,7 +455,8 @@ class SCF {
446
  }
447
 
448
  $settings = array();
449
- if ( !empty( $type ) ) {
 
450
  $settings_posts = self::get_settings_posts( $object );
451
  if ( $meta_type === 'post' ) {
452
  $settings = self::get_settings_for_post( $object, $settings_posts );
@@ -466,7 +476,8 @@ class SCF {
466
  $settings,
467
  $type,
468
  $id,
469
- $meta_type
 
470
  );
471
  if ( !is_array( $settings ) ) {
472
  $settings = array();
@@ -625,7 +636,7 @@ class SCF {
625
  $has_array = true;
626
  }
627
 
628
- if ( !is_int( $key ) ) {
629
  return true;
630
  }
631
  }
1
  <?php
2
  /**
3
  * SCF
4
+ * Version : 2.0.0
5
  * Author : inc2734
6
  * Created : September 23, 2014
7
+ * Modified : September 30, 2016
8
  * License : GPLv2 or later
9
  * License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
  */
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();
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' :
405
  $key = '';
406
  }
407
 
408
+ if ( ! empty( $key ) && ( ! empty( $types ) ) ) {
409
+ $meta_query = array();
410
+ foreach ( $types as $type ) {
411
+ $meta_query[] = array(
412
+ 'key' => $key,
413
+ 'value' => sprintf( '"%s"', $type ),
414
+ 'compare' => 'LIKE',
415
+ );
416
+ }
417
+ if ( $meta_query ) {
418
+ $meta_query[ 'relation' ] = 'OR';
419
+ }
420
+
421
+ $args = array(
422
  'post_type' => SCF_Config::NAME,
423
  'posts_per_page' => -1,
424
  'order' => 'ASC',
425
  'order_by' => 'menu_order',
426
+ 'meta_query' => $meta_query,
427
+ );
428
+
429
+ $settings_posts = get_posts( $args );
 
 
 
 
430
  }
431
 
432
  $Cache = Smart_Custom_Fields_Cache::getInstance();
444
  $Meta = new Smart_Custom_Fields_Meta( $object );
445
  $id = $Meta->get_id();
446
  $type = $Meta->get_type( false );
447
+ $types = $Meta->get_types( false );
448
  $meta_type = $Meta->get_meta_type();
449
 
450
  // IF the post that has custom field settings according to post ID,
455
  }
456
 
457
  $settings = array();
458
+
459
+ if ( ! empty( $types ) ) {
460
  $settings_posts = self::get_settings_posts( $object );
461
  if ( $meta_type === 'post' ) {
462
  $settings = self::get_settings_for_post( $object, $settings_posts );
476
  $settings,
477
  $type,
478
  $id,
479
+ $meta_type,
480
+ $types
481
  );
482
  if ( !is_array( $settings ) ) {
483
  $settings = array();
636
  $has_array = true;
637
  }
638
 
639
+ if ( !is_int( $key ) ) {
640
  return true;
641
  }
642
  }
classes/models/class.meta.php CHANGED
@@ -1,10 +1,10 @@
1
  <?php
2
  /**
3
  * Smart_Custom_Fields_Meta
4
- * Version : 2.0.0
5
  * Author : inc2734
6
  * Created : March 17, 2015
7
- * Modified : July 1, 2016
8
  * License : GPLv2 or later
9
  * License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
  */
@@ -30,9 +30,16 @@ class Smart_Custom_Fields_Meta {
30
  /**
31
  * Post Type or Role or Taxonomy or Menu slug
32
  * @var string
 
33
  */
34
  protected $type;
35
 
 
 
 
 
 
 
36
  /**
37
  * @param WP_Post|WP_User|WP_Term|stdClass $object
38
  */
@@ -42,28 +49,33 @@ class Smart_Custom_Fields_Meta {
42
  }
43
  $this->object = $object;
44
  if ( is_a( $object, 'WP_Post' ) ) {
45
- $this->id = $object->ID;
46
- $this->type = $object->post_type;
 
47
  $this->meta_type = 'post';
48
  }
49
  elseif ( is_a( $object, 'WP_User' ) ) {
50
- $this->id = $object->ID;
51
- $this->type = $object->roles[0];
 
52
  $this->meta_type = 'user';
53
  }
54
  elseif ( isset( $object->term_id ) ) {
55
- $this->id = $object->term_id;
56
- $this->type = $object->taxonomy;
 
57
  $this->meta_type = 'term';
58
  }
59
  elseif ( isset( $object->menu_slug ) ) {
60
- $this->id = $object->menu_slug;
61
- $this->type = $object->menu_slug;
 
62
  $this->meta_type = 'option';
63
  }
64
  elseif( empty( $object ) || is_wp_error( $object ) ) {
65
- $this->id = null;
66
- $this->type = null;
 
67
  $this->meta_type = null;
68
  }
69
  else {
@@ -92,22 +104,37 @@ class Smart_Custom_Fields_Meta {
92
  /**
93
  * Getting type ( Post type or Role or Taxonomy or Menu slug )
94
  *
 
95
  * @param bool $accept_revision If post type, whether allow revision post type
96
  * @return string
97
  */
98
  public function get_type( $accept_revision = true ) {
99
  if ( $this->meta_type === 'post' && !$accept_revision ) {
100
- return $this->get_public_post_type( $this->id );
 
101
  }
102
  return $this->type;
103
  }
104
 
 
 
 
 
 
 
 
 
 
 
 
 
 
105
  /**
106
  * Getting post type
107
  * To feel good also Post ID of the revision
108
  *
109
  * @param int $post_id
110
- * @return string
111
  */
112
  protected function get_public_post_type( $post_id ) {
113
  if ( $public_post_id = wp_is_post_revision( $post_id ) ) {
@@ -116,9 +143,9 @@ class Smart_Custom_Fields_Meta {
116
  $post = get_post( $post_id );
117
  }
118
  if ( !empty( $post->post_type ) ) {
119
- return $post->post_type;
120
  }
121
- return $this->type;
122
  }
123
 
124
  /**
1
  <?php
2
  /**
3
  * Smart_Custom_Fields_Meta
4
+ * Version : 2.1.0
5
  * Author : inc2734
6
  * Created : March 17, 2015
7
+ * Modified : September 30, 2016
8
  * License : GPLv2 or later
9
  * License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
  */
30
  /**
31
  * Post Type or Role or Taxonomy or Menu slug
32
  * @var string
33
+ * @deprecated
34
  */
35
  protected $type;
36
 
37
+ /**
38
+ * Post Type or Roles or Taxonomy or Menu slug
39
+ * @var array
40
+ */
41
+ protected $types = array();
42
+
43
  /**
44
  * @param WP_Post|WP_User|WP_Term|stdClass $object
45
  */
49
  }
50
  $this->object = $object;
51
  if ( is_a( $object, 'WP_Post' ) ) {
52
+ $this->id = $object->ID;
53
+ $this->type = $object->post_type;
54
+ $this->types = array( $object->post_type );
55
  $this->meta_type = 'post';
56
  }
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
  }
63
  elseif ( isset( $object->term_id ) ) {
64
+ $this->id = $object->term_id;
65
+ $this->type = $object->taxonomy;
66
+ $this->types = array( $object->taxonomy );
67
  $this->meta_type = 'term';
68
  }
69
  elseif ( isset( $object->menu_slug ) ) {
70
+ $this->id = $object->menu_slug;
71
+ $this->type = $object->menu_slug;
72
+ $this->types = array( $object->menu_slug );
73
  $this->meta_type = 'option';
74
  }
75
  elseif( empty( $object ) || is_wp_error( $object ) ) {
76
+ $this->id = null;
77
+ $this->type = null;
78
+ $this->types = null;
79
  $this->meta_type = null;
80
  }
81
  else {
104
  /**
105
  * Getting type ( Post type or Role or Taxonomy or Menu slug )
106
  *
107
+ * @deprecated
108
  * @param bool $accept_revision If post type, whether allow revision post type
109
  * @return string
110
  */
111
  public function get_type( $accept_revision = true ) {
112
  if ( $this->meta_type === 'post' && !$accept_revision ) {
113
+ $public_post_type = $this->get_public_post_type( $this->id );
114
+ return $public_post_type[0];
115
  }
116
  return $this->type;
117
  }
118
 
119
+ /**
120
+ * Getting type ( Post type or Role or Taxonomy or Menu slug )
121
+ *
122
+ * @param bool $accept_revision If post type, whether allow revision post type
123
+ * @return array
124
+ */
125
+ public function get_types( $accept_revision = true ) {
126
+ if ( $this->meta_type === 'post' && ! $accept_revision ) {
127
+ return $this->get_public_post_type( $this->id );
128
+ }
129
+ return $this->types;
130
+ }
131
+
132
  /**
133
  * Getting post type
134
  * To feel good also Post ID of the revision
135
  *
136
  * @param int $post_id
137
+ * @return array
138
  */
139
  protected function get_public_post_type( $post_id ) {
140
  if ( $public_post_id = wp_is_post_revision( $post_id ) ) {
143
  $post = get_post( $post_id );
144
  }
145
  if ( !empty( $post->post_type ) ) {
146
+ return array( $post->post_type );
147
  }
148
+ return $this->types;
149
  }
150
 
151
  /**
readme.txt CHANGED
@@ -1,10 +1,10 @@
1
  === Smart Custom Fields ===
2
- Contributors: inc2734, toro_unit, mimosafa, hideokamoto, hisako-isaka, kurudrive, hanamura
3
  Donate link: http://www.amazon.co.jp/registry/wishlist/39ANKRNSTNW40
4
  Tags: plugin, custom field, custom, field, meta, meta field, repeat, repeatable
5
  Requires at least: 3.9
6
- Tested up to: 4.6.0
7
- Stable tag: 2.3.0
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -125,6 +125,10 @@ You can send your own language pack to me.
125
 
126
  == Changelog ==
127
 
 
 
 
 
128
  = 2.3.0 =
129
  * Support displayed thumbnail when value of file and image field is file url.
130
 
1
  === Smart Custom Fields ===
2
+ Contributors: inc2734, toro_unit, mimosafa, hideokamoto, hisako-isaka, kurudrive, hanamura, justinticktock
3
  Donate link: http://www.amazon.co.jp/registry/wishlist/39ANKRNSTNW40
4
  Tags: plugin, custom field, custom, field, meta, meta field, repeat, repeatable
5
  Requires at least: 3.9
6
+ Tested up to: 4.6.1
7
+ Stable tag: 3.0.0
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
125
 
126
  == Changelog ==
127
 
128
+ = 3.0.0 =
129
+ * Support multiple user roles.
130
+ * Update filter hook smart-cf-register-fields
131
+
132
  = 2.3.0 =
133
  * Support displayed thumbnail when value of file and image field is file url.
134
 
smart-custom-fields.php CHANGED
@@ -3,11 +3,11 @@
3
  * Plugin name: Smart Custom Fields
4
  * Plugin URI: https://github.com/inc2734/smart-custom-fields/
5
  * Description: Smart Custom Fields is a simple plugin that management custom fields.
6
- * Version: 2.3.0
7
  * Author: inc2734
8
  * Author URI: http://2inc.org
9
  * Created: October 9, 2014
10
- * Modified: September 6, 2016
11
  * Text Domain: smart-custom-fields
12
  * Domain Path: /languages
13
  * License: GPLv2 or later
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: 3.0.0
7
  * Author: inc2734
8
  * Author URI: http://2inc.org
9
  * Created: October 9, 2014
10
+ * Modified: September 30, 2016
11
  * Text Domain: smart-custom-fields
12
  * Domain Path: /languages
13
  * License: GPLv2 or later