Smart Custom Fields - Version 1.2.1

Version Description

  • Fixed a bug that post id filtering incorrect.
Download this release

Release Info

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

Code changes from version 1.2.0 to 1.2.1

Files changed (3) hide show
  1. classes/class.scf.php +30 -19
  2. readme.txt +4 -1
  3. smart-custom-fields.php +3 -3
classes/class.scf.php CHANGED
@@ -1,10 +1,10 @@
1
  <?php
2
  /**
3
  * SCF
4
- * Version : 1.1.0
5
  * Author : Takashi Kitajima
6
  * Created : September 23, 2014
7
- * Modified : February 27, 2015
8
  * License : GPLv2
9
  * License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
  */
@@ -296,16 +296,16 @@ class SCF {
296
  /**
297
  * その投稿タイプで有効になっている SCF を取得
298
  *
299
- * @param int $post_type
300
- * @param array $settings
 
301
  */
302
- public static function get_settings_posts( $post_type ) {
303
- global $post;
304
  $posts = array();
305
  if ( isset( self::$settings_posts_cache[$post_type] ) ) {
306
  return self::$settings_posts_cache[$post_type];
307
  }
308
- $_posts = get_posts( array(
309
  'post_type' => SCF_Config::NAME,
310
  'posts_per_page' => -1,
311
  'order' => 'ASC',
@@ -320,25 +320,33 @@ class SCF {
320
  ) );
321
 
322
  // Post ID による表示条件設定がある場合はフィルタリングする
 
323
  if ( isset( $post->ID ) ) {
324
- foreach ( $_posts as $_post ) {
325
- $condition_post_ids = array();
326
- $_condition_post_ids = get_post_meta( $_post->ID, SCF_Config::PREFIX . 'condition-post-ids', true );
 
 
 
 
 
327
  if ( $_condition_post_ids ) {
328
  $_condition_post_ids = explode( ',', $_condition_post_ids );
329
  foreach ( $_condition_post_ids as $condition_post_id ) {
330
  $condition_post_ids[] = trim( $condition_post_id );
331
  }
332
- if ( $condition_post_ids && !in_array( $post->ID, $condition_post_ids ) ) {
333
  continue;
334
  }
335
  }
336
- $posts[] = $_post;
337
  }
338
  } else {
339
- $posts = $_posts;
 
 
 
340
  }
341
- self::save_settings_posts_cache( $post_type, $posts );
342
  return $posts;
343
  }
344
 
@@ -355,20 +363,23 @@ class SCF {
355
  /**
356
  * Setting オブジェクトの配列を取得
357
  *
358
- * @param int $post_type
359
- * @param array $settings
 
360
  */
361
- public static function get_settings( $post_type ) {
362
  if ( isset( self::$settings_cache[$post_type] ) ) {
363
  return self::$settings_cache[$post_type];
364
  }
365
  $settings = array();
366
- $cf_posts = self::get_settings_posts( $post_type );
367
  foreach ( $cf_posts as $post ) {
368
  $settings[] = SCF::add_setting( $post->ID, $post->post_title );
369
  }
370
  $settings = apply_filters( SCF_Config::PREFIX . 'register-fields', $settings, $post_type );
371
- self::save_settings_cache( $post_type, $settings );
 
 
372
  return $settings;
373
  }
374
 
1
  <?php
2
  /**
3
  * SCF
4
+ * Version : 1.1.1
5
  * Author : Takashi Kitajima
6
  * Created : September 23, 2014
7
+ * Modified : March 12, 2015
8
  * License : GPLv2
9
  * License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
  */
296
  /**
297
  * その投稿タイプで有効になっている SCF を取得
298
  *
299
+ * @param string $post_type
300
+ * @param bool $do_caching
301
+ * @return array $settings
302
  */
303
+ public static function get_settings_posts( $post_type, $do_caching = true ) {
 
304
  $posts = array();
305
  if ( isset( self::$settings_posts_cache[$post_type] ) ) {
306
  return self::$settings_posts_cache[$post_type];
307
  }
308
+ $settings_posts = get_posts( array(
309
  'post_type' => SCF_Config::NAME,
310
  'posts_per_page' => -1,
311
  'order' => 'ASC',
320
  ) );
321
 
322
  // Post ID による表示条件設定がある場合はフィルタリングする
323
+ global $post;
324
  if ( isset( $post->ID ) ) {
325
+ $post_id = $post->ID;
326
+ foreach ( $settings_posts as $settings_post ) {
327
+ $condition_post_ids = array();
328
+ $_condition_post_ids = get_post_meta(
329
+ $settings_post->ID,
330
+ SCF_Config::PREFIX . 'condition-post-ids',
331
+ true
332
+ );
333
  if ( $_condition_post_ids ) {
334
  $_condition_post_ids = explode( ',', $_condition_post_ids );
335
  foreach ( $_condition_post_ids as $condition_post_id ) {
336
  $condition_post_ids[] = trim( $condition_post_id );
337
  }
338
+ if ( $condition_post_ids && !in_array( $post_id, $condition_post_ids ) ) {
339
  continue;
340
  }
341
  }
342
+ $posts[] = $settings_post;
343
  }
344
  } else {
345
+ $posts = $settings_posts;
346
+ }
347
+ if ( $do_caching === true ) {
348
+ self::save_settings_posts_cache( $post_type, $posts );
349
  }
 
350
  return $posts;
351
  }
352
 
363
  /**
364
  * Setting オブジェクトの配列を取得
365
  *
366
+ * @param string $post_type
367
+ * @param bool $do_caching
368
+ * @return array $settings
369
  */
370
+ public static function get_settings( $post_type, $do_caching = true ) {
371
  if ( isset( self::$settings_cache[$post_type] ) ) {
372
  return self::$settings_cache[$post_type];
373
  }
374
  $settings = array();
375
+ $cf_posts = self::get_settings_posts( $post_type, $do_caching );
376
  foreach ( $cf_posts as $post ) {
377
  $settings[] = SCF::add_setting( $post->ID, $post->post_title );
378
  }
379
  $settings = apply_filters( SCF_Config::PREFIX . 'register-fields', $settings, $post_type );
380
+ if ( $do_caching === true ) {
381
+ self::save_settings_cache( $post_type, $settings );
382
+ }
383
  return $settings;
384
  }
385
 
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: http://www.amazon.co.jp/registry/wishlist/39ANKRNSTNW40
4
  Tags: plugin, custom field, custom, field, meta, meta field, repeat, repeatable
5
  Requires at least: 3.9
6
  Tested up to: 4.1.1
7
- Stable tag: 1.2.0
8
  License: GPLv2
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -72,6 +72,9 @@ You can send your own language pack to me.
72
 
73
  == Changelog ==
74
 
 
 
 
75
  = 1.2.0 =
76
  * refactoring. A lot of changes in all.
77
  * Renewd the Smart_Custom_Fields_Field_Base.
4
  Tags: plugin, custom field, custom, field, meta, meta field, repeat, repeatable
5
  Requires at least: 3.9
6
  Tested up to: 4.1.1
7
+ Stable tag: 1.2.1
8
  License: GPLv2
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
72
 
73
  == Changelog ==
74
 
75
+ = 1.2.1 =
76
+ * Fixed a bug that post id filtering incorrect.
77
+
78
  = 1.2.0 =
79
  * refactoring. A lot of changes in all.
80
  * Renewd the Smart_Custom_Fields_Field_Base.
smart-custom-fields.php CHANGED
@@ -3,11 +3,11 @@
3
  * Plugin name: Smart Custom Fields
4
  * Plugin URI: https://github.com/inc2734/smart-custom-fields/
5
  * Description: Smart Custom Fields is a simple plugin that management custom fields.
6
- * Version: 1.2.0
7
  * Author: Takashi Kitajima
8
  * Author URI: http://2inc.org
9
  * Created: October 9, 2014
10
- * Modified: February 27, 2015
11
  * Text Domain: smart-custom-fields
12
  * Domain Path: /languages
13
  * License: GPLv2
@@ -87,7 +87,7 @@ class Smart_Custom_Fields {
87
  new Smart_Custom_Fields_Controller_Settings();
88
  }
89
  // その他の新規作成・編集画面
90
- elseif ( SCF::get_settings( $screen->id ) ) {
91
  require_once plugin_dir_path( __FILE__ ) . 'classes/controller/class.editor.php';
92
  new Smart_Custom_Fields_Controller_Editor();
93
  }
3
  * Plugin name: Smart Custom Fields
4
  * Plugin URI: https://github.com/inc2734/smart-custom-fields/
5
  * Description: Smart Custom Fields is a simple plugin that management custom fields.
6
+ * Version: 1.2.1
7
  * Author: Takashi Kitajima
8
  * Author URI: http://2inc.org
9
  * Created: October 9, 2014
10
+ * Modified: March 12, 2015
11
  * Text Domain: smart-custom-fields
12
  * Domain Path: /languages
13
  * License: GPLv2
87
  new Smart_Custom_Fields_Controller_Settings();
88
  }
89
  // その他の新規作成・編集画面
90
+ elseif ( SCF::get_settings( $screen->id, false ) ) {
91
  require_once plugin_dir_path( __FILE__ ) . 'classes/controller/class.editor.php';
92
  new Smart_Custom_Fields_Controller_Editor();
93
  }