Version Description
- Add display condition by post id.
- Fix bug that is not displayed wysiwyg editor when there are not content editor.
- Textarea does not filter the_content filter in SCF::get() and SCF::gets().
Download this release
Release Info
Developer | inc2734 |
Plugin | Smart Custom Fields |
Version | 1.0.1 |
Comparing to | |
See all releases |
Code changes from version 1.0.0 to 1.0.1
- classes/class.field-base.php +40 -14
- classes/class.revisions.php +3 -3
- classes/class.scf.php +60 -7
- classes/class.settings.php +23 -3
- classes/fields/class.field-check.php +4 -3
- classes/fields/class.field-relation.php +4 -3
- classes/fields/class.field-wysiwyg.php +16 -2
- css/settings.css +4 -0
- readme.txt +6 -1
- smart-custom-fields.php +16 -17
classes/class.field-base.php
CHANGED
@@ -1,10 +1,10 @@
|
|
1 |
<?php
|
2 |
/**
|
3 |
* Smart_Custom_Fields_Field_Base
|
4 |
-
* Version : 1.0.
|
5 |
* Author : Takashi Kitajima
|
6 |
* Created : October 7, 2014
|
7 |
-
* Modified :
|
8 |
* License : GPLv2
|
9 |
* License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
*/
|
@@ -20,6 +20,11 @@ abstract class Smart_Custom_Fields_Field_Base {
|
|
20 |
*/
|
21 |
protected $label;
|
22 |
|
|
|
|
|
|
|
|
|
|
|
23 |
/**
|
24 |
* $field
|
25 |
*/
|
@@ -43,17 +48,28 @@ abstract class Smart_Custom_Fields_Field_Base {
|
|
43 |
if ( empty( $settings['optgroup'] ) ) {
|
44 |
$settings['optgroup'] = 'basic-fields';
|
45 |
}
|
46 |
-
|
|
|
|
|
47 |
add_filter( SCF_Config::PREFIX . 'field-select-' . $settings['optgroup'], array( $this, 'field_select' ) );
|
48 |
add_action( SCF_Config::PREFIX . 'field-options', array( $this, '_display_field_options' ), 10, 3 );
|
|
|
|
|
|
|
49 |
}
|
50 |
|
51 |
/**
|
52 |
* init
|
53 |
-
* @return array ( name, label, optgroup )
|
54 |
*/
|
55 |
abstract protected function init();
|
56 |
|
|
|
|
|
|
|
|
|
|
|
|
|
57 |
/**
|
58 |
* get_field
|
59 |
* @param array $field フィールドの情報
|
@@ -63,16 +79,6 @@ abstract class Smart_Custom_Fields_Field_Base {
|
|
63 |
*/
|
64 |
abstract public function get_field( $field, $index, $value );
|
65 |
|
66 |
-
/**
|
67 |
-
* add_fields
|
68 |
-
* @param array $fields
|
69 |
-
* @return array $fields
|
70 |
-
*/
|
71 |
-
public function add_fields( $fields ) {
|
72 |
-
$fields[$this->name] = $this;
|
73 |
-
return $fields;
|
74 |
-
}
|
75 |
-
|
76 |
/**
|
77 |
* field_select
|
78 |
* @param array $options その optgroup に属するフィールドのリスト
|
@@ -159,6 +165,26 @@ abstract class Smart_Custom_Fields_Field_Base {
|
|
159 |
}
|
160 |
}
|
161 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
162 |
public function get_choices( $choices ) {
|
163 |
return explode( "\n", $choices );
|
164 |
}
|
1 |
<?php
|
2 |
/**
|
3 |
* Smart_Custom_Fields_Field_Base
|
4 |
+
* Version : 1.0.1
|
5 |
* Author : Takashi Kitajima
|
6 |
* Created : October 7, 2014
|
7 |
+
* Modified : October 10, 2014
|
8 |
* License : GPLv2
|
9 |
* License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
*/
|
20 |
*/
|
21 |
protected $label;
|
22 |
|
23 |
+
/**
|
24 |
+
* $allow_multiple_data
|
25 |
+
*/
|
26 |
+
protected $allow_multiple_data = false;
|
27 |
+
|
28 |
/**
|
29 |
* $field
|
30 |
*/
|
48 |
if ( empty( $settings['optgroup'] ) ) {
|
49 |
$settings['optgroup'] = 'basic-fields';
|
50 |
}
|
51 |
+
if ( isset( $settings['allow-multiple-data'] ) && $settings['allow-multiple-data'] === true ) {
|
52 |
+
$this->allow_multiple_data = true;
|
53 |
+
}
|
54 |
add_filter( SCF_Config::PREFIX . 'field-select-' . $settings['optgroup'], array( $this, 'field_select' ) );
|
55 |
add_action( SCF_Config::PREFIX . 'field-options', array( $this, '_display_field_options' ), 10, 3 );
|
56 |
+
$this->after_loaded();
|
57 |
+
|
58 |
+
SCF::add_field_instance( $this );
|
59 |
}
|
60 |
|
61 |
/**
|
62 |
* init
|
63 |
+
* @return array ( name, label, optgroup, allow-multiple-data )
|
64 |
*/
|
65 |
abstract protected function init();
|
66 |
|
67 |
+
/**
|
68 |
+
* after_loaded
|
69 |
+
*/
|
70 |
+
protected function after_loaded() {
|
71 |
+
}
|
72 |
+
|
73 |
/**
|
74 |
* get_field
|
75 |
* @param array $field フィールドの情報
|
79 |
*/
|
80 |
abstract public function get_field( $field, $index, $value );
|
81 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
82 |
/**
|
83 |
* field_select
|
84 |
* @param array $options その optgroup に属するフィールドのリスト
|
165 |
}
|
166 |
}
|
167 |
|
168 |
+
/**
|
169 |
+
* get_name
|
170 |
+
* @return string
|
171 |
+
*/
|
172 |
+
public function get_name() {
|
173 |
+
return $this->name;
|
174 |
+
}
|
175 |
+
|
176 |
+
/**
|
177 |
+
* get_allow_multiple_data
|
178 |
+
*/
|
179 |
+
public function allow_multiple_data() {
|
180 |
+
return $this->allow_multiple_data;
|
181 |
+
}
|
182 |
+
|
183 |
+
/**
|
184 |
+
* get_choices
|
185 |
+
* @param string $choices
|
186 |
+
* @return array
|
187 |
+
*/
|
188 |
public function get_choices( $choices ) {
|
189 |
return explode( "\n", $choices );
|
190 |
}
|
classes/class.revisions.php
CHANGED
@@ -1,10 +1,10 @@
|
|
1 |
<?php
|
2 |
/**
|
3 |
* Smart_Custom_Fields_Revisions
|
4 |
-
* Version : 1.0.
|
5 |
* Author : Takashi Kitajima
|
6 |
* Created : September 23, 2014
|
7 |
-
* Modified :
|
8 |
* License : GPLv2
|
9 |
* License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
*/
|
@@ -90,7 +90,7 @@ class Smart_Custom_Fields_Revisions {
|
|
90 |
foreach ( $group['fields'] as $field ) {
|
91 |
delete_metadata( 'post', $post_id, $field['name'] );
|
92 |
|
93 |
-
if ( $is_repeat &&
|
94 |
$repeat_multiple_data_fields = $_POST[SCF_Config::NAME][$field['name']];
|
95 |
foreach ( $repeat_multiple_data_fields as $values ) {
|
96 |
if ( is_array( $values ) ) {
|
1 |
<?php
|
2 |
/**
|
3 |
* Smart_Custom_Fields_Revisions
|
4 |
+
* Version : 1.0.1
|
5 |
* Author : Takashi Kitajima
|
6 |
* Created : September 23, 2014
|
7 |
+
* Modified : October 10, 2014
|
8 |
* License : GPLv2
|
9 |
* License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
*/
|
90 |
foreach ( $group['fields'] as $field ) {
|
91 |
delete_metadata( 'post', $post_id, $field['name'] );
|
92 |
|
93 |
+
if ( $is_repeat && $field['allow-multiple-data'] ) {
|
94 |
$repeat_multiple_data_fields = $_POST[SCF_Config::NAME][$field['name']];
|
95 |
foreach ( $repeat_multiple_data_fields as $values ) {
|
96 |
if ( is_array( $values ) ) {
|
classes/class.scf.php
CHANGED
@@ -1,15 +1,20 @@
|
|
1 |
<?php
|
2 |
/**
|
3 |
* SCF
|
4 |
-
* Version : 1.0.
|
5 |
* Author : Takashi Kitajima
|
6 |
* Created : September 23, 2014
|
7 |
-
* Modified :
|
8 |
* License : GPLv2
|
9 |
* License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
*/
|
11 |
class SCF {
|
12 |
|
|
|
|
|
|
|
|
|
|
|
13 |
/**
|
14 |
* データ取得処理は重いので、一度取得したデータは cache に保存する。
|
15 |
* キーに post_id を設定すること。
|
@@ -186,7 +191,7 @@ class SCF {
|
|
186 |
// チェックボックス以外
|
187 |
else {
|
188 |
foreach ( $_post_meta as $_post_meta_key => $value ) {
|
189 |
-
if ( in_array( $field['type'], array( '
|
190 |
$value = apply_filters( 'the_content', $value );
|
191 |
} elseif ( $field['type'] === 'relation' ) {
|
192 |
if ( get_post_status( $value ) !== 'publish' )
|
@@ -208,12 +213,12 @@ class SCF {
|
|
208 |
* @return mixed $post_meta
|
209 |
*/
|
210 |
protected static function get_field( $post_id, $field, $is_repeat, $name = null ) {
|
211 |
-
if (
|
212 |
$post_meta = get_post_meta( $post_id, $field['name'] );
|
213 |
} else {
|
214 |
$post_meta = get_post_meta( $post_id, $field['name'], true );
|
215 |
}
|
216 |
-
if ( in_array( $field['type'], array( '
|
217 |
if ( is_array( $post_meta ) ) {
|
218 |
$_post_meta = array();
|
219 |
foreach ( $post_meta as $key => $value ) {
|
@@ -251,11 +256,12 @@ class SCF {
|
|
251 |
* @param array $settings
|
252 |
*/
|
253 |
public static function get_settings_posts( $post_type ) {
|
|
|
254 |
$posts = array();
|
255 |
if ( isset( self::$settings_posts_cache[$post_type] ) ) {
|
256 |
return self::$settings_posts_cache[$post_type];
|
257 |
}
|
258 |
-
$
|
259 |
'post_type' => SCF_Config::NAME,
|
260 |
'posts_per_page' => -1,
|
261 |
'meta_query' => array(
|
@@ -266,6 +272,24 @@ class SCF {
|
|
266 |
),
|
267 |
),
|
268 |
) );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
269 |
self::save_settings_posts_cache( $post_type, $posts );
|
270 |
return $posts;
|
271 |
}
|
@@ -297,7 +321,14 @@ class SCF {
|
|
297 |
if ( is_array( $_setting ) ) {
|
298 |
$setting = $_setting;
|
299 |
}
|
300 |
-
$settings[] = $setting;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
301 |
}
|
302 |
}
|
303 |
self::save_settings_cache( $post_type, $settings );
|
@@ -348,4 +379,26 @@ class SCF {
|
|
348 |
}
|
349 |
return true;
|
350 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
351 |
}
|
1 |
<?php
|
2 |
/**
|
3 |
* SCF
|
4 |
+
* Version : 1.0.1
|
5 |
* Author : Takashi Kitajima
|
6 |
* Created : September 23, 2014
|
7 |
+
* Modified : October 10, 2014
|
8 |
* License : GPLv2
|
9 |
* License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
*/
|
11 |
class SCF {
|
12 |
|
13 |
+
/**
|
14 |
+
* Smart Custom Fields に登録されているフォームアイテム(field)のインスタンスの配列
|
15 |
+
*/
|
16 |
+
protected static $fields = array();
|
17 |
+
|
18 |
/**
|
19 |
* データ取得処理は重いので、一度取得したデータは cache に保存する。
|
20 |
* キーに post_id を設定すること。
|
191 |
// チェックボックス以外
|
192 |
else {
|
193 |
foreach ( $_post_meta as $_post_meta_key => $value ) {
|
194 |
+
if ( in_array( $field['type'], array( 'wysiwyg' ) ) ) {
|
195 |
$value = apply_filters( 'the_content', $value );
|
196 |
} elseif ( $field['type'] === 'relation' ) {
|
197 |
if ( get_post_status( $value ) !== 'publish' )
|
213 |
* @return mixed $post_meta
|
214 |
*/
|
215 |
protected static function get_field( $post_id, $field, $is_repeat, $name = null ) {
|
216 |
+
if ( $field['allow-multiple-data'] || $is_repeat ) {
|
217 |
$post_meta = get_post_meta( $post_id, $field['name'] );
|
218 |
} else {
|
219 |
$post_meta = get_post_meta( $post_id, $field['name'], true );
|
220 |
}
|
221 |
+
if ( in_array( $field['type'], array( 'wysiwyg' ) ) ) {
|
222 |
if ( is_array( $post_meta ) ) {
|
223 |
$_post_meta = array();
|
224 |
foreach ( $post_meta as $key => $value ) {
|
256 |
* @param array $settings
|
257 |
*/
|
258 |
public static function get_settings_posts( $post_type ) {
|
259 |
+
global $post;
|
260 |
$posts = array();
|
261 |
if ( isset( self::$settings_posts_cache[$post_type] ) ) {
|
262 |
return self::$settings_posts_cache[$post_type];
|
263 |
}
|
264 |
+
$_posts = get_posts( array(
|
265 |
'post_type' => SCF_Config::NAME,
|
266 |
'posts_per_page' => -1,
|
267 |
'meta_query' => array(
|
272 |
),
|
273 |
),
|
274 |
) );
|
275 |
+
|
276 |
+
// Post ID による表示条件設定がある場合はフィルタリングする
|
277 |
+
if ( isset( $post->ID ) ) {
|
278 |
+
foreach ( $_posts as $_post ) {
|
279 |
+
$condition_post_ids = array();
|
280 |
+
$_condition_post_ids = get_post_meta( $_post->ID, SCF_Config::PREFIX . 'condition-post-ids', true );
|
281 |
+
if ( $_condition_post_ids ) {
|
282 |
+
$_condition_post_ids = explode( ',', $_condition_post_ids );
|
283 |
+
foreach ( $_condition_post_ids as $condition_post_id ) {
|
284 |
+
$condition_post_ids[] = trim( $condition_post_id );
|
285 |
+
}
|
286 |
+
if ( $condition_post_ids && !in_array( $post->ID, $condition_post_ids ) ) {
|
287 |
+
continue;
|
288 |
+
}
|
289 |
+
}
|
290 |
+
$posts[] = $_post;
|
291 |
+
}
|
292 |
+
}
|
293 |
self::save_settings_posts_cache( $post_type, $posts );
|
294 |
return $posts;
|
295 |
}
|
321 |
if ( is_array( $_setting ) ) {
|
322 |
$setting = $_setting;
|
323 |
}
|
324 |
+
$settings[SCF_Config::PREFIX . 'custom-field-' . $_post->ID] = $setting;
|
325 |
+
}
|
326 |
+
foreach ( $settings as $setting_key => $setting ) {
|
327 |
+
foreach ( $setting as $group_key => $group ) {
|
328 |
+
foreach ( $group['fields'] as $field_key => $field ) {
|
329 |
+
$settings[$setting_key][$group_key]['fields'][$field_key]['allow-multiple-data'] = self::$fields[$field['type']]->allow_multiple_data();
|
330 |
+
}
|
331 |
+
}
|
332 |
}
|
333 |
}
|
334 |
self::save_settings_cache( $post_type, $settings );
|
379 |
}
|
380 |
return true;
|
381 |
}
|
382 |
+
|
383 |
+
/**
|
384 |
+
* add_field_instance
|
385 |
+
* @param Smart_Custom_Fields_Field_Base $instance
|
386 |
+
*/
|
387 |
+
public static function add_field_instance( Smart_Custom_Fields_Field_Base $instance ) {
|
388 |
+
$instance_name = $instance->get_name();
|
389 |
+
if ( !empty( $instance_name ) ) {
|
390 |
+
self::$fields[$instance_name] = $instance;
|
391 |
+
}
|
392 |
+
}
|
393 |
+
|
394 |
+
/**
|
395 |
+
* get_field_instance
|
396 |
+
* @param string $field_name フォームアイテムの name
|
397 |
+
* @param Smart_Custom_Fields_Field_Base
|
398 |
+
*/
|
399 |
+
public static function get_field_instance( $field_name ) {
|
400 |
+
if ( !empty( self::$fields[$field_name] ) ) {
|
401 |
+
return self::$fields[$field_name];
|
402 |
+
}
|
403 |
+
}
|
404 |
}
|
classes/class.settings.php
CHANGED
@@ -1,10 +1,10 @@
|
|
1 |
<?php
|
2 |
/**
|
3 |
* Smart_Custom_Fields_Settings
|
4 |
-
* Version : 1.0.
|
5 |
* Author : Takashi Kitajima
|
6 |
* Created : September 23, 2014
|
7 |
-
* Modified :
|
8 |
* License : GPLv2
|
9 |
* License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
*/
|
@@ -262,9 +262,10 @@ class Smart_Custom_Fields_Settings {
|
|
262 |
unset( $post_types[SCF_Config::NAME] );
|
263 |
|
264 |
$conditions = get_post_meta( get_the_ID(), SCF_Config::PREFIX . 'condition', true );
|
|
|
265 |
foreach ( $post_types as $post_type => $post_type_object ) {
|
266 |
$current = ( is_array( $conditions ) && in_array( $post_type, $conditions ) ) ? $post_type : false;
|
267 |
-
|
268 |
'<label><input type="checkbox" name="%s" value="%s" %s /> %s</label>',
|
269 |
esc_attr( SCF_Config::PREFIX . 'condition[]' ),
|
270 |
esc_attr( $post_type ),
|
@@ -272,6 +273,19 @@ class Smart_Custom_Fields_Settings {
|
|
272 |
esc_attr( $post_type_object->labels->singular_name )
|
273 |
);
|
274 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
275 |
}
|
276 |
|
277 |
/**
|
@@ -327,5 +341,11 @@ class Smart_Custom_Fields_Settings {
|
|
327 |
} else {
|
328 |
update_post_meta( $post_id, SCF_Config::PREFIX . 'condition', $_POST[SCF_Config::PREFIX . 'condition'] );
|
329 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
330 |
}
|
331 |
}
|
1 |
<?php
|
2 |
/**
|
3 |
* Smart_Custom_Fields_Settings
|
4 |
+
* Version : 1.0.1
|
5 |
* Author : Takashi Kitajima
|
6 |
* Created : September 23, 2014
|
7 |
+
* Modified : October 10, 2014
|
8 |
* License : GPLv2
|
9 |
* License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
*/
|
262 |
unset( $post_types[SCF_Config::NAME] );
|
263 |
|
264 |
$conditions = get_post_meta( get_the_ID(), SCF_Config::PREFIX . 'condition', true );
|
265 |
+
$post_type_field = '';
|
266 |
foreach ( $post_types as $post_type => $post_type_object ) {
|
267 |
$current = ( is_array( $conditions ) && in_array( $post_type, $conditions ) ) ? $post_type : false;
|
268 |
+
$post_type_field .= sprintf(
|
269 |
'<label><input type="checkbox" name="%s" value="%s" %s /> %s</label>',
|
270 |
esc_attr( SCF_Config::PREFIX . 'condition[]' ),
|
271 |
esc_attr( $post_type ),
|
273 |
esc_attr( $post_type_object->labels->singular_name )
|
274 |
);
|
275 |
}
|
276 |
+
printf(
|
277 |
+
'<p><b>%s</b>%s</p>',
|
278 |
+
esc_html__( 'Post Types', 'smart-custom-fields' ),
|
279 |
+
$post_type_field
|
280 |
+
);
|
281 |
+
|
282 |
+
$condition_post_ids = get_post_meta( get_the_ID(), SCF_Config::PREFIX . 'condition-post-ids', true );
|
283 |
+
printf(
|
284 |
+
'<p><b>%s</b><input type="text" name="%s" value="%s" class="widefat" /></p>',
|
285 |
+
esc_html__( 'Post Ids ( Comma separated )', 'smart-custom-fields' ),
|
286 |
+
esc_attr( SCF_Config::PREFIX . 'condition-post-ids' ),
|
287 |
+
$condition_post_ids
|
288 |
+
);
|
289 |
}
|
290 |
|
291 |
/**
|
341 |
} else {
|
342 |
update_post_meta( $post_id, SCF_Config::PREFIX . 'condition', $_POST[SCF_Config::PREFIX . 'condition'] );
|
343 |
}
|
344 |
+
|
345 |
+
if ( !isset( $_POST[SCF_Config::PREFIX . 'condition-post-ids'] ) ) {
|
346 |
+
delete_post_meta( $post_id, SCF_Config::PREFIX . 'condition-post-ids' );
|
347 |
+
} else {
|
348 |
+
update_post_meta( $post_id, SCF_Config::PREFIX . 'condition-post-ids', $_POST[SCF_Config::PREFIX . 'condition-post-ids'] );
|
349 |
+
}
|
350 |
}
|
351 |
}
|
classes/fields/class.field-check.php
CHANGED
@@ -1,10 +1,10 @@
|
|
1 |
<?php
|
2 |
/**
|
3 |
* Smart_Custom_Fields_Field_Check
|
4 |
-
* Version : 1.0.
|
5 |
* Author : Takashi Kitajima
|
6 |
* Created : October 7, 2014
|
7 |
-
* Modified :
|
8 |
* License : GPLv2
|
9 |
* License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
*/
|
@@ -12,13 +12,14 @@ class Smart_Custom_Fields_Field_Check extends Smart_Custom_Fields_Field_Base {
|
|
12 |
|
13 |
/**
|
14 |
* init
|
15 |
-
* @return array ( name, label, optgroup )
|
16 |
*/
|
17 |
protected function init() {
|
18 |
return array(
|
19 |
'name' => 'check',
|
20 |
'label' => __( 'Check', 'smart-custom-fields' ),
|
21 |
'optgroup' => 'select-fields',
|
|
|
22 |
);
|
23 |
}
|
24 |
|
1 |
<?php
|
2 |
/**
|
3 |
* Smart_Custom_Fields_Field_Check
|
4 |
+
* Version : 1.0.1
|
5 |
* Author : Takashi Kitajima
|
6 |
* Created : October 7, 2014
|
7 |
+
* Modified : October 10, 2014
|
8 |
* License : GPLv2
|
9 |
* License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
*/
|
12 |
|
13 |
/**
|
14 |
* init
|
15 |
+
* @return array ( name, label, optgroup, allow-multiple-data )
|
16 |
*/
|
17 |
protected function init() {
|
18 |
return array(
|
19 |
'name' => 'check',
|
20 |
'label' => __( 'Check', 'smart-custom-fields' ),
|
21 |
'optgroup' => 'select-fields',
|
22 |
+
'allow-multiple-data' => true,
|
23 |
);
|
24 |
}
|
25 |
|
classes/fields/class.field-relation.php
CHANGED
@@ -1,10 +1,10 @@
|
|
1 |
<?php
|
2 |
/**
|
3 |
* Smart_Custom_Fields_Field_Relation
|
4 |
-
* Version : 1.0.
|
5 |
* Author : Takashi Kitajima
|
6 |
* Created : October 7, 2014
|
7 |
-
* Modified :
|
8 |
* License : GPLv2
|
9 |
* License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
*/
|
@@ -12,13 +12,14 @@ class Smart_Custom_Fields_Field_Relation extends Smart_Custom_Fields_Field_Base
|
|
12 |
|
13 |
/**
|
14 |
* init
|
15 |
-
* @return array ( name, label, optgroup )
|
16 |
*/
|
17 |
protected function init() {
|
18 |
return array(
|
19 |
'name' => 'relation',
|
20 |
'label' => __( 'Relation', 'smart-custom-fields' ),
|
21 |
'optgroup' => 'other-fields',
|
|
|
22 |
);
|
23 |
}
|
24 |
|
1 |
<?php
|
2 |
/**
|
3 |
* Smart_Custom_Fields_Field_Relation
|
4 |
+
* Version : 1.0.1
|
5 |
* Author : Takashi Kitajima
|
6 |
* Created : October 7, 2014
|
7 |
+
* Modified : October 10, 2014
|
8 |
* License : GPLv2
|
9 |
* License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
*/
|
12 |
|
13 |
/**
|
14 |
* init
|
15 |
+
* @return array ( name, label, optgroup, allow-multiple-data )
|
16 |
*/
|
17 |
protected function init() {
|
18 |
return array(
|
19 |
'name' => 'relation',
|
20 |
'label' => __( 'Relation', 'smart-custom-fields' ),
|
21 |
'optgroup' => 'other-fields',
|
22 |
+
'allow-multiple-data' => true,
|
23 |
);
|
24 |
}
|
25 |
|
classes/fields/class.field-wysiwyg.php
CHANGED
@@ -1,10 +1,10 @@
|
|
1 |
<?php
|
2 |
/**
|
3 |
* Smart_Custom_Fields_Field_Wysiwyg
|
4 |
-
* Version : 1.0.
|
5 |
* Author : Takashi Kitajima
|
6 |
* Created : October 7, 2014
|
7 |
-
* Modified :
|
8 |
* License : GPLv2
|
9 |
* License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
*/
|
@@ -22,6 +22,20 @@ class Smart_Custom_Fields_Field_Wysiwyg extends Smart_Custom_Fields_Field_Base {
|
|
22 |
);
|
23 |
}
|
24 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
/**
|
26 |
* get_field
|
27 |
* @param array $field フィールドの情報
|
1 |
<?php
|
2 |
/**
|
3 |
* Smart_Custom_Fields_Field_Wysiwyg
|
4 |
+
* Version : 1.0.1
|
5 |
* Author : Takashi Kitajima
|
6 |
* Created : October 7, 2014
|
7 |
+
* Modified : October 10, 2014
|
8 |
* License : GPLv2
|
9 |
* License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
*/
|
22 |
);
|
23 |
}
|
24 |
|
25 |
+
/**
|
26 |
+
* after_loaded
|
27 |
+
*/
|
28 |
+
protected function after_loaded() {
|
29 |
+
add_action( 'admin_footer', array( $this, 'admin_footer' ) );
|
30 |
+
}
|
31 |
+
public function admin_footer() {
|
32 |
+
?>
|
33 |
+
<div style="display:none;">
|
34 |
+
<?php wp_editor( '', SCF_Config::PREFIX . 'wysiwyg-base' ); ?>
|
35 |
+
</div>
|
36 |
+
<?php
|
37 |
+
}
|
38 |
+
|
39 |
/**
|
40 |
* get_field
|
41 |
* @param array $field フィールドの情報
|
css/settings.css
CHANGED
@@ -131,6 +131,10 @@
|
|
131 |
/** ==================================================
|
132 |
* #smart-cf-meta-box-condition
|
133 |
*/
|
|
|
|
|
|
|
|
|
134 |
#smart-cf-meta-box-condition label {
|
135 |
display: block;
|
136 |
margin: 0 0 5px;
|
131 |
/** ==================================================
|
132 |
* #smart-cf-meta-box-condition
|
133 |
*/
|
134 |
+
#smart-cf-meta-box-condition b {
|
135 |
+
display: block;
|
136 |
+
margin: 0 0 5px;
|
137 |
+
}
|
138 |
#smart-cf-meta-box-condition label {
|
139 |
display: block;
|
140 |
margin: 0 0 5px;
|
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.0
|
7 |
-
Stable tag: 1.0.
|
8 |
License: GPLv2
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
@@ -60,5 +60,10 @@ https://github.com/inc2734/smart-custom-fields/
|
|
60 |
|
61 |
== Changelog ==
|
62 |
|
|
|
|
|
|
|
|
|
|
|
63 |
= 1.0.0 =
|
64 |
* Initial release.
|
4 |
Tags: plugin, custom field, custom, field, meta, meta field, repeat, repeatable
|
5 |
Requires at least: 3.9
|
6 |
Tested up to: 4.0
|
7 |
+
Stable tag: 1.0.1
|
8 |
License: GPLv2
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
60 |
|
61 |
== Changelog ==
|
62 |
|
63 |
+
= 1.0.1 =
|
64 |
+
* Add display condition by post id.
|
65 |
+
* Fix bug that is not displayed wysiwyg editor when there are not content editor.
|
66 |
+
* Textarea does not filter the_content filter in SCF::get() and SCF::gets().
|
67 |
+
|
68 |
= 1.0.0 =
|
69 |
* Initial release.
|
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.0.
|
7 |
* Author: Takashi Kitajima
|
8 |
* Author URI: http://2inc.org
|
9 |
* Created: October 9, 2014
|
10 |
-
* Modified:
|
11 |
* Text Domain: smart-custom-fields
|
12 |
* Domain Path: /languages/
|
13 |
* License: GPLv2
|
@@ -48,7 +48,13 @@ class Smart_Custom_Fields {
|
|
48 |
public function plugins_loaded() {
|
49 |
do_action( SCF_Config::PREFIX . 'load' );
|
50 |
require_once plugin_dir_path( __FILE__ ) . 'classes/class.field-base.php';
|
51 |
-
require_once plugin_dir_path( __FILE__ ) . 'classes/
|
|
|
|
|
|
|
|
|
|
|
|
|
52 |
foreach ( glob( plugin_dir_path( __FILE__ ) . 'classes/fields/*.php' ) as $form_item ) {
|
53 |
include_once $form_item;
|
54 |
$basename = basename( $form_item, '.php' );
|
@@ -57,14 +63,6 @@ class Smart_Custom_Fields {
|
|
57 |
new $classname();
|
58 |
}
|
59 |
}
|
60 |
-
$this->fields = apply_filters( SCF_Config::PREFIX . 'add-fields', $this->fields );
|
61 |
-
|
62 |
-
require_once plugin_dir_path( __FILE__ ) . 'classes/class.settings.php';
|
63 |
-
require_once plugin_dir_path( __FILE__ ) . 'classes/class.revisions.php';
|
64 |
-
require_once plugin_dir_path( __FILE__ ) . 'classes/class.scf.php';
|
65 |
-
new Smart_Custom_Fields_Settings();
|
66 |
-
new Smart_Custom_Fields_Revisions();
|
67 |
-
new SCF();
|
68 |
|
69 |
add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
|
70 |
add_action( 'add_meta_boxes', array( $this, 'add_meta_boxes' ), 10, 2 );
|
@@ -169,7 +167,8 @@ class Smart_Custom_Fields {
|
|
169 |
* @param array $setings カスタムフィールドの設定情報
|
170 |
*/
|
171 |
public function display_meta_box( $post, $settings ) {
|
172 |
-
$
|
|
|
173 |
$tables = $this->get_tables( $post->ID, $groups );
|
174 |
|
175 |
printf( '<div class="%s">', esc_attr( SCF_Config::PREFIX . 'meta-box' ) );
|
@@ -242,11 +241,11 @@ class Smart_Custom_Fields {
|
|
242 |
foreach ( $group['fields'] as $field ) {
|
243 |
delete_post_meta( $post_id, $field['name'] );
|
244 |
|
245 |
-
if (
|
246 |
$multiple_data_fields[] = $field['name'];
|
247 |
}
|
248 |
|
249 |
-
if ( $is_repeat &&
|
250 |
$repeat_multiple_data_fields = $_POST[SCF_Config::NAME][$field['name']];
|
251 |
foreach ( $repeat_multiple_data_fields as $values ) {
|
252 |
if ( is_array( $values ) ) {
|
@@ -448,10 +447,10 @@ class Smart_Custom_Fields {
|
|
448 |
|
449 |
// 複数値許可フィールドのとき
|
450 |
$post_status = get_post_status( $post_id );
|
451 |
-
if (
|
452 |
$value = array();
|
453 |
if ( !SCF::is_empty( $field['default'] ) && ( $post_status === 'auto-draft' || is_null( $index ) ) ) {
|
454 |
-
$value = $
|
455 |
}
|
456 |
$_value = $this->get_multiple_data_field_value( $post_id, $field['name'], $index );
|
457 |
}
|
@@ -477,7 +476,7 @@ class Smart_Custom_Fields {
|
|
477 |
);
|
478 |
}
|
479 |
|
480 |
-
$form_field = $
|
481 |
printf(
|
482 |
'<tr><th>%s</th><td>%s%s</td></tr>',
|
483 |
esc_html( $field_label ),
|
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.0.1
|
7 |
* Author: Takashi Kitajima
|
8 |
* Author URI: http://2inc.org
|
9 |
* Created: October 9, 2014
|
10 |
+
* Modified: October 10, 2014
|
11 |
* Text Domain: smart-custom-fields
|
12 |
* Domain Path: /languages/
|
13 |
* License: GPLv2
|
48 |
public function plugins_loaded() {
|
49 |
do_action( SCF_Config::PREFIX . 'load' );
|
50 |
require_once plugin_dir_path( __FILE__ ) . 'classes/class.field-base.php';
|
51 |
+
require_once plugin_dir_path( __FILE__ ) . 'classes/class.settings.php';
|
52 |
+
require_once plugin_dir_path( __FILE__ ) . 'classes/class.revisions.php';
|
53 |
+
require_once plugin_dir_path( __FILE__ ) . 'classes/class.scf.php';
|
54 |
+
new Smart_Custom_Fields_Settings();
|
55 |
+
new Smart_Custom_Fields_Revisions();
|
56 |
+
new SCF();
|
57 |
+
|
58 |
foreach ( glob( plugin_dir_path( __FILE__ ) . 'classes/fields/*.php' ) as $form_item ) {
|
59 |
include_once $form_item;
|
60 |
$basename = basename( $form_item, '.php' );
|
63 |
new $classname();
|
64 |
}
|
65 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
66 |
|
67 |
add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
|
68 |
add_action( 'add_meta_boxes', array( $this, 'add_meta_boxes' ), 10, 2 );
|
167 |
* @param array $setings カスタムフィールドの設定情報
|
168 |
*/
|
169 |
public function display_meta_box( $post, $settings ) {
|
170 |
+
$_settings = SCF::get_settings( get_post_type() );
|
171 |
+
$groups = $_settings[$settings['id']];
|
172 |
$tables = $this->get_tables( $post->ID, $groups );
|
173 |
|
174 |
printf( '<div class="%s">', esc_attr( SCF_Config::PREFIX . 'meta-box' ) );
|
241 |
foreach ( $group['fields'] as $field ) {
|
242 |
delete_post_meta( $post_id, $field['name'] );
|
243 |
|
244 |
+
if ( $field['allow-multiple-data'] ) {
|
245 |
$multiple_data_fields[] = $field['name'];
|
246 |
}
|
247 |
|
248 |
+
if ( $is_repeat && $field['allow-multiple-data'] ) {
|
249 |
$repeat_multiple_data_fields = $_POST[SCF_Config::NAME][$field['name']];
|
250 |
foreach ( $repeat_multiple_data_fields as $values ) {
|
251 |
if ( is_array( $values ) ) {
|
447 |
|
448 |
// 複数値許可フィールドのとき
|
449 |
$post_status = get_post_status( $post_id );
|
450 |
+
if ( $field['allow-multiple-data'] ) {
|
451 |
$value = array();
|
452 |
if ( !SCF::is_empty( $field['default'] ) && ( $post_status === 'auto-draft' || is_null( $index ) ) ) {
|
453 |
+
$value = SCF::get_field_instance( $field['type'] )->get_choices( $field['default'] );
|
454 |
}
|
455 |
$_value = $this->get_multiple_data_field_value( $post_id, $field['name'], $index );
|
456 |
}
|
476 |
);
|
477 |
}
|
478 |
|
479 |
+
$form_field = SCF::get_field_instance( $field['type'] )->get_field( $field, $index, $value );
|
480 |
printf(
|
481 |
'<tr><th>%s</th><td>%s%s</td></tr>',
|
482 |
esc_html( $field_label ),
|