Version Description
- Refactoring
- Added meta data of custom options page.
Download this release
Release Info
Developer | inc2734 |
Plugin | Smart Custom Fields |
Version | 2.0.0 |
Comparing to | |
See all releases |
Code changes from version 1.7.0 to 2.0.0
- classes/class.scf.php +150 -257
- classes/controller/class.controller-base.php +6 -6
- classes/controller/class.option.php +75 -0
- classes/controller/class.profile.php +2 -2
- classes/controller/class.settings.php +39 -2
- classes/controller/class.taxonomy.php +5 -12
- classes/models/class.cache.php +249 -0
- classes/models/class.meta.php +16 -8
- classes/models/class.options-page.php +86 -0
- css/option.css +9 -0
- css/settings.css +6 -4
- languages/smart-custom-fields-ja.mo +0 -0
- languages/smart-custom-fields-ja.po +34 -23
- languages/smart-custom-fields.pot +34 -25
- readme.txt +53 -11
- smart-custom-fields.php +19 -18
classes/class.scf.php
CHANGED
@@ -1,10 +1,10 @@
|
|
1 |
<?php
|
2 |
/**
|
3 |
* SCF
|
4 |
-
* Version : 1.
|
5 |
* Author : inc2734
|
6 |
* Created : September 23, 2014
|
7 |
-
* Modified :
|
8 |
* License : GPLv2 or later
|
9 |
* License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
*/
|
@@ -17,42 +17,10 @@ class SCF {
|
|
17 |
protected static $fields = array();
|
18 |
|
19 |
/**
|
20 |
-
*
|
21 |
-
* Using post_id as key.
|
22 |
* @var array
|
23 |
*/
|
24 |
-
protected static $
|
25 |
-
|
26 |
-
/**
|
27 |
-
* Getting data proccesses is heavy. So saved getted data to $settings_posts_cache.
|
28 |
-
* Using post_type as key.
|
29 |
-
* @var array
|
30 |
-
*/
|
31 |
-
protected static $settings_posts_cache = array();
|
32 |
-
|
33 |
-
/**
|
34 |
-
* Getting data proccesses is heavy. So saved getted data to $settings_cache.
|
35 |
-
* Using post_type as key.
|
36 |
-
* @var array
|
37 |
-
*/
|
38 |
-
public static $settings_cache = array();
|
39 |
-
|
40 |
-
/**
|
41 |
-
* Getting data proccesses is heavy. So saved getted data to $repeat_multiple_data_cache.
|
42 |
-
* Using post_id as key.
|
43 |
-
* @var array
|
44 |
-
*/
|
45 |
-
protected static $repeat_multiple_data_cache = array();
|
46 |
-
|
47 |
-
/**
|
48 |
-
* Clear all caches.
|
49 |
-
*/
|
50 |
-
public static function clear_all_cache() {
|
51 |
-
self::clear_cache();
|
52 |
-
self::clear_settings_posts_cache();
|
53 |
-
self::clear_settings_cache();
|
54 |
-
self::clear_repeat_multiple_data_cache();
|
55 |
-
}
|
56 |
|
57 |
/**
|
58 |
* Getting all of the post meta data to feel good
|
@@ -91,14 +59,14 @@ class SCF {
|
|
91 |
if ( empty( $post_id ) ) {
|
92 |
return;
|
93 |
}
|
94 |
-
|
95 |
// Don't output meta data that not save in the SCF settings page
|
96 |
// Getting the settings data, judged to output meta data.
|
97 |
return self::get_meta( get_post( $post_id ), $name );
|
98 |
}
|
99 |
|
100 |
/**
|
101 |
-
|
102 |
*
|
103 |
* @param int $user_id
|
104 |
* @param string $name group name or field name
|
@@ -113,14 +81,14 @@ class SCF {
|
|
113 |
if ( $name === null ) {
|
114 |
return self::get_all_meta( get_userdata( $user_id ) );
|
115 |
}
|
116 |
-
|
117 |
// Don't output meta data that not save in the SCF settings page.
|
118 |
// Getting the settings data, judged to output meta data.
|
119 |
return self::get_meta( get_userdata( $user_id ), $name );
|
120 |
}
|
121 |
|
122 |
/**
|
123 |
-
|
124 |
*
|
125 |
* @param int $term_id
|
126 |
* @param string $taxonomy_name
|
@@ -136,23 +104,52 @@ class SCF {
|
|
136 |
if ( $name === null ) {
|
137 |
return self::get_all_meta( get_term( $term_id, $taxonomy_name ) );
|
138 |
}
|
139 |
-
|
140 |
// Don't output meta data that not save in the SCF settings page
|
141 |
// Getting the settings data, judged to output meta data.
|
142 |
return self::get_meta( get_term( $term_id, $taxonomy_name ), $name );
|
143 |
}
|
144 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
145 |
/**
|
146 |
* Getting any meta data to feel good
|
147 |
*
|
148 |
-
* @param WP_Post|WP_User|
|
149 |
* @param string $name group name or field name
|
150 |
* @return mixed
|
151 |
*/
|
152 |
protected static function get_meta( $object, $name ) {
|
153 |
-
|
|
|
154 |
self::debug_cache_message( "use get cache. [name: {$name}]" );
|
155 |
-
return
|
156 |
} else {
|
157 |
self::debug_cache_message( "dont use get cache... [name: {$name}]" );
|
158 |
}
|
@@ -163,10 +160,10 @@ class SCF {
|
|
163 |
$Group = $Setting->get_group( $name );
|
164 |
if ( $Group ) {
|
165 |
$values_by_group = self::get_values_by_group( $object, $Group );
|
166 |
-
|
167 |
return $values_by_group;
|
168 |
}
|
169 |
-
|
170 |
// If $name doesn't matche the group name, returns the field that matches.
|
171 |
$groups = $Setting->get_groups();
|
172 |
foreach ( $groups as $Group ) {
|
@@ -174,7 +171,7 @@ class SCF {
|
|
174 |
if ( $Field ) {
|
175 |
$is_repeatable = $Group->is_repeatable();
|
176 |
$value_by_field = self::get_value_by_field( $object, $Field, $is_repeatable );
|
177 |
-
|
178 |
return $value_by_field;
|
179 |
}
|
180 |
}
|
@@ -184,10 +181,11 @@ class SCF {
|
|
184 |
/**
|
185 |
* Getting all of any meta data to feel good
|
186 |
*
|
187 |
-
* @param WP_Post|WP_User|WP_Term $object
|
188 |
* @return mixed
|
189 |
*/
|
190 |
protected static function get_all_meta( $object ) {
|
|
|
191 |
$settings = self::get_settings( $object );
|
192 |
$post_meta = array();
|
193 |
foreach ( $settings as $Setting ) {
|
@@ -197,7 +195,7 @@ class SCF {
|
|
197 |
$group_name = $Group->get_name();
|
198 |
if ( $is_repeatable && $group_name ) {
|
199 |
$values_by_group = self::get_values_by_group( $object, $Group );
|
200 |
-
|
201 |
$post_meta[$group_name] = $values_by_group;
|
202 |
}
|
203 |
else {
|
@@ -205,7 +203,7 @@ class SCF {
|
|
205 |
foreach ( $fields as $Field ) {
|
206 |
$field_name = $Field->get( 'name' );
|
207 |
$value_by_field = self::get_value_by_field( $object, $Field, $is_repeatable );
|
208 |
-
|
209 |
$post_meta[$field_name] = $value_by_field;
|
210 |
}
|
211 |
}
|
@@ -230,60 +228,11 @@ class SCF {
|
|
230 |
return $post_id;
|
231 |
}
|
232 |
|
233 |
-
/**
|
234 |
-
* Saving to cache
|
235 |
-
*
|
236 |
-
* @param WP_Post|WP_User|WP_Term $object
|
237 |
-
* @param string $name
|
238 |
-
* @param mixed $data
|
239 |
-
*/
|
240 |
-
protected static function save_cache( $object, $name, $data ) {
|
241 |
-
$Meta = new Smart_Custom_Fields_Meta( $object );
|
242 |
-
$id = $Meta->get_id();
|
243 |
-
$type = $Meta->get_type();
|
244 |
-
$meta_type = $Meta->get_meta_type();
|
245 |
-
if ( !empty( $id ) && !empty( $type ) && !empty( $meta_type ) ) {
|
246 |
-
self::$cache[$meta_type . '_' . $type . '_' . $id][$name] = $data;
|
247 |
-
}
|
248 |
-
}
|
249 |
-
|
250 |
-
/**
|
251 |
-
* Getting the cache
|
252 |
-
*
|
253 |
-
* @param WP_Post|WP_User|WP_Term $object
|
254 |
-
* @param string $name
|
255 |
-
* @return mixed
|
256 |
-
*/
|
257 |
-
protected static function get_cache( $object, $name = null ) {
|
258 |
-
$Meta = new Smart_Custom_Fields_Meta( $object );
|
259 |
-
$id = $Meta->get_id();
|
260 |
-
$type = $Meta->get_type();
|
261 |
-
$meta_type = $Meta->get_meta_type();
|
262 |
-
if ( !empty( $id ) && !empty( $type ) && !empty( $meta_type ) ) {
|
263 |
-
if ( is_null( $name ) ) {
|
264 |
-
if ( isset( self::$cache[$meta_type . '_' . $type . '_' . $id] ) ) {
|
265 |
-
return self::$cache[$meta_type . '_' . $type . '_' . $id];
|
266 |
-
}
|
267 |
-
} else {
|
268 |
-
if ( isset( self::$cache[$meta_type . '_' . $type . '_' . $id][$name] ) ) {
|
269 |
-
return self::$cache[$meta_type . '_' . $type . '_' . $id][$name];
|
270 |
-
}
|
271 |
-
}
|
272 |
-
}
|
273 |
-
}
|
274 |
-
|
275 |
-
/**
|
276 |
-
* Clear caches
|
277 |
-
*/
|
278 |
-
public static function clear_cache() {
|
279 |
-
self::$cache = array();
|
280 |
-
}
|
281 |
-
|
282 |
/**
|
283 |
* Getting the meta data of the group
|
284 |
* When group, Note the point that returned data are repetition
|
285 |
*
|
286 |
-
* @param WP_Post|WP_User|WP_Term $object
|
287 |
* @param Smart_Custom_Fields_Group $Group
|
288 |
* @return mixed
|
289 |
*/
|
@@ -315,7 +264,7 @@ class SCF {
|
|
315 |
/**
|
316 |
* Getting the meta data of the field
|
317 |
*
|
318 |
-
* @param WP_Post|WP_User|WP_Term $object
|
319 |
* @param array $field
|
320 |
* @param bool $is_repeatable Whether the group that this field belongs is repetition
|
321 |
* @return mixed $post_meta
|
@@ -412,51 +361,17 @@ class SCF {
|
|
412 |
}
|
413 |
|
414 |
/**
|
415 |
-
*
|
416 |
-
*
|
417 |
-
* @param WP_Post|WP_User|WP_Term $object
|
418 |
-
* @param array $settings_posts
|
419 |
-
*/
|
420 |
-
protected static function save_settings_posts_cache( $object, $settings_posts ) {
|
421 |
-
$Meta = new Smart_Custom_Fields_Meta( $object );
|
422 |
-
$type = $Meta->get_type( false );
|
423 |
-
$meta_type = $Meta->get_meta_type();
|
424 |
-
self::$settings_posts_cache[$meta_type . '_' . $type] = $settings_posts;
|
425 |
-
}
|
426 |
-
|
427 |
-
/**
|
428 |
-
* Getting cache that enabled custom field settings in the post type or the role or the term.
|
429 |
-
*
|
430 |
-
* @param WP_Post|WP_User|WP_Term $object
|
431 |
-
* @return array|null
|
432 |
-
*/
|
433 |
-
public static function get_settings_posts_cache( $object ) {
|
434 |
-
$Meta = new Smart_Custom_Fields_Meta( $object );
|
435 |
-
$type = $Meta->get_type( false );
|
436 |
-
$meta_type = $Meta->get_meta_type();
|
437 |
-
if ( isset( self::$settings_posts_cache[$meta_type . '_' . $type] ) ) {
|
438 |
-
return self::$settings_posts_cache[$meta_type . '_' . $type];
|
439 |
-
}
|
440 |
-
}
|
441 |
-
|
442 |
-
/**
|
443 |
-
* Clear the $settings_posts_cache
|
444 |
-
*/
|
445 |
-
public static function clear_settings_posts_cache() {
|
446 |
-
self::$settings_posts_cache = array();
|
447 |
-
}
|
448 |
-
|
449 |
-
/**
|
450 |
-
* Getting enabled custom field settings in the post type or the role or the term.
|
451 |
*
|
452 |
-
* @param WP_Post|WP_User|WP_Term $object
|
453 |
* @return array $settings
|
454 |
*/
|
455 |
public static function get_settings_posts( $object ) {
|
|
|
456 |
$settings_posts = array();
|
457 |
-
if (
|
458 |
self::debug_cache_message( "use settings posts cache." );
|
459 |
-
return
|
460 |
} else {
|
461 |
self::debug_cache_message( "dont use settings posts cache..." );
|
462 |
}
|
@@ -474,6 +389,9 @@ class SCF {
|
|
474 |
case 'term' :
|
475 |
$key = SCF_Config::PREFIX . 'taxonomies';
|
476 |
break;
|
|
|
|
|
|
|
477 |
default :
|
478 |
$key = '';
|
479 |
}
|
@@ -493,73 +411,16 @@ class SCF {
|
|
493 |
),
|
494 |
) );
|
495 |
}
|
496 |
-
self::save_settings_posts_cache( $object, $settings_posts );
|
497 |
-
return $settings_posts;
|
498 |
-
}
|
499 |
|
500 |
-
|
501 |
-
|
502 |
-
|
503 |
-
* @param int $settings_post_id
|
504 |
-
* @param WP_post|WP_User|WP_term $object
|
505 |
-
* @param Smart_Custom_Fields_Setting $Setting
|
506 |
-
*/
|
507 |
-
protected static function save_settings_cache( $settings_post_id, $Setting, $object = null ) {
|
508 |
-
if ( !is_null( $object ) ) {
|
509 |
-
$Meta = new Smart_Custom_Fields_Meta( $object );
|
510 |
-
$id = $Meta->get_id();
|
511 |
-
$meta_type = $Meta->get_meta_type();
|
512 |
-
}
|
513 |
-
if ( !empty( $meta_type ) && !empty( $id ) ) {
|
514 |
-
self::$settings_cache[$settings_post_id][$meta_type . '_' . $id] = $Setting;
|
515 |
-
} else {
|
516 |
-
self::$settings_cache[$settings_post_id][0] = $Setting;
|
517 |
-
}
|
518 |
-
}
|
519 |
-
|
520 |
-
/**
|
521 |
-
* Getting the Setting object cache
|
522 |
-
* If there isn't the custom field settings ... null
|
523 |
-
* If there is custom field settings
|
524 |
-
* If there is no data for the specified $ meta_type + $id
|
525 |
-
* There is a thing of the General ... Smart_Custom_Fields_Setting
|
526 |
-
* There isn't a thing of the General ... false
|
527 |
-
* If there the data for the specified $meta_type + $id ... Smart_Custom_Fields_Setting
|
528 |
-
*
|
529 |
-
* @param int $settings_post_id
|
530 |
-
* @param WP_post|WP_User|WP_Term $object
|
531 |
-
* @return Smart_Custom_Fields_Setting|false|null
|
532 |
-
*/
|
533 |
-
public static function get_settings_cache( $settings_post_id, $object = null ) {
|
534 |
-
if ( !is_null( $object ) ) {
|
535 |
-
$Meta = new Smart_Custom_Fields_Meta( $object );
|
536 |
-
$id = $Meta->get_id();
|
537 |
-
$meta_type = $Meta->get_meta_type();
|
538 |
-
}
|
539 |
-
|
540 |
-
if ( isset( self::$settings_cache[$settings_post_id] ) ) {
|
541 |
-
$settings_cache = self::$settings_cache[$settings_post_id];
|
542 |
-
if ( !empty( $id ) && !empty( $meta_type ) && isset( $settings_cache[$meta_type . '_' . $id] ) ) {
|
543 |
-
return $settings_cache[$meta_type . '_' . $id];
|
544 |
-
}
|
545 |
-
if ( isset( $settings_cache[0] ) ) {
|
546 |
-
return $settings_cache[0];
|
547 |
-
}
|
548 |
-
return false;
|
549 |
-
}
|
550 |
-
}
|
551 |
-
|
552 |
-
/**
|
553 |
-
* Clear the $settings_cache
|
554 |
-
*/
|
555 |
-
public static function clear_settings_cache() {
|
556 |
-
self::$settings_cache = array();
|
557 |
}
|
558 |
|
559 |
/**
|
560 |
* Getting array of the Setting object
|
561 |
*
|
562 |
-
* @param WP_Post|WP_User|WP_Term $object
|
563 |
* @return array $settings
|
564 |
*/
|
565 |
public static function get_settings( $object ) {
|
@@ -567,7 +428,7 @@ class SCF {
|
|
567 |
$id = $Meta->get_id();
|
568 |
$type = $Meta->get_type( false );
|
569 |
$meta_type = $Meta->get_meta_type();
|
570 |
-
|
571 |
// IF the post that has custom field settings according to post ID,
|
572 |
// don't display because the post ID would change in preview.
|
573 |
// So if in preview, re-getting post ID from original post (parent of the preview).
|
@@ -587,6 +448,9 @@ class SCF {
|
|
587 |
elseif ( $meta_type === 'term' ) {
|
588 |
$settings = self::get_settings_for_term( $object, $settings_posts );
|
589 |
}
|
|
|
|
|
|
|
590 |
}
|
591 |
$settings = apply_filters(
|
592 |
SCF_Config::PREFIX . 'register-fields',
|
@@ -609,11 +473,12 @@ class SCF {
|
|
609 |
* @return array
|
610 |
*/
|
611 |
protected static function get_settings_for_post( $object, $settings_posts ) {
|
|
|
612 |
$settings = array();
|
613 |
foreach ( $settings_posts as $settings_post ) {
|
614 |
-
if (
|
615 |
self::debug_cache_message( "use settings cache. [id: {$settings_post->ID}]" );
|
616 |
-
$Setting =
|
617 |
if ( $Setting ) {
|
618 |
$settings[$settings_post->ID] = $Setting;
|
619 |
}
|
@@ -635,46 +500,45 @@ class SCF {
|
|
635 |
}
|
636 |
$Post = get_post( $condition_post_id );
|
637 |
if ( empty( $Post ) ) {
|
638 |
-
$Post =
|
639 |
-
$Post->ID = $condition_post_id;
|
640 |
-
$Post = new WP_Post( $Post );
|
641 |
}
|
642 |
-
|
643 |
}
|
644 |
} else {
|
645 |
$Setting = SCF::add_setting( $settings_post->ID, $settings_post->post_title );
|
646 |
$settings[$settings_post->ID] = $Setting;
|
647 |
-
|
648 |
}
|
649 |
}
|
650 |
return $settings;
|
651 |
}
|
652 |
|
653 |
/**
|
654 |
-
|
655 |
*
|
656 |
* @param WP_User $object
|
657 |
* @param array $settings_posts
|
658 |
* @return array
|
659 |
*/
|
660 |
protected static function get_settings_for_profile( $object, $settings_posts ) {
|
|
|
661 |
$settings = array();
|
662 |
foreach ( $settings_posts as $settings_post ) {
|
663 |
-
if (
|
664 |
self::debug_cache_message( "use settings cache. [id: {$settings_post->ID}]" );
|
665 |
-
$settings[] =
|
666 |
continue;
|
667 |
}
|
668 |
self::debug_cache_message( "dont use settings cache... [id: {$settings_post->ID}]" );
|
669 |
$Setting = SCF::add_setting( $settings_post->ID, $settings_post->post_title );
|
670 |
$settings[] = $Setting;
|
671 |
-
|
672 |
}
|
673 |
return $settings;
|
674 |
}
|
675 |
|
676 |
/**
|
677 |
-
|
678 |
*
|
679 |
* @param WP_Term $object
|
680 |
* @param array $settings_posts
|
@@ -685,56 +549,27 @@ class SCF {
|
|
685 |
}
|
686 |
|
687 |
/**
|
688 |
-
*
|
689 |
*
|
690 |
-
* @param
|
691 |
-
* @param
|
692 |
-
|
693 |
-
protected static function save_repeat_multiple_data_cache( $object, $repeat_multiple_data ) {
|
694 |
-
$Meta = new Smart_Custom_Fields_Meta( $object );
|
695 |
-
$id = $Meta->get_id();
|
696 |
-
$type = $Meta->get_type();
|
697 |
-
$meta_type = $Meta->get_meta_type();
|
698 |
-
if ( !empty( $id ) && !empty( $type ) && !empty( $meta_type ) ) {
|
699 |
-
self::$repeat_multiple_data_cache[$meta_type . '_' . $type . '_' . $id] = $repeat_multiple_data;
|
700 |
-
}
|
701 |
-
}
|
702 |
-
|
703 |
-
/**
|
704 |
-
* Getting delimited identification data of the repeated multi-value items from cache
|
705 |
-
*
|
706 |
-
* @param WP_Post|WP_User|WP_Term $object
|
707 |
-
* @return mixed
|
708 |
-
*/
|
709 |
-
protected static function get_repeat_multiple_data_cache( $object ) {
|
710 |
-
$Meta = new Smart_Custom_Fields_Meta( $object );
|
711 |
-
$id = $Meta->get_id();
|
712 |
-
$type = $Meta->get_type();
|
713 |
-
$meta_type = $Meta->get_meta_type();
|
714 |
-
if ( !empty( $id ) && !empty( $type ) ) {
|
715 |
-
if ( isset( self::$repeat_multiple_data_cache[$meta_type . '_' . $type . '_' . $id] ) ) {
|
716 |
-
return self::$repeat_multiple_data_cache[$meta_type . '_' . $type . '_' . $id];
|
717 |
-
}
|
718 |
-
}
|
719 |
-
}
|
720 |
-
|
721 |
-
/**
|
722 |
-
* Clear delimited identification data of the repeated multi-value items cache
|
723 |
*/
|
724 |
-
|
725 |
-
self
|
726 |
}
|
727 |
|
728 |
/**
|
729 |
-
|
730 |
*
|
731 |
-
* @param WP_Post|WP_User|WP_Term $object
|
732 |
* @return array
|
733 |
*/
|
734 |
public static function get_repeat_multiple_data( $object ) {
|
|
|
735 |
$repeat_multiple_data = array();
|
736 |
-
if (
|
737 |
-
return
|
738 |
}
|
739 |
|
740 |
$Meta = new Smart_Custom_Fields_Meta( $object );
|
@@ -743,7 +578,7 @@ class SCF {
|
|
743 |
$repeat_multiple_data = $_repeat_multiple_data;
|
744 |
}
|
745 |
|
746 |
-
|
747 |
return $repeat_multiple_data;
|
748 |
}
|
749 |
|
@@ -804,7 +639,7 @@ class SCF {
|
|
804 |
* Getting custom fields that saved custo field settings page
|
805 |
* Note that not return only one even define multiple fields with the same name of the field name
|
806 |
*
|
807 |
-
* @param WP_Post|WP_User|WP_Term $object
|
808 |
* @param string $field_name
|
809 |
* @return Smart_Custom_Fields_Field_Base|null
|
810 |
*/
|
@@ -817,7 +652,7 @@ class SCF {
|
|
817 |
}
|
818 |
}
|
819 |
}
|
820 |
-
|
821 |
/**
|
822 |
* Convert to array from newline delimiter $choices
|
823 |
*
|
@@ -846,6 +681,64 @@ class SCF {
|
|
846 |
return new Smart_Custom_Fields_Setting( $id, $title );
|
847 |
}
|
848 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
849 |
/**
|
850 |
* Print cache usage
|
851 |
*/
|
1 |
<?php
|
2 |
/**
|
3 |
* SCF
|
4 |
+
* Version : 1.4.0
|
5 |
* Author : inc2734
|
6 |
* Created : September 23, 2014
|
7 |
+
* Modified : Mau 31, 2016
|
8 |
* License : GPLv2 or later
|
9 |
* License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
*/
|
17 |
protected static $fields = array();
|
18 |
|
19 |
/**
|
20 |
+
* Array of the custom options pages.
|
|
|
21 |
* @var array
|
22 |
*/
|
23 |
+
protected static $options_pages = array();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
|
25 |
/**
|
26 |
* Getting all of the post meta data to feel good
|
59 |
if ( empty( $post_id ) ) {
|
60 |
return;
|
61 |
}
|
62 |
+
|
63 |
// Don't output meta data that not save in the SCF settings page
|
64 |
// Getting the settings data, judged to output meta data.
|
65 |
return self::get_meta( get_post( $post_id ), $name );
|
66 |
}
|
67 |
|
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
|
81 |
if ( $name === null ) {
|
82 |
return self::get_all_meta( get_userdata( $user_id ) );
|
83 |
}
|
84 |
+
|
85 |
// Don't output meta data that not save in the SCF settings page.
|
86 |
// Getting the settings data, judged to output meta data.
|
87 |
return self::get_meta( get_userdata( $user_id ), $name );
|
88 |
}
|
89 |
|
90 |
/**
|
91 |
+
* Getting the term meta data to feel good
|
92 |
*
|
93 |
* @param int $term_id
|
94 |
* @param string $taxonomy_name
|
104 |
if ( $name === null ) {
|
105 |
return self::get_all_meta( get_term( $term_id, $taxonomy_name ) );
|
106 |
}
|
107 |
+
|
108 |
// Don't output meta data that not save in the SCF settings page
|
109 |
// Getting the settings data, judged to output meta data.
|
110 |
return self::get_meta( get_term( $term_id, $taxonomy_name ), $name );
|
111 |
}
|
112 |
|
113 |
+
/**
|
114 |
+
* Getting the custom options page meta data to feel good
|
115 |
+
*
|
116 |
+
* @param string $menu_slug custom options page slug
|
117 |
+
* @param string $name group name or field name
|
118 |
+
* @return mixed
|
119 |
+
*/
|
120 |
+
public static function get_option_meta( $menu_slug, $name = null ) {
|
121 |
+
if ( empty( $menu_slug ) ) {
|
122 |
+
return;
|
123 |
+
}
|
124 |
+
|
125 |
+
if ( !isset( self::$options_pages[$menu_slug] ) ) {
|
126 |
+
return;
|
127 |
+
}
|
128 |
+
|
129 |
+
$Option = self::generate_option_object( $menu_slug );
|
130 |
+
|
131 |
+
// If $name is null, return the all meta data.
|
132 |
+
if ( $name === null ) {
|
133 |
+
return self::get_all_meta( $Option );
|
134 |
+
}
|
135 |
+
|
136 |
+
// Don't output meta data that not save in the SCF settings page
|
137 |
+
// Getting the settings data, judged to output meta data.
|
138 |
+
return self::get_meta( $Option, $name );
|
139 |
+
}
|
140 |
+
|
141 |
/**
|
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 ) {
|
149 |
+
$Cache = Smart_Custom_Fields_Cache::getInstance();
|
150 |
+
if ( $Cache->get_meta( $object, $name ) ) {
|
151 |
self::debug_cache_message( "use get cache. [name: {$name}]" );
|
152 |
+
return $Cache->get_meta( $object, $name );
|
153 |
} else {
|
154 |
self::debug_cache_message( "dont use get cache... [name: {$name}]" );
|
155 |
}
|
160 |
$Group = $Setting->get_group( $name );
|
161 |
if ( $Group ) {
|
162 |
$values_by_group = self::get_values_by_group( $object, $Group );
|
163 |
+
$Cache->save_meta( $object, $name, $values_by_group );
|
164 |
return $values_by_group;
|
165 |
}
|
166 |
+
|
167 |
// If $name doesn't matche the group name, returns the field that matches.
|
168 |
$groups = $Setting->get_groups();
|
169 |
foreach ( $groups as $Group ) {
|
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;
|
176 |
}
|
177 |
}
|
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 ) {
|
195 |
$group_name = $Group->get_name();
|
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 {
|
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 |
}
|
228 |
return $post_id;
|
229 |
}
|
230 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
231 |
/**
|
232 |
* Getting the meta data of the group
|
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 |
*/
|
264 |
/**
|
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
|
361 |
}
|
362 |
|
363 |
/**
|
364 |
+
* Getting enabled custom field settings in the post type or the role or the term.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
365 |
*
|
366 |
+
* @param WP_Post|WP_User|WP_Term|stdClass $object
|
367 |
* @return array $settings
|
368 |
*/
|
369 |
public static function get_settings_posts( $object ) {
|
370 |
+
$Cache = Smart_Custom_Fields_Cache::getInstance();
|
371 |
$settings_posts = array();
|
372 |
+
if ( $Cache->get_settings_posts( $object ) !== null ) {
|
373 |
self::debug_cache_message( "use settings posts cache." );
|
374 |
+
return $Cache->get_settings_posts( $object );
|
375 |
} else {
|
376 |
self::debug_cache_message( "dont use settings posts cache..." );
|
377 |
}
|
389 |
case 'term' :
|
390 |
$key = SCF_Config::PREFIX . 'taxonomies';
|
391 |
break;
|
392 |
+
case 'option' :
|
393 |
+
$key = SCF_Config::PREFIX . 'options-pages';
|
394 |
+
break;
|
395 |
default :
|
396 |
$key = '';
|
397 |
}
|
411 |
),
|
412 |
) );
|
413 |
}
|
|
|
|
|
|
|
414 |
|
415 |
+
$Cache = Smart_Custom_Fields_Cache::getInstance();
|
416 |
+
$Cache->save_settings_posts( $object, $settings_posts );
|
417 |
+
return $settings_posts;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
418 |
}
|
419 |
|
420 |
/**
|
421 |
* Getting array of the Setting object
|
422 |
*
|
423 |
+
* @param WP_Post|WP_User|WP_Term|Smart_Custom_Fields_Options_Mock $object
|
424 |
* @return array $settings
|
425 |
*/
|
426 |
public static function get_settings( $object ) {
|
428 |
$id = $Meta->get_id();
|
429 |
$type = $Meta->get_type( false );
|
430 |
$meta_type = $Meta->get_meta_type();
|
431 |
+
|
432 |
// IF the post that has custom field settings according to post ID,
|
433 |
// don't display because the post ID would change in preview.
|
434 |
// So if in preview, re-getting post ID from original post (parent of the preview).
|
448 |
elseif ( $meta_type === 'term' ) {
|
449 |
$settings = self::get_settings_for_term( $object, $settings_posts );
|
450 |
}
|
451 |
+
elseif ( $meta_type === 'option' ) {
|
452 |
+
$settings = self::get_settings_for_option( $object, $settings_posts );
|
453 |
+
}
|
454 |
}
|
455 |
$settings = apply_filters(
|
456 |
SCF_Config::PREFIX . 'register-fields',
|
473 |
* @return array
|
474 |
*/
|
475 |
protected static function get_settings_for_post( $object, $settings_posts ) {
|
476 |
+
$Cache = Smart_Custom_Fields_Cache::getInstance();
|
477 |
$settings = array();
|
478 |
foreach ( $settings_posts as $settings_post ) {
|
479 |
+
if ( $Cache->get_settings( $settings_post->ID ) !== null ) {
|
480 |
self::debug_cache_message( "use settings cache. [id: {$settings_post->ID}]" );
|
481 |
+
$Setting = $Cache->get_settings( $settings_post->ID, $object );
|
482 |
if ( $Setting ) {
|
483 |
$settings[$settings_post->ID] = $Setting;
|
484 |
}
|
500 |
}
|
501 |
$Post = get_post( $condition_post_id );
|
502 |
if ( empty( $Post ) ) {
|
503 |
+
$Post = self::generate_post_object( $condition_post_id );
|
|
|
|
|
504 |
}
|
505 |
+
$Cache->save_settings( $settings_post->ID, $Setting, $Post );
|
506 |
}
|
507 |
} else {
|
508 |
$Setting = SCF::add_setting( $settings_post->ID, $settings_post->post_title );
|
509 |
$settings[$settings_post->ID] = $Setting;
|
510 |
+
$Cache->save_settings( $settings_post->ID, $Setting );
|
511 |
}
|
512 |
}
|
513 |
return $settings;
|
514 |
}
|
515 |
|
516 |
/**
|
517 |
+
* Getting the Setting object for user
|
518 |
*
|
519 |
* @param WP_User $object
|
520 |
* @param array $settings_posts
|
521 |
* @return array
|
522 |
*/
|
523 |
protected static function get_settings_for_profile( $object, $settings_posts ) {
|
524 |
+
$Cache = Smart_Custom_Fields_Cache::getInstance();
|
525 |
$settings = array();
|
526 |
foreach ( $settings_posts as $settings_post ) {
|
527 |
+
if ( $Cache->get_settings( $settings_post->ID ) !== null ) {
|
528 |
self::debug_cache_message( "use settings cache. [id: {$settings_post->ID}]" );
|
529 |
+
$settings[] = $Cache->get_settings( $settings_post->ID );
|
530 |
continue;
|
531 |
}
|
532 |
self::debug_cache_message( "dont use settings cache... [id: {$settings_post->ID}]" );
|
533 |
$Setting = SCF::add_setting( $settings_post->ID, $settings_post->post_title );
|
534 |
$settings[] = $Setting;
|
535 |
+
$Cache->save_settings( $settings_post->ID, $Setting );
|
536 |
}
|
537 |
return $settings;
|
538 |
}
|
539 |
|
540 |
/**
|
541 |
+
* Getting the Setting object for term
|
542 |
*
|
543 |
* @param WP_Term $object
|
544 |
* @param array $settings_posts
|
549 |
}
|
550 |
|
551 |
/**
|
552 |
+
* Getting the Setting object for option
|
553 |
*
|
554 |
+
* @param WP_Term $object
|
555 |
+
* @param array $settings_posts
|
556 |
+
* @return array
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
557 |
*/
|
558 |
+
protected static function get_settings_for_option( $object, $settings_posts ) {
|
559 |
+
return self::get_settings_for_profile( $object, $settings_posts );
|
560 |
}
|
561 |
|
562 |
/**
|
563 |
+
* Getting delimited identification data of the repeated multi-value items
|
564 |
*
|
565 |
+
* @param WP_Post|WP_User|WP_Term|stdClass $object
|
566 |
* @return array
|
567 |
*/
|
568 |
public static function get_repeat_multiple_data( $object ) {
|
569 |
+
$Cache = Smart_Custom_Fields_Cache::getInstance();
|
570 |
$repeat_multiple_data = array();
|
571 |
+
if ( $Cache->get_repeat_multiple_data( $object ) ) {
|
572 |
+
return $Cache->get_repeat_multiple_data( $object );
|
573 |
}
|
574 |
|
575 |
$Meta = new Smart_Custom_Fields_Meta( $object );
|
578 |
$repeat_multiple_data = $_repeat_multiple_data;
|
579 |
}
|
580 |
|
581 |
+
$Cache->save_repeat_multiple_data( $object, $repeat_multiple_data );
|
582 |
return $repeat_multiple_data;
|
583 |
}
|
584 |
|
639 |
* Getting custom fields that saved custo field settings page
|
640 |
* Note that not return only one even define multiple fields with the same name of the field name
|
641 |
*
|
642 |
+
* @param WP_Post|WP_User|WP_Term|stdClass $object
|
643 |
* @param string $field_name
|
644 |
* @return Smart_Custom_Fields_Field_Base|null
|
645 |
*/
|
652 |
}
|
653 |
}
|
654 |
}
|
655 |
+
|
656 |
/**
|
657 |
* Convert to array from newline delimiter $choices
|
658 |
*
|
681 |
return new Smart_Custom_Fields_Setting( $id, $title );
|
682 |
}
|
683 |
|
684 |
+
/**
|
685 |
+
* Adding custom options page
|
686 |
+
*
|
687 |
+
* @see https://developer.wordpress.org/reference/functions/add_menu_page/
|
688 |
+
* @param string $page_title
|
689 |
+
* @param string $menu_title
|
690 |
+
* @param string $capability
|
691 |
+
* @param string $menu_slug
|
692 |
+
* @param string $icon_url
|
693 |
+
* @param int $position
|
694 |
+
* @return $menu_slug
|
695 |
+
*/
|
696 |
+
public static function add_options_page( $page_title, $menu_title, $capability, $menu_slug, $icon_url = '', $position = null ) {
|
697 |
+
self::$options_pages[$menu_slug] = $menu_title;
|
698 |
+
new Smart_Custom_Fields_Options_Page( $page_title, $menu_title, $capability, $menu_slug, $icon_url = '', $position = null );
|
699 |
+
return $menu_slug;
|
700 |
+
}
|
701 |
+
|
702 |
+
/**
|
703 |
+
* Return array of custom options pages
|
704 |
+
*
|
705 |
+
* @return array
|
706 |
+
*/
|
707 |
+
public static function get_options_pages() {
|
708 |
+
return self::$options_pages;
|
709 |
+
}
|
710 |
+
|
711 |
+
/**
|
712 |
+
* Generate WP_Post object
|
713 |
+
*
|
714 |
+
* @param int $post_id
|
715 |
+
* @param string $post_type
|
716 |
+
* @return WP_Post
|
717 |
+
*/
|
718 |
+
public static function generate_post_object( $post_id, $post_type = null ) {
|
719 |
+
$Post = new stdClass();
|
720 |
+
$Post->ID = $post_id;
|
721 |
+
$Post->post_type = $post_type;
|
722 |
+
return new WP_Post( $Post );
|
723 |
+
}
|
724 |
+
|
725 |
+
/**
|
726 |
+
* Generate option object
|
727 |
+
*
|
728 |
+
* @param string $menu_slug
|
729 |
+
* @return stdClass
|
730 |
+
*/
|
731 |
+
public static function generate_option_object( $menu_slug ) {
|
732 |
+
$options_pages = SCF::get_options_pages();
|
733 |
+
if ( !isset( $options_pages[$menu_slug] ) ) {
|
734 |
+
return;
|
735 |
+
}
|
736 |
+
$Option = new stdClass();
|
737 |
+
$Option->menu_slug = $menu_slug;
|
738 |
+
$Option->menu_title = $options_pages[$menu_slug];
|
739 |
+
return $Option;
|
740 |
+
}
|
741 |
+
|
742 |
/**
|
743 |
* Print cache usage
|
744 |
*/
|
classes/controller/class.controller-base.php
CHANGED
@@ -62,7 +62,7 @@ class Smart_Custom_Fields_Controller_Base {
|
|
62 |
/**
|
63 |
* Display custom fields in edit page.
|
64 |
*
|
65 |
-
* @param WP_Post|WP_User|WP_Term $object
|
66 |
* @param array $callback_args custom field setting information
|
67 |
*/
|
68 |
public function display_meta_box( $object, $callback_args ) {
|
@@ -103,7 +103,7 @@ class Smart_Custom_Fields_Controller_Base {
|
|
103 |
* Saving posted data
|
104 |
*
|
105 |
* @param array $data
|
106 |
-
* @param WP_Post|WP_User|WP_Term $object
|
107 |
*/
|
108 |
protected function save( $data, $object ) {
|
109 |
check_admin_referer(
|
@@ -118,7 +118,7 @@ class Smart_Custom_Fields_Controller_Base {
|
|
118 |
/**
|
119 |
* Generating array for displaying the custom fields
|
120 |
*
|
121 |
-
* @param WP_Post|WP_User|WP_Term $object
|
122 |
* @param array $groups Settings from custom field settings page
|
123 |
* @return array $tables Array for displaying a table for custom fields
|
124 |
*/
|
@@ -173,7 +173,7 @@ class Smart_Custom_Fields_Controller_Base {
|
|
173 |
/**
|
174 |
* Getting the multi-value field meta data.
|
175 |
*
|
176 |
-
* @param WP_Post|WP_User|WP_Term $object
|
177 |
* @param Smart_Custom_Fields_Field_Base $Field
|
178 |
* @param int $index
|
179 |
* @return array or null
|
@@ -217,7 +217,7 @@ class Smart_Custom_Fields_Controller_Base {
|
|
217 |
/**
|
218 |
* Getting the non multi-value field meta data.
|
219 |
*
|
220 |
-
* @param WP_Post|WP_User|WP_Term $object
|
221 |
* @param Smart_Custom_Fields_Field_Base $Field
|
222 |
* @param int $index
|
223 |
* @return string or null
|
@@ -243,7 +243,7 @@ class Smart_Custom_Fields_Controller_Base {
|
|
243 |
/**
|
244 |
* Displaying tr element for table of custom fields
|
245 |
*
|
246 |
-
* @param WP_Post|WP_User|WP_Term $object
|
247 |
* @param bool $is_repeat
|
248 |
* @param array $fields
|
249 |
* @param int, null $index
|
62 |
/**
|
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 ) {
|
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 ) {
|
109 |
check_admin_referer(
|
118 |
/**
|
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 |
*/
|
173 |
/**
|
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 or null
|
217 |
/**
|
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 or null
|
243 |
/**
|
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
|
classes/controller/class.option.php
ADDED
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Smart_Custom_Fields_Controller_Option
|
4 |
+
* Version : 1.0.0
|
5 |
+
* Author : inc2734
|
6 |
+
* Created : May 29, 2014
|
7 |
+
* Modified :
|
8 |
+
* License : GPLv2 or later
|
9 |
+
* License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
+
*/
|
11 |
+
class Smart_Custom_Fields_Controller_Option extends Smart_Custom_Fields_Controller_Base {
|
12 |
+
|
13 |
+
/**
|
14 |
+
* __construct
|
15 |
+
*/
|
16 |
+
public function __construct() {
|
17 |
+
parent::__construct();
|
18 |
+
add_action( SCF_Config::PREFIX . 'custom-options-page', array( $this, 'save_option' ) );
|
19 |
+
add_action( SCF_Config::PREFIX . 'custom-options-page', array( $this, 'custom_options_page' ) );
|
20 |
+
}
|
21 |
+
|
22 |
+
/**
|
23 |
+
* Loading resources for term edit page
|
24 |
+
*
|
25 |
+
* @param string $hook
|
26 |
+
*/
|
27 |
+
public function admin_enqueue_scripts( $hook ) {
|
28 |
+
parent::admin_enqueue_scripts( $hook );
|
29 |
+
wp_enqueue_style(
|
30 |
+
SCF_Config::PREFIX . 'option',
|
31 |
+
plugins_url( SCF_Config::NAME ) . '/css/option.css'
|
32 |
+
);
|
33 |
+
}
|
34 |
+
|
35 |
+
/**
|
36 |
+
* Displaying custom fields in custom options page
|
37 |
+
*
|
38 |
+
* @param stdClass $Option
|
39 |
+
*/
|
40 |
+
public function custom_options_page( $Option ) {
|
41 |
+
$settings = SCF::get_settings( $Option );
|
42 |
+
if ( !$settings ) {
|
43 |
+
return;
|
44 |
+
}
|
45 |
+
?>
|
46 |
+
<form method="post" action="">
|
47 |
+
<?php foreach ( $settings as $Setting ) : ?>
|
48 |
+
<?php $callback_args['args'] = $Setting->get_groups(); ?>
|
49 |
+
<table class="form-table">
|
50 |
+
<tr>
|
51 |
+
<th scope="row"><?php echo esc_html( $Setting->get_title() ); ?></th>
|
52 |
+
<td><?php $this->display_meta_box( $Option, $callback_args ); ?></td>
|
53 |
+
</tr>
|
54 |
+
</table>
|
55 |
+
<?php endforeach; ?>
|
56 |
+
<p class="submit">
|
57 |
+
<input type="submit" name="submit" id="submit" class="button button-primary" value="<?php esc_attr_e( 'Save settings', 'smart-custom-fields' ); ?>">
|
58 |
+
</p>
|
59 |
+
</form>
|
60 |
+
<?php
|
61 |
+
}
|
62 |
+
|
63 |
+
/**
|
64 |
+
* Saving meta data from custom fields in custom options page
|
65 |
+
*
|
66 |
+
* @param stdClass $Option
|
67 |
+
*/
|
68 |
+
public function save_option( $Option ) {
|
69 |
+
if ( !isset( $_POST[SCF_Config::NAME] ) ) {
|
70 |
+
return;
|
71 |
+
}
|
72 |
+
|
73 |
+
$this->save( $_POST, $Option );
|
74 |
+
}
|
75 |
+
}
|
classes/controller/class.profile.php
CHANGED
@@ -23,7 +23,7 @@ class Smart_Custom_Fields_Controller_Profile extends Smart_Custom_Fields_Control
|
|
23 |
|
24 |
/**
|
25 |
* Loading resources for profile edit page
|
26 |
-
*
|
27 |
* @param string $hook
|
28 |
*/
|
29 |
public function admin_enqueue_scripts( $hook ) {
|
@@ -57,7 +57,7 @@ class Smart_Custom_Fields_Controller_Profile extends Smart_Custom_Fields_Control
|
|
57 |
|
58 |
/**
|
59 |
* Saving meta data from custom fields in profile edit page.
|
60 |
-
*
|
61 |
* @param int $user_id
|
62 |
*/
|
63 |
public function update( $user_id ) {
|
23 |
|
24 |
/**
|
25 |
* Loading resources for profile edit page
|
26 |
+
*
|
27 |
* @param string $hook
|
28 |
*/
|
29 |
public function admin_enqueue_scripts( $hook ) {
|
57 |
|
58 |
/**
|
59 |
* Saving meta data from custom fields in profile edit page.
|
60 |
+
*
|
61 |
* @param int $user_id
|
62 |
*/
|
63 |
public function update( $user_id ) {
|
classes/controller/class.settings.php
CHANGED
@@ -1,10 +1,10 @@
|
|
1 |
<?php
|
2 |
/**
|
3 |
* Smart_Custom_Fields_Controller_Settings
|
4 |
-
* Version : 1.
|
5 |
* Author : inc2734
|
6 |
* Created : September 23, 2014
|
7 |
-
* Modified :
|
8 |
* License : GPLv2 or later
|
9 |
* License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
*/
|
@@ -98,6 +98,13 @@ class Smart_Custom_Fields_Controller_Settings {
|
|
98 |
SCF_Config::NAME,
|
99 |
'side'
|
100 |
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
101 |
}
|
102 |
|
103 |
/**
|
@@ -285,6 +292,30 @@ class Smart_Custom_Fields_Controller_Settings {
|
|
285 |
);
|
286 |
}
|
287 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
288 |
/**
|
289 |
* Saving settings
|
290 |
*
|
@@ -364,5 +395,11 @@ class Smart_Custom_Fields_Controller_Settings {
|
|
364 |
} else {
|
365 |
update_post_meta( $post_id, SCF_Config::PREFIX . 'taxonomies', $_POST[SCF_Config::PREFIX . 'taxonomies'] );
|
366 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
367 |
}
|
368 |
}
|
1 |
<?php
|
2 |
/**
|
3 |
* Smart_Custom_Fields_Controller_Settings
|
4 |
+
* Version : 1.3.0
|
5 |
* Author : inc2734
|
6 |
* Created : September 23, 2014
|
7 |
+
* Modified : May 31, 2016
|
8 |
* License : GPLv2 or later
|
9 |
* License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
*/
|
98 |
SCF_Config::NAME,
|
99 |
'side'
|
100 |
);
|
101 |
+
add_meta_box(
|
102 |
+
SCF_Config::PREFIX . 'meta-box-condition-options-page',
|
103 |
+
__( 'Display conditions ( Options page )', 'smart-custom-fields' ),
|
104 |
+
array( $this, 'display_meta_box_condition_options_page' ),
|
105 |
+
SCF_Config::NAME,
|
106 |
+
'side'
|
107 |
+
);
|
108 |
}
|
109 |
|
110 |
/**
|
292 |
);
|
293 |
}
|
294 |
|
295 |
+
/**
|
296 |
+
* Displaying the meta box to set the display conditions for custom options page
|
297 |
+
*/
|
298 |
+
public function display_meta_box_condition_options_page() {
|
299 |
+
$optinos_pages = SCF::get_options_pages();
|
300 |
+
$conditions = get_post_meta( get_the_ID(), SCF_Config::PREFIX . 'options-pages', true );
|
301 |
+
$options_page_field = '';
|
302 |
+
foreach ( $optinos_pages as $name => $optinos_page ) {
|
303 |
+
$current = ( is_array( $conditions ) && in_array( $name, $conditions ) ) ? $name : false;
|
304 |
+
$options_page_field .= sprintf(
|
305 |
+
'<label><input type="checkbox" name="%s" value="%s" %s /> %s</label>',
|
306 |
+
esc_attr( SCF_Config::PREFIX . 'options-pages[]' ),
|
307 |
+
esc_attr( $name ),
|
308 |
+
checked( $current, $name, false ),
|
309 |
+
esc_html( $optinos_page )
|
310 |
+
);
|
311 |
+
}
|
312 |
+
printf(
|
313 |
+
'<p><b>%s</b>%s</p>',
|
314 |
+
esc_html__( 'Options pages', 'smart-custom-fields' ),
|
315 |
+
$options_page_field
|
316 |
+
);
|
317 |
+
}
|
318 |
+
|
319 |
/**
|
320 |
* Saving settings
|
321 |
*
|
395 |
} else {
|
396 |
update_post_meta( $post_id, SCF_Config::PREFIX . 'taxonomies', $_POST[SCF_Config::PREFIX . 'taxonomies'] );
|
397 |
}
|
398 |
+
|
399 |
+
if ( !isset( $_POST[SCF_Config::PREFIX . 'options-pages'] ) ) {
|
400 |
+
delete_post_meta( $post_id, SCF_Config::PREFIX . 'options-pages' );
|
401 |
+
} else {
|
402 |
+
update_post_meta( $post_id, SCF_Config::PREFIX . 'options-pages', $_POST[SCF_Config::PREFIX . 'options-pages'] );
|
403 |
+
}
|
404 |
}
|
405 |
}
|
classes/controller/class.taxonomy.php
CHANGED
@@ -1,36 +1,29 @@
|
|
1 |
<?php
|
2 |
/**
|
3 |
* Smart_Custom_Fields_Controller_Taxonomy
|
4 |
-
* Version : 1.0.
|
5 |
* Author : inc2734
|
6 |
* Created : April 26, 2015
|
7 |
-
* Modified :
|
8 |
* License : GPLv2 or later
|
9 |
* License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
*/
|
11 |
class Smart_Custom_Fields_Controller_Taxonomy extends Smart_Custom_Fields_Controller_Base {
|
12 |
|
13 |
-
/**
|
14 |
-
* Taxonomy NAME
|
15 |
-
* @var string
|
16 |
-
*/
|
17 |
-
protected $taxonomy;
|
18 |
-
|
19 |
/**
|
20 |
* __construct
|
21 |
*/
|
22 |
public function __construct() {
|
23 |
parent::__construct();
|
24 |
|
25 |
-
|
26 |
-
add_action( $this->taxonomy . '_edit_form_fields', array( $this, 'edit_form_fields' ) );
|
27 |
add_action( 'edited_terms' , array( $this, 'update' ), 10, 2 );
|
28 |
add_action( 'delete_term' , array( $this, 'delete' ), 10, 4 );
|
29 |
}
|
30 |
|
31 |
/**
|
32 |
* Loading resources for term edit page
|
33 |
-
*
|
34 |
* @param string $hook
|
35 |
*/
|
36 |
public function admin_enqueue_scripts( $hook ) {
|
@@ -63,7 +56,7 @@ class Smart_Custom_Fields_Controller_Taxonomy extends Smart_Custom_Fields_Contro
|
|
63 |
|
64 |
/**
|
65 |
* Saving meta data from custom fields in term edit page
|
66 |
-
*
|
67 |
* @param int $term_id
|
68 |
* @param string $taxonomy
|
69 |
*/
|
1 |
<?php
|
2 |
/**
|
3 |
* Smart_Custom_Fields_Controller_Taxonomy
|
4 |
+
* Version : 1.0.1
|
5 |
* Author : inc2734
|
6 |
* Created : April 26, 2015
|
7 |
+
* Modified : May 31, 2016
|
8 |
* License : GPLv2 or later
|
9 |
* License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
*/
|
11 |
class Smart_Custom_Fields_Controller_Taxonomy extends Smart_Custom_Fields_Controller_Base {
|
12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
/**
|
14 |
* __construct
|
15 |
*/
|
16 |
public function __construct() {
|
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 |
/**
|
25 |
* Loading resources for term edit page
|
26 |
+
*
|
27 |
* @param string $hook
|
28 |
*/
|
29 |
public function admin_enqueue_scripts( $hook ) {
|
56 |
|
57 |
/**
|
58 |
* Saving meta data from custom fields in term edit page
|
59 |
+
*
|
60 |
* @param int $term_id
|
61 |
* @param string $taxonomy
|
62 |
*/
|
classes/models/class.cache.php
ADDED
@@ -0,0 +1,249 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Smart_Custom_Fields_Cache
|
4 |
+
* Version : 1.0.0
|
5 |
+
* Author : inc2734
|
6 |
+
* Created : Mau 31, 2016
|
7 |
+
* Modified :
|
8 |
+
* License : GPLv2 or later
|
9 |
+
* License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
+
*/
|
11 |
+
class Smart_Custom_Fields_Cache {
|
12 |
+
|
13 |
+
/**
|
14 |
+
* Singleton instance
|
15 |
+
* @var Smart_Custom_Fields_Cache
|
16 |
+
*/
|
17 |
+
private static $instance;
|
18 |
+
|
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();
|
25 |
+
|
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();
|
32 |
+
|
33 |
+
/**
|
34 |
+
* Getting data proccesses is heavy. So saved getted data to $settings.
|
35 |
+
* Using post_type as key.
|
36 |
+
* @var array
|
37 |
+
*/
|
38 |
+
public $settings = array();
|
39 |
+
|
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();
|
46 |
+
|
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;
|
54 |
+
}
|
55 |
+
|
56 |
+
/**
|
57 |
+
* Clear all caches.
|
58 |
+
*/
|
59 |
+
public function flush() {
|
60 |
+
$this->clear_meta();
|
61 |
+
$this->clear_settings_posts();
|
62 |
+
$this->clear_settings();
|
63 |
+
$this->clear_repeat_multiple_data();
|
64 |
+
}
|
65 |
+
|
66 |
+
/**
|
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 |
+
|
83 |
+
/**
|
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 ) {
|
91 |
+
$Meta = new Smart_Custom_Fields_Meta( $object );
|
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 |
+
}
|
106 |
+
}
|
107 |
+
|
108 |
+
/**
|
109 |
+
* Clear caches
|
110 |
+
*/
|
111 |
+
public function clear_meta() {
|
112 |
+
$this->meta = array();
|
113 |
+
}
|
114 |
+
|
115 |
+
/**
|
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 |
+
/**
|
129 |
+
* Getting cache that enabled custom field settings in the post type or the role or the term.
|
130 |
+
*
|
131 |
+
* @param WP_Post|WP_User|WP_Term|stdClass $object
|
132 |
+
* @return array|null
|
133 |
+
*/
|
134 |
+
public function get_settings_posts( $object ) {
|
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 |
+
|
143 |
+
/**
|
144 |
+
* Clear the $settings_posts
|
145 |
+
*/
|
146 |
+
public function clear_settings_posts() {
|
147 |
+
$this->settings_posts = array();
|
148 |
+
}
|
149 |
+
|
150 |
+
/**
|
151 |
+
* Saving the Setting object to cache
|
152 |
+
*
|
153 |
+
* @param int $settings_post_id
|
154 |
+
* @param WP_Post|WP_User|WP_Term|stdClass $object
|
155 |
+
* @param Smart_Custom_Fields_Setting $Setting
|
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 |
+
|
170 |
+
/**
|
171 |
+
* Getting the Setting object cache
|
172 |
+
* If there isn't the custom field settings ... null
|
173 |
+
* If there is custom field settings
|
174 |
+
* If there is no data for the specified $ meta_type + $id
|
175 |
+
* There is a thing of the General ... Smart_Custom_Fields_Setting
|
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];
|
197 |
+
}
|
198 |
+
return false;
|
199 |
+
}
|
200 |
+
}
|
201 |
+
|
202 |
+
/**
|
203 |
+
* Clear the $settings
|
204 |
+
*/
|
205 |
+
public function clear_settings() {
|
206 |
+
$this->settings = array();
|
207 |
+
}
|
208 |
+
|
209 |
+
/**
|
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 |
+
|
225 |
+
/**
|
226 |
+
* Getting delimited identification data of the repeated multi-value items from cache
|
227 |
+
*
|
228 |
+
* @param WP_Post|WP_User|WP_Term|stdClass $object
|
229 |
+
* @return mixed
|
230 |
+
*/
|
231 |
+
public function get_repeat_multiple_data( $object ) {
|
232 |
+
$Meta = new Smart_Custom_Fields_Meta( $object );
|
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 |
+
}
|
242 |
+
|
243 |
+
/**
|
244 |
+
* Clear delimited identification data of the repeated multi-value items cache
|
245 |
+
*/
|
246 |
+
public function clear_repeat_multiple_data() {
|
247 |
+
$this->repeat_multiple_data = array();
|
248 |
+
}
|
249 |
+
}
|
classes/models/class.meta.php
CHANGED
@@ -1,40 +1,40 @@
|
|
1 |
<?php
|
2 |
/**
|
3 |
* Smart_Custom_Fields_Meta
|
4 |
-
* Version : 1.
|
5 |
* Author : inc2734
|
6 |
* Created : March 17, 2015
|
7 |
-
* Modified :
|
8 |
* License : GPLv2 or later
|
9 |
* License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
*/
|
11 |
class Smart_Custom_Fields_Meta {
|
12 |
|
13 |
/**
|
14 |
-
* @var WP_Post|WP_User|WP_Term
|
15 |
*/
|
16 |
protected $object;
|
17 |
|
18 |
/**
|
19 |
* What meta data
|
20 |
-
* @var string post or user or term
|
21 |
*/
|
22 |
protected $meta_type = 'post';
|
23 |
|
24 |
/**
|
25 |
-
* Post ID or User ID or Term ID
|
26 |
* @var int
|
27 |
*/
|
28 |
protected $id;
|
29 |
|
30 |
/**
|
31 |
-
* Post Type or Role or Taxonomy
|
32 |
* @var string
|
33 |
*/
|
34 |
protected $type;
|
35 |
|
36 |
/**
|
37 |
-
* @param WP_Post|WP_User|WP_Term $object
|
38 |
*/
|
39 |
public function __construct( $object ) {
|
40 |
if ( !function_exists( 'get_editable_roles' ) ) {
|
@@ -56,6 +56,11 @@ class Smart_Custom_Fields_Meta {
|
|
56 |
$this->type = $object->taxonomy;
|
57 |
$this->meta_type = 'term';
|
58 |
}
|
|
|
|
|
|
|
|
|
|
|
59 |
elseif( empty( $object ) || is_wp_error( $object ) ) {
|
60 |
$this->id = null;
|
61 |
$this->type = null;
|
@@ -69,7 +74,7 @@ class Smart_Custom_Fields_Meta {
|
|
69 |
/**
|
70 |
* Getting the meta type
|
71 |
*
|
72 |
-
* @return string post or user or term
|
73 |
*/
|
74 |
public function get_meta_type() {
|
75 |
return $this->meta_type;
|
@@ -347,6 +352,9 @@ class Smart_Custom_Fields_Meta {
|
|
347 |
case 'term' :
|
348 |
$object = get_term( $this->id, $this->type );
|
349 |
break;
|
|
|
|
|
|
|
350 |
default :
|
351 |
$object = null;
|
352 |
}
|
1 |
<?php
|
2 |
/**
|
3 |
* Smart_Custom_Fields_Meta
|
4 |
+
* Version : 1.3.0
|
5 |
* Author : inc2734
|
6 |
* Created : March 17, 2015
|
7 |
+
* Modified : May 31, 2015
|
8 |
* License : GPLv2 or later
|
9 |
* License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
*/
|
11 |
class Smart_Custom_Fields_Meta {
|
12 |
|
13 |
/**
|
14 |
+
* @var WP_Post|WP_User|WP_Term|stdClass
|
15 |
*/
|
16 |
protected $object;
|
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 |
*/
|
34 |
protected $type;
|
35 |
|
36 |
/**
|
37 |
+
* @param WP_Post|WP_User|WP_Term|stdClass $object
|
38 |
*/
|
39 |
public function __construct( $object ) {
|
40 |
if ( !function_exists( 'get_editable_roles' ) ) {
|
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;
|
74 |
/**
|
75 |
* Getting the meta type
|
76 |
*
|
77 |
+
* @return string post or user or term or option
|
78 |
*/
|
79 |
public function get_meta_type() {
|
80 |
return $this->meta_type;
|
352 |
case 'term' :
|
353 |
$object = get_term( $this->id, $this->type );
|
354 |
break;
|
355 |
+
case 'option' :
|
356 |
+
$object = SCF::generate_option_object( $this->id );
|
357 |
+
break;
|
358 |
default :
|
359 |
$object = null;
|
360 |
}
|
classes/models/class.options-page.php
ADDED
@@ -0,0 +1,86 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Smart_Custom_Fields_Options_Page
|
4 |
+
* Version : 1.0.0
|
5 |
+
* Author : inc2734
|
6 |
+
* Created : May 29, 2014
|
7 |
+
* Modified :
|
8 |
+
* License : GPLv2 or later
|
9 |
+
* License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
+
*/
|
11 |
+
class Smart_Custom_Fields_Options_Page {
|
12 |
+
|
13 |
+
/**
|
14 |
+
* @var string
|
15 |
+
*/
|
16 |
+
protected $page_title;
|
17 |
+
|
18 |
+
/**
|
19 |
+
* @var string
|
20 |
+
*/
|
21 |
+
protected $menu_title;
|
22 |
+
|
23 |
+
/**
|
24 |
+
* @var string
|
25 |
+
*/
|
26 |
+
protected $capability;
|
27 |
+
|
28 |
+
/**
|
29 |
+
* @var string
|
30 |
+
*/
|
31 |
+
protected $menu_slug;
|
32 |
+
|
33 |
+
/**
|
34 |
+
* @var string
|
35 |
+
*/
|
36 |
+
protected $icon_url;
|
37 |
+
|
38 |
+
/**
|
39 |
+
* @var int
|
40 |
+
*/
|
41 |
+
protected $position;
|
42 |
+
|
43 |
+
/**
|
44 |
+
* @see https://developer.wordpress.org/reference/functions/add_menu_page/
|
45 |
+
* @param string $page_title
|
46 |
+
* @param string $menu_title
|
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;
|
54 |
+
$this->menu_title = $menu_title;
|
55 |
+
$this->capability = $capability;
|
56 |
+
$this->menu_slug = $menu_slug;
|
57 |
+
$this->icon_url = $icon_url;
|
58 |
+
$this->position = $position;
|
59 |
+
add_action( 'admin_menu', array( $this, 'add_options_page_menu' ) );
|
60 |
+
}
|
61 |
+
|
62 |
+
public function add_options_page_menu() {
|
63 |
+
return add_menu_page(
|
64 |
+
$this->page_title,
|
65 |
+
$this->menu_title,
|
66 |
+
$this->capability,
|
67 |
+
$this->menu_slug,
|
68 |
+
array( $this, 'display' ),
|
69 |
+
$this->icon_url,
|
70 |
+
$this->position
|
71 |
+
);
|
72 |
+
}
|
73 |
+
|
74 |
+
public function display() {
|
75 |
+
$Option = SCF::generate_option_object( $_GET['page'] );
|
76 |
+
if ( !$Option ) {
|
77 |
+
return;
|
78 |
+
}
|
79 |
+
?>
|
80 |
+
<div class="wrap">
|
81 |
+
<h3><?php echo esc_html( $Option->menu_title ); ?></h3>
|
82 |
+
<?php do_action( SCF_Config::PREFIX . 'custom-options-page', $Option ); ?>
|
83 |
+
</div>
|
84 |
+
<?php
|
85 |
+
}
|
86 |
+
}
|
css/option.css
ADDED
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/**
|
2 |
+
* option.css
|
3 |
+
* Version : 1.0.0
|
4 |
+
* Author : inc2734
|
5 |
+
* Created : May 30, 2016
|
6 |
+
* Modified :
|
7 |
+
* License : GPLv2 or later
|
8 |
+
* License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
9 |
+
*/
|
css/settings.css
CHANGED
@@ -1,9 +1,9 @@
|
|
1 |
/**
|
2 |
* settings.css
|
3 |
-
* Version : 1.0
|
4 |
* Author : inc2734
|
5 |
* Created : September 23, 2014
|
6 |
-
* Modified :
|
7 |
* License : GPLv2 or later
|
8 |
* License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
9 |
*/
|
@@ -180,13 +180,15 @@
|
|
180 |
*/
|
181 |
#smart-cf-meta-box-condition-post b,
|
182 |
#smart-cf-meta-box-condition-profile b,
|
183 |
-
#smart-cf-meta-box-condition-taxonomy b
|
|
|
184 |
display: block;
|
185 |
margin: 0 0 5px;
|
186 |
}
|
187 |
#smart-cf-meta-box-condition-post label,
|
188 |
#smart-cf-meta-box-condition-profile label,
|
189 |
-
#smart-cf-meta-box-condition-taxonomy label
|
|
|
190 |
display: block;
|
191 |
margin: 0 0 5px;
|
192 |
}
|
1 |
/**
|
2 |
* settings.css
|
3 |
+
* Version : 1.1.0
|
4 |
* Author : inc2734
|
5 |
* Created : September 23, 2014
|
6 |
+
* Modified : May 31, 2016
|
7 |
* License : GPLv2 or later
|
8 |
* License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
9 |
*/
|
180 |
*/
|
181 |
#smart-cf-meta-box-condition-post b,
|
182 |
#smart-cf-meta-box-condition-profile b,
|
183 |
+
#smart-cf-meta-box-condition-taxonomy b,
|
184 |
+
#smart-cf-meta-box-condition-options-page b {
|
185 |
display: block;
|
186 |
margin: 0 0 5px;
|
187 |
}
|
188 |
#smart-cf-meta-box-condition-post label,
|
189 |
#smart-cf-meta-box-condition-profile label,
|
190 |
+
#smart-cf-meta-box-condition-taxonomy label,
|
191 |
+
#smart-cf-meta-box-condition-options-page label {
|
192 |
display: block;
|
193 |
margin: 0 0 5px;
|
194 |
}
|
languages/smart-custom-fields-ja.mo
CHANGED
Binary file
|
languages/smart-custom-fields-ja.po
CHANGED
@@ -2,10 +2,10 @@
|
|
2 |
# This file is distributed under the same license as the Smart Custom Fields package.
|
3 |
msgid ""
|
4 |
msgstr ""
|
5 |
-
"Project-Id-Version: Smart Custom Fields
|
6 |
"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/smart-custom-fields\n"
|
7 |
-
"POT-Creation-Date: 2016-
|
8 |
-
"PO-Revision-Date: 2016-
|
9 |
"Last-Translator: inc2734 <inc@2inc.org>\n"
|
10 |
"Language-Team: \n"
|
11 |
"Language: ja\n"
|
@@ -26,6 +26,10 @@ msgstr "画像設定"
|
|
26 |
msgid "File setting"
|
27 |
msgstr "ファイル設定"
|
28 |
|
|
|
|
|
|
|
|
|
29 |
#: classes/controller/class.profile.php:43 classes/controller/class.settings.php:76
|
30 |
msgid "Custom Fields"
|
31 |
msgstr "カスタムフィールド"
|
@@ -62,36 +66,44 @@ msgstr "表示条件(プロフィール)"
|
|
62 |
msgid "Display conditions ( Taxonomy )"
|
63 |
msgstr "表示条件(タクソノミー)"
|
64 |
|
65 |
-
#: classes/controller/class.settings.php:
|
|
|
|
|
|
|
|
|
66 |
msgid "Type"
|
67 |
msgstr "タイプ"
|
68 |
|
69 |
-
#: classes/controller/class.settings.php:
|
70 |
msgid "Add Sub field"
|
71 |
msgstr "サブフィールドを追加"
|
72 |
|
73 |
-
#: classes/controller/class.settings.php:
|
74 |
msgid "Add Field"
|
75 |
msgstr "フィールド追加"
|
76 |
|
77 |
-
#: classes/controller/class.settings.php:
|
78 |
#: classes/fields/class.field-relation.php:213
|
79 |
msgid "Post Types"
|
80 |
msgstr "投稿タイプ"
|
81 |
|
82 |
-
#: classes/controller/class.settings.php:
|
83 |
msgid "Post Ids ( Comma separated )"
|
84 |
msgstr "投稿 ID (カンマ区切り)"
|
85 |
|
86 |
-
#: classes/controller/class.settings.php:
|
87 |
msgid "Roles"
|
88 |
msgstr "権限"
|
89 |
|
90 |
-
#: classes/controller/class.settings.php:
|
91 |
#: classes/fields/class.field-taxonomy.php:216
|
92 |
msgid "Taxonomies"
|
93 |
msgstr "タクソノミー"
|
94 |
|
|
|
|
|
|
|
|
|
95 |
#: classes/fields/class.field-boolean.php:24
|
96 |
msgid "Boolean"
|
97 |
msgstr "真偽値"
|
@@ -273,46 +285,45 @@ msgstr "繰り返し"
|
|
273 |
msgid "Group name"
|
274 |
msgstr "グループ名"
|
275 |
|
276 |
-
|
277 |
-
#:
|
278 |
-
#: smart-custom-fields.php:159 smart-custom-fields.php:160
|
279 |
msgid "Smart Custom Fields"
|
280 |
msgstr "Smart Custom Fields"
|
281 |
|
282 |
-
#: smart-custom-fields.php:
|
283 |
-
#: smart-custom-fields.php:
|
284 |
msgid "Add New"
|
285 |
msgstr "新規追加"
|
286 |
|
287 |
-
#: smart-custom-fields.php:
|
288 |
msgid "New Field"
|
289 |
msgstr "新規フィールド"
|
290 |
|
291 |
-
#: smart-custom-fields.php:
|
292 |
msgid "Edit Field"
|
293 |
msgstr "フィールド編集"
|
294 |
|
295 |
-
#: smart-custom-fields.php:
|
296 |
msgid "View Field"
|
297 |
msgstr "フィールドを表示"
|
298 |
|
299 |
-
#: smart-custom-fields.php:
|
300 |
msgid "All Fields"
|
301 |
msgstr "すべてのフィールド"
|
302 |
|
303 |
-
#: smart-custom-fields.php:
|
304 |
msgid "Search Fields"
|
305 |
msgstr "フィールドを検索"
|
306 |
|
307 |
-
#: smart-custom-fields.php:
|
308 |
msgid "Parent Fields:"
|
309 |
msgstr "親フィールド:"
|
310 |
|
311 |
-
#: smart-custom-fields.php:
|
312 |
msgid "No Fields found."
|
313 |
msgstr "フィールドは見つかりませんでした。"
|
314 |
|
315 |
-
#: smart-custom-fields.php:
|
316 |
msgid "No Fields found in Trash."
|
317 |
msgstr "ゴミ箱にフィールドは見つかりませんでした"
|
318 |
|
2 |
# This file is distributed under the same license as the Smart Custom Fields package.
|
3 |
msgid ""
|
4 |
msgstr ""
|
5 |
+
"Project-Id-Version: Smart Custom Fields 2.0.0\n"
|
6 |
"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/smart-custom-fields\n"
|
7 |
+
"POT-Creation-Date: 2016-05-31 19:02+0900\n"
|
8 |
+
"PO-Revision-Date: 2016-05-31 19:02+0900\n"
|
9 |
"Last-Translator: inc2734 <inc@2inc.org>\n"
|
10 |
"Language-Team: \n"
|
11 |
"Language: ja\n"
|
26 |
msgid "File setting"
|
27 |
msgstr "ファイル設定"
|
28 |
|
29 |
+
#: classes/controller/class.option.php:57
|
30 |
+
msgid "Save settings"
|
31 |
+
msgstr "設定を保存"
|
32 |
+
|
33 |
#: classes/controller/class.profile.php:43 classes/controller/class.settings.php:76
|
34 |
msgid "Custom Fields"
|
35 |
msgstr "カスタムフィールド"
|
66 |
msgid "Display conditions ( Taxonomy )"
|
67 |
msgstr "表示条件(タクソノミー)"
|
68 |
|
69 |
+
#: classes/controller/class.settings.php:103
|
70 |
+
msgid "Display conditions ( Options page )"
|
71 |
+
msgstr "表示条件(オプションページ)"
|
72 |
+
|
73 |
+
#: classes/controller/class.settings.php:163
|
74 |
msgid "Type"
|
75 |
msgstr "タイプ"
|
76 |
|
77 |
+
#: classes/controller/class.settings.php:198
|
78 |
msgid "Add Sub field"
|
79 |
msgstr "サブフィールドを追加"
|
80 |
|
81 |
+
#: classes/controller/class.settings.php:202
|
82 |
msgid "Add Field"
|
83 |
msgstr "フィールド追加"
|
84 |
|
85 |
+
#: classes/controller/class.settings.php:232
|
86 |
#: classes/fields/class.field-relation.php:213
|
87 |
msgid "Post Types"
|
88 |
msgstr "投稿タイプ"
|
89 |
|
90 |
+
#: classes/controller/class.settings.php:239
|
91 |
msgid "Post Ids ( Comma separated )"
|
92 |
msgstr "投稿 ID (カンマ区切り)"
|
93 |
|
94 |
+
#: classes/controller/class.settings.php:264
|
95 |
msgid "Roles"
|
96 |
msgstr "権限"
|
97 |
|
98 |
+
#: classes/controller/class.settings.php:290
|
99 |
#: classes/fields/class.field-taxonomy.php:216
|
100 |
msgid "Taxonomies"
|
101 |
msgstr "タクソノミー"
|
102 |
|
103 |
+
#: classes/controller/class.settings.php:314
|
104 |
+
msgid "Options pages"
|
105 |
+
msgstr "オプションページ"
|
106 |
+
|
107 |
#: classes/fields/class.field-boolean.php:24
|
108 |
msgid "Boolean"
|
109 |
msgstr "真偽値"
|
285 |
msgid "Group name"
|
286 |
msgstr "グループ名"
|
287 |
|
288 |
+
#: classes/models/class.revisions.php:124 smart-custom-fields.php:159
|
289 |
+
#: smart-custom-fields.php:160 smart-custom-fields.php:161
|
|
|
290 |
msgid "Smart Custom Fields"
|
291 |
msgstr "Smart Custom Fields"
|
292 |
|
293 |
+
#: smart-custom-fields.php:162 smart-custom-fields.php:163
|
294 |
+
#: smart-custom-fields.php:209 smart-custom-fields.php:210
|
295 |
msgid "Add New"
|
296 |
msgstr "新規追加"
|
297 |
|
298 |
+
#: smart-custom-fields.php:164
|
299 |
msgid "New Field"
|
300 |
msgstr "新規フィールド"
|
301 |
|
302 |
+
#: smart-custom-fields.php:165
|
303 |
msgid "Edit Field"
|
304 |
msgstr "フィールド編集"
|
305 |
|
306 |
+
#: smart-custom-fields.php:166
|
307 |
msgid "View Field"
|
308 |
msgstr "フィールドを表示"
|
309 |
|
310 |
+
#: smart-custom-fields.php:167
|
311 |
msgid "All Fields"
|
312 |
msgstr "すべてのフィールド"
|
313 |
|
314 |
+
#: smart-custom-fields.php:168
|
315 |
msgid "Search Fields"
|
316 |
msgstr "フィールドを検索"
|
317 |
|
318 |
+
#: smart-custom-fields.php:169
|
319 |
msgid "Parent Fields:"
|
320 |
msgstr "親フィールド:"
|
321 |
|
322 |
+
#: smart-custom-fields.php:170
|
323 |
msgid "No Fields found."
|
324 |
msgstr "フィールドは見つかりませんでした。"
|
325 |
|
326 |
+
#: smart-custom-fields.php:171
|
327 |
msgid "No Fields found in Trash."
|
328 |
msgstr "ゴミ箱にフィールドは見つかりませんでした"
|
329 |
|
languages/smart-custom-fields.pot
CHANGED
@@ -2,10 +2,9 @@
|
|
2 |
# This file is distributed under the same license as the Smart Custom Fields package.
|
3 |
msgid ""
|
4 |
msgstr ""
|
5 |
-
"Project-Id-Version: Smart Custom Fields
|
6 |
-
"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/smart-custom-"
|
7 |
-
"
|
8 |
-
"POT-Creation-Date: 2016-02-03 05:01:33+00:00\n"
|
9 |
"MIME-Version: 1.0\n"
|
10 |
"Content-Type: text/plain; charset=UTF-8\n"
|
11 |
"Content-Transfer-Encoding: 8bit\n"
|
@@ -21,6 +20,10 @@ msgstr ""
|
|
21 |
msgid "File setting"
|
22 |
msgstr ""
|
23 |
|
|
|
|
|
|
|
|
|
24 |
#: classes/controller/class.profile.php:43
|
25 |
#: classes/controller/class.settings.php:76
|
26 |
msgid "Custom Fields"
|
@@ -58,36 +61,44 @@ msgstr ""
|
|
58 |
msgid "Display conditions ( Taxonomy )"
|
59 |
msgstr ""
|
60 |
|
61 |
-
#: classes/controller/class.settings.php:
|
|
|
|
|
|
|
|
|
62 |
msgid "Type"
|
63 |
msgstr ""
|
64 |
|
65 |
-
#: classes/controller/class.settings.php:
|
66 |
msgid "Add Sub field"
|
67 |
msgstr ""
|
68 |
|
69 |
-
#: classes/controller/class.settings.php:
|
70 |
msgid "Add Field"
|
71 |
msgstr ""
|
72 |
|
73 |
-
#: classes/controller/class.settings.php:
|
74 |
#: classes/fields/class.field-relation.php:213
|
75 |
msgid "Post Types"
|
76 |
msgstr ""
|
77 |
|
78 |
-
#: classes/controller/class.settings.php:
|
79 |
msgid "Post Ids ( Comma separated )"
|
80 |
msgstr ""
|
81 |
|
82 |
-
#: classes/controller/class.settings.php:
|
83 |
msgid "Roles"
|
84 |
msgstr ""
|
85 |
|
86 |
-
#: classes/controller/class.settings.php:
|
87 |
#: classes/fields/class.field-taxonomy.php:216
|
88 |
msgid "Taxonomies"
|
89 |
msgstr ""
|
90 |
|
|
|
|
|
|
|
|
|
91 |
#: classes/fields/class.field-boolean.php:24
|
92 |
msgid "Boolean"
|
93 |
msgstr ""
|
@@ -278,47 +289,45 @@ msgstr ""
|
|
278 |
msgid "Group name"
|
279 |
msgstr ""
|
280 |
|
281 |
-
|
282 |
-
|
283 |
-
#: classes/models/class.revisions.php:124 smart-custom-fields.php:158
|
284 |
-
#: smart-custom-fields.php:159 smart-custom-fields.php:160
|
285 |
msgid "Smart Custom Fields"
|
286 |
msgstr ""
|
287 |
|
288 |
-
#: smart-custom-fields.php:
|
289 |
-
#: smart-custom-fields.php:
|
290 |
msgid "Add New"
|
291 |
msgstr ""
|
292 |
|
293 |
-
#: smart-custom-fields.php:
|
294 |
msgid "New Field"
|
295 |
msgstr ""
|
296 |
|
297 |
-
#: smart-custom-fields.php:
|
298 |
msgid "Edit Field"
|
299 |
msgstr ""
|
300 |
|
301 |
-
#: smart-custom-fields.php:
|
302 |
msgid "View Field"
|
303 |
msgstr ""
|
304 |
|
305 |
-
#: smart-custom-fields.php:
|
306 |
msgid "All Fields"
|
307 |
msgstr ""
|
308 |
|
309 |
-
#: smart-custom-fields.php:
|
310 |
msgid "Search Fields"
|
311 |
msgstr ""
|
312 |
|
313 |
-
#: smart-custom-fields.php:
|
314 |
msgid "Parent Fields:"
|
315 |
msgstr ""
|
316 |
|
317 |
-
#: smart-custom-fields.php:
|
318 |
msgid "No Fields found."
|
319 |
msgstr ""
|
320 |
|
321 |
-
#: smart-custom-fields.php:
|
322 |
msgid "No Fields found in Trash."
|
323 |
msgstr ""
|
324 |
|
2 |
# This file is distributed under the same license as the Smart Custom Fields package.
|
3 |
msgid ""
|
4 |
msgstr ""
|
5 |
+
"Project-Id-Version: Smart Custom Fields 2.0.0\n"
|
6 |
+
"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/smart-custom-fields\n"
|
7 |
+
"POT-Creation-Date: 2016-05-31 09:52:10+00:00\n"
|
|
|
8 |
"MIME-Version: 1.0\n"
|
9 |
"Content-Type: text/plain; charset=UTF-8\n"
|
10 |
"Content-Transfer-Encoding: 8bit\n"
|
20 |
msgid "File setting"
|
21 |
msgstr ""
|
22 |
|
23 |
+
#: classes/controller/class.option.php:57
|
24 |
+
msgid "Save settings"
|
25 |
+
msgstr ""
|
26 |
+
|
27 |
#: classes/controller/class.profile.php:43
|
28 |
#: classes/controller/class.settings.php:76
|
29 |
msgid "Custom Fields"
|
61 |
msgid "Display conditions ( Taxonomy )"
|
62 |
msgstr ""
|
63 |
|
64 |
+
#: classes/controller/class.settings.php:103
|
65 |
+
msgid "Display conditions ( Options page )"
|
66 |
+
msgstr ""
|
67 |
+
|
68 |
+
#: classes/controller/class.settings.php:163
|
69 |
msgid "Type"
|
70 |
msgstr ""
|
71 |
|
72 |
+
#: classes/controller/class.settings.php:198
|
73 |
msgid "Add Sub field"
|
74 |
msgstr ""
|
75 |
|
76 |
+
#: classes/controller/class.settings.php:202
|
77 |
msgid "Add Field"
|
78 |
msgstr ""
|
79 |
|
80 |
+
#: classes/controller/class.settings.php:232
|
81 |
#: classes/fields/class.field-relation.php:213
|
82 |
msgid "Post Types"
|
83 |
msgstr ""
|
84 |
|
85 |
+
#: classes/controller/class.settings.php:239
|
86 |
msgid "Post Ids ( Comma separated )"
|
87 |
msgstr ""
|
88 |
|
89 |
+
#: classes/controller/class.settings.php:264
|
90 |
msgid "Roles"
|
91 |
msgstr ""
|
92 |
|
93 |
+
#: classes/controller/class.settings.php:290
|
94 |
#: classes/fields/class.field-taxonomy.php:216
|
95 |
msgid "Taxonomies"
|
96 |
msgstr ""
|
97 |
|
98 |
+
#: classes/controller/class.settings.php:314
|
99 |
+
msgid "Options pages"
|
100 |
+
msgstr ""
|
101 |
+
|
102 |
#: classes/fields/class.field-boolean.php:24
|
103 |
msgid "Boolean"
|
104 |
msgstr ""
|
289 |
msgid "Group name"
|
290 |
msgstr ""
|
291 |
|
292 |
+
#: classes/models/class.revisions.php:124 smart-custom-fields.php:159
|
293 |
+
#: smart-custom-fields.php:160 smart-custom-fields.php:161
|
|
|
|
|
294 |
msgid "Smart Custom Fields"
|
295 |
msgstr ""
|
296 |
|
297 |
+
#: smart-custom-fields.php:162 smart-custom-fields.php:163
|
298 |
+
#: smart-custom-fields.php:209 smart-custom-fields.php:210
|
299 |
msgid "Add New"
|
300 |
msgstr ""
|
301 |
|
302 |
+
#: smart-custom-fields.php:164
|
303 |
msgid "New Field"
|
304 |
msgstr ""
|
305 |
|
306 |
+
#: smart-custom-fields.php:165
|
307 |
msgid "Edit Field"
|
308 |
msgstr ""
|
309 |
|
310 |
+
#: smart-custom-fields.php:166
|
311 |
msgid "View Field"
|
312 |
msgstr ""
|
313 |
|
314 |
+
#: smart-custom-fields.php:167
|
315 |
msgid "All Fields"
|
316 |
msgstr ""
|
317 |
|
318 |
+
#: smart-custom-fields.php:168
|
319 |
msgid "Search Fields"
|
320 |
msgstr ""
|
321 |
|
322 |
+
#: smart-custom-fields.php:169
|
323 |
msgid "Parent Fields:"
|
324 |
msgstr ""
|
325 |
|
326 |
+
#: smart-custom-fields.php:170
|
327 |
msgid "No Fields found."
|
328 |
msgstr ""
|
329 |
|
330 |
+
#: smart-custom-fields.php:171
|
331 |
msgid "No Fields found in Trash."
|
332 |
msgstr ""
|
333 |
|
readme.txt
CHANGED
@@ -3,8 +3,8 @@ Contributors: inc2734, toro_unit, mimosafa, hideokamoto, hisako-isaka, kurudrive
|
|
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.
|
7 |
-
Stable tag:
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
@@ -38,28 +38,66 @@ https://www.youtube.com/watch?v=WxPZurn0yvI
|
|
38 |
|
39 |
= How to get meta data ? =
|
40 |
|
41 |
-
|
|
|
42 |
This method can get any meta data.
|
43 |
-
|
|
|
|
|
44 |
This method can get meta data of any group.
|
45 |
|
46 |
-
|
|
|
47 |
This method can get all meta data.
|
48 |
|
49 |
-
|
|
|
50 |
This method can get any user meta data.
|
51 |
-
|
|
|
|
|
|
|
|
|
52 |
This method can get user meta data of any group.
|
53 |
-
|
|
|
|
|
54 |
This method can get all user meta data.
|
55 |
|
56 |
-
|
|
|
|
|
|
|
57 |
This method can get any term meta data.
|
58 |
-
|
|
|
|
|
59 |
This method can get term meta data of any group.
|
60 |
-
|
|
|
|
|
61 |
This method can get all term meta data.
|
62 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
63 |
= Register custom fields by the code. =
|
64 |
|
65 |
https://gist.github.com/inc2734/9f6d65c7473d060d0fd6
|
@@ -87,6 +125,10 @@ You can send your own language pack to me.
|
|
87 |
|
88 |
== Changelog ==
|
89 |
|
|
|
|
|
|
|
|
|
90 |
= 1.7.0 =
|
91 |
* Added taxonomy relation field.
|
92 |
* Added textarea rows setting.
|
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.5.2
|
7 |
+
Stable tag: 2.0.0
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
38 |
|
39 |
= How to get meta data ? =
|
40 |
|
41 |
+
== Post meta data ==
|
42 |
+
|
43 |
This method can get any meta data.
|
44 |
+
|
45 |
+
`SCF::get( 'field-name' )`
|
46 |
+
|
47 |
This method can get meta data of any group.
|
48 |
|
49 |
+
`SCF::get( 'group-name' )`
|
50 |
+
|
51 |
This method can get all meta data.
|
52 |
|
53 |
+
`SCF::gets()`
|
54 |
+
|
55 |
This method can get any user meta data.
|
56 |
+
|
57 |
+
== User meta data ==
|
58 |
+
|
59 |
+
`SCF::get_user_meta( $user_id, 'field-name' )`
|
60 |
+
|
61 |
This method can get user meta data of any group.
|
62 |
+
|
63 |
+
`SCF::get_user_meta( $user_id, 'group-name' )`
|
64 |
+
|
65 |
This method can get all user meta data.
|
66 |
|
67 |
+
`SCF::get_user_meta( $user_id )`
|
68 |
+
|
69 |
+
== Term meta data ==
|
70 |
+
|
71 |
This method can get any term meta data.
|
72 |
+
|
73 |
+
`SCF::get_term_meta( $term_id, $taxonomy 'field-name' )`
|
74 |
+
|
75 |
This method can get term meta data of any group.
|
76 |
+
|
77 |
+
`SCF::get_term_meta( $term_id, $taxonomy, 'group-name' )`
|
78 |
+
|
79 |
This method can get all term meta data.
|
80 |
|
81 |
+
`SCF::get_term_meta( $term_id, $taxonomy )`
|
82 |
+
|
83 |
+
== Custom options page meta data ==
|
84 |
+
|
85 |
+
This method can get any custom options page meta data.
|
86 |
+
|
87 |
+
`SCF::get_option_meta( $menu_slug 'field-name' )`
|
88 |
+
|
89 |
+
This method can get custom options page meta data of any group.
|
90 |
+
|
91 |
+
`SCF::get_option_meta( $menu_slug, 'group-name' )`
|
92 |
+
|
93 |
+
This method can get all custom options page meta data.
|
94 |
+
|
95 |
+
`SCF::get_option_meta( $menu_slug )`
|
96 |
+
|
97 |
+
= Create custom options page =
|
98 |
+
|
99 |
+
`SCF::add_options_page( $page_title, $menu_title, $capability, $menu_slug, $icon_url = '', $position = null );`
|
100 |
+
|
101 |
= Register custom fields by the code. =
|
102 |
|
103 |
https://gist.github.com/inc2734/9f6d65c7473d060d0fd6
|
125 |
|
126 |
== Changelog ==
|
127 |
|
128 |
+
= 2.0.0 =
|
129 |
+
* Refactoring
|
130 |
+
* Added meta data of custom options page.
|
131 |
+
|
132 |
= 1.7.0 =
|
133 |
* Added taxonomy relation field.
|
134 |
* Added textarea rows setting.
|
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:
|
7 |
* Author: inc2734
|
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 or later
|
@@ -34,13 +34,6 @@ class Smart_Custom_Fields {
|
|
34 |
dirname( plugin_basename( __FILE__ ) ) . '/languages'
|
35 |
);
|
36 |
|
37 |
-
add_action( 'after_setup_theme', array( $this, 'after_setup_theme' ) );
|
38 |
-
}
|
39 |
-
|
40 |
-
/**
|
41 |
-
* Loading classes
|
42 |
-
*/
|
43 |
-
public function after_setup_theme() {
|
44 |
do_action( SCF_Config::PREFIX . 'load' );
|
45 |
require_once plugin_dir_path( __FILE__ ) . 'classes/models/class.meta.php';
|
46 |
require_once plugin_dir_path( __FILE__ ) . 'classes/models/class.setting.php';
|
@@ -48,6 +41,8 @@ class Smart_Custom_Fields {
|
|
48 |
require_once plugin_dir_path( __FILE__ ) . 'classes/models/class.abstract-field-base.php';
|
49 |
require_once plugin_dir_path( __FILE__ ) . 'classes/models/class.revisions.php';
|
50 |
require_once plugin_dir_path( __FILE__ ) . 'classes/models/class.ajax.php';
|
|
|
|
|
51 |
require_once plugin_dir_path( __FILE__ ) . 'classes/class.scf.php';
|
52 |
new Smart_Custom_Fields_Revisions();
|
53 |
|
@@ -111,10 +106,7 @@ class Smart_Custom_Fields {
|
|
111 |
// その他の新規作成・編集画面
|
112 |
elseif ( in_array( $screen->id, get_post_types() ) ) {
|
113 |
$post_id = $this->get_post_id_in_admin();
|
114 |
-
|
115 |
-
$Post->ID = $post_id;
|
116 |
-
$Post->post_type = $screen->id;
|
117 |
-
if ( SCF::get_settings( new WP_Post( $Post ) ) ) {
|
118 |
require_once plugin_dir_path( __FILE__ ) . 'classes/controller/class.controller-base.php';
|
119 |
require_once plugin_dir_path( __FILE__ ) . 'classes/controller/class.editor.php';
|
120 |
new Smart_Custom_Fields_Revisions();
|
@@ -124,11 +116,6 @@ class Smart_Custom_Fields {
|
|
124 |
// プロフィール編集画面
|
125 |
elseif ( in_array( $screen->id, array( 'profile', 'user-edit' ) ) ) {
|
126 |
$user_id = $this->get_user_id_in_admin();
|
127 |
-
$user_data = get_userdata( $user_id );
|
128 |
-
$roles[0] = false;
|
129 |
-
if ( $user_data ) {
|
130 |
-
$roles = $user_data->roles;
|
131 |
-
}
|
132 |
if ( SCF::get_settings( get_userdata( $user_id ) ) ) {
|
133 |
require_once plugin_dir_path( __FILE__ ) . 'classes/controller/class.controller-base.php';
|
134 |
require_once plugin_dir_path( __FILE__ ) . 'classes/controller/class.profile.php';
|
@@ -147,6 +134,20 @@ class Smart_Custom_Fields {
|
|
147 |
}
|
148 |
}
|
149 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
150 |
}
|
151 |
|
152 |
/**
|
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.0.0
|
7 |
* Author: inc2734
|
8 |
* Author URI: http://2inc.org
|
9 |
* Created: October 9, 2014
|
10 |
+
* Modified: May 31, 2016
|
11 |
* Text Domain: smart-custom-fields
|
12 |
* Domain Path: /languages
|
13 |
* License: GPLv2 or later
|
34 |
dirname( plugin_basename( __FILE__ ) ) . '/languages'
|
35 |
);
|
36 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
do_action( SCF_Config::PREFIX . 'load' );
|
38 |
require_once plugin_dir_path( __FILE__ ) . 'classes/models/class.meta.php';
|
39 |
require_once plugin_dir_path( __FILE__ ) . 'classes/models/class.setting.php';
|
41 |
require_once plugin_dir_path( __FILE__ ) . 'classes/models/class.abstract-field-base.php';
|
42 |
require_once plugin_dir_path( __FILE__ ) . 'classes/models/class.revisions.php';
|
43 |
require_once plugin_dir_path( __FILE__ ) . 'classes/models/class.ajax.php';
|
44 |
+
require_once plugin_dir_path( __FILE__ ) . 'classes/models/class.options-page.php';
|
45 |
+
require_once plugin_dir_path( __FILE__ ) . 'classes/models/class.cache.php';
|
46 |
require_once plugin_dir_path( __FILE__ ) . 'classes/class.scf.php';
|
47 |
new Smart_Custom_Fields_Revisions();
|
48 |
|
106 |
// その他の新規作成・編集画面
|
107 |
elseif ( in_array( $screen->id, get_post_types() ) ) {
|
108 |
$post_id = $this->get_post_id_in_admin();
|
109 |
+
if ( SCF::get_settings( SCF::generate_post_object( $post_id, $screen->id ) ) ) {
|
|
|
|
|
|
|
110 |
require_once plugin_dir_path( __FILE__ ) . 'classes/controller/class.controller-base.php';
|
111 |
require_once plugin_dir_path( __FILE__ ) . 'classes/controller/class.editor.php';
|
112 |
new Smart_Custom_Fields_Revisions();
|
116 |
// プロフィール編集画面
|
117 |
elseif ( in_array( $screen->id, array( 'profile', 'user-edit' ) ) ) {
|
118 |
$user_id = $this->get_user_id_in_admin();
|
|
|
|
|
|
|
|
|
|
|
119 |
if ( SCF::get_settings( get_userdata( $user_id ) ) ) {
|
120 |
require_once plugin_dir_path( __FILE__ ) . 'classes/controller/class.controller-base.php';
|
121 |
require_once plugin_dir_path( __FILE__ ) . 'classes/controller/class.profile.php';
|
134 |
}
|
135 |
}
|
136 |
}
|
137 |
+
// オプションページ
|
138 |
+
else {
|
139 |
+
$menu_slug = preg_replace( '/^toplevel_page_(.+)$/', '$1', $screen->id );
|
140 |
+
$options_pages = SCF::get_options_pages();
|
141 |
+
|
142 |
+
if ( array_key_exists( $menu_slug, $options_pages ) ) {
|
143 |
+
$Option = SCF::generate_option_object( $menu_slug );
|
144 |
+
if ( SCF::get_settings( $Option ) ) {
|
145 |
+
require_once plugin_dir_path( __FILE__ ) . 'classes/controller/class.controller-base.php';
|
146 |
+
require_once plugin_dir_path( __FILE__ ) . 'classes/controller/class.option.php';
|
147 |
+
new Smart_Custom_Fields_Controller_Option();
|
148 |
+
}
|
149 |
+
}
|
150 |
+
}
|
151 |
}
|
152 |
|
153 |
/**
|