-
Notifications
You must be signed in to change notification settings - Fork 285
/
acf.php
executable file
·2065 lines (1597 loc) · 44.4 KB
/
acf.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/*
Plugin Name: Advanced Custom Fields
Plugin URI: http://www.advancedcustomfields.com/
Description: Fully customise WordPress edit screens with powerful fields. Boasting a professional interface and a powerfull API, it’s a must have for any web developer working with WordPress. Field types include: Wysiwyg, text, textarea, image, file, select, checkbox, page link, post object, date picker, color picker, repeater, flexible content, gallery and more!
Version: 3.5.4.2
Author: Elliot Condon
Author URI: http://www.elliotcondon.com/
License: GPL
Copyright: Elliot Condon
*/
include('core/api.php');
$acf = new Acf();
class Acf
{
var $dir,
$path,
$version,
$upgrade_version,
$fields,
$cache,
$defaults,
// controllers
$upgrade,
$settings,
$field_groups,
$field_group,
$input,
$options_page,
$everything_fields,
$third_party;
/*
* Constructor
*
* @description:
* @since 1.0.0
* @created: 23/06/12
*/
function __construct()
{
// vars
$this->path = plugin_dir_path(__FILE__);
$this->dir = plugins_url('',__FILE__);
$this->version = '3.5.4.2';
$this->upgrade_version = '3.4.1'; // this is the latest version which requires an upgrade
$this->cache = array(); // basic array cache to hold data throughout the page load
$this->defaults = array(
'options_page' => array(
'capability' => 'edit_posts', // capability to view options page
'title' => __('Options','acf'), // title / menu name ('Site Options')
'pages' => array(), // an array of sub pages ('Header, Footer, Home, etc')
),
'activation_codes' => array(
'repeater' => '', // activation code for the repeater add-on (XXXX-XXXX-XXXX-XXXX)
'options_page' => '', // activation code for the options page add-on (XXXX-XXXX-XXXX-XXXX)
'flexible_content' => '', // activation code for the flexible content add-on (XXXX-XXXX-XXXX-XXXX)
'gallery' => '', // activation code for the gallery add-on (XXXX-XXXX-XXXX-XXXX)
),
);
// set text domain
load_plugin_textdomain('acf', false, basename(dirname(__FILE__)).'/lang' );
// controllers
$this->setup_controllers();
// actions
add_action('init', array($this, 'init'));
add_action('admin_menu', array($this,'admin_menu'));
add_action('admin_head', array($this,'admin_head'));
add_action('acf_save_post', array($this, 'acf_save_post'), 10); // save post, called from many places (api, input, everything, options)
// filters
add_filter('acf_load_field', array($this, 'acf_load_field'), 5);
add_filter('post_updated_messages', array($this, 'post_updated_messages'));
add_filter('acf_parse_value', array($this, 'acf_parse_value'));
// ajax
add_action('wp_ajax_get_input_metabox_ids', array($this, 'get_input_metabox_ids'));
return true;
}
/*
* Init
*
* @description:
* @since 1.0.0
* @created: 23/06/12
*/
function init()
{
// setup defaults
$this->defaults = apply_filters('acf_settings', $this->defaults);
// allow for older filters
$this->defaults['options_page']['title'] = apply_filters('acf_options_page_title', $this->defaults['options_page']['title']);
// setup fields
$this->setup_fields();
// Create ACF post type
$labels = array(
'name' => __( 'Field Groups', 'acf' ),
'singular_name' => __( 'Advanced Custom Fields', 'acf' ),
'add_new' => __( 'Add New' , 'acf' ),
'add_new_item' => __( 'Add New Field Group' , 'acf' ),
'edit_item' => __( 'Edit Field Group' , 'acf' ),
'new_item' => __( 'New Field Group' , 'acf' ),
'view_item' => __('View Field Group', 'acf'),
'search_items' => __('Search Field Groups', 'acf'),
'not_found' => __('No Field Groups found', 'acf'),
'not_found_in_trash' => __('No Field Groups found in Trash', 'acf'),
);
register_post_type('acf', array(
'labels' => $labels,
'public' => false,
'show_ui' => true,
'_builtin' => false,
'capability_type' => 'page',
'hierarchical' => true,
'rewrite' => false,
'query_var' => "acf",
'supports' => array(
'title',
),
'show_in_menu' => false,
));
// register acf scripts
$scripts = array(
'acf-fields' => $this->dir . '/js/fields.js',
'acf-input-actions' => $this->dir . '/js/input-actions.js',
'acf-input-ajax' => $this->dir . '/js/input-ajax.js',
'acf-datepicker' => $this->dir . '/core/fields/date_picker/jquery.ui.datepicker.js',
);
foreach( $scripts as $k => $v )
{
wp_register_script( $k, $v, array('jquery'), $this->version );
}
// register acf styles
$styles = array(
'acf' => $this->dir . '/css/acf.css',
'acf-fields' => $this->dir . '/css/fields.css',
'acf-global' => $this->dir . '/css/global.css',
'acf-input' => $this->dir . '/css/input.css',
'acf-datepicker' => $this->dir . '/core/fields/date_picker/style.date_picker.css',
);
foreach( $styles as $k => $v )
{
wp_register_style( $k, $v, false, $this->version );
}
}
/*
* get_cache
*
* @description: Simple ACF (once per page) cache
* @since 3.1.9
* @created: 23/06/12
*/
function get_cache($key = false)
{
// key is required
if( !$key )
return false;
// does cache at key exist?
if( !isset($this->cache[$key]) )
return false;
// return cahced item
return $this->cache[$key];
}
/*
* set_cache
*
* @description: Simple ACF (once per page) cache
* @since 3.1.9
* @created: 23/06/12
*/
function set_cache($key = false, $value = null)
{
// key is required
if( !$key )
return false;
// update the cache array
$this->cache[$key] = $value;
// return true. Probably not needed
return true;
}
/*
* setup_fields
*
* @description: Create an array of field objects, including custom registered field types
* @since 1.0.0
* @created: 23/06/12
*/
function setup_fields()
{
// include parent field
include_once('core/fields/acf_field.php');
// include child fields
include_once('core/fields/acf_field.php');
include_once('core/fields/tab.php');
include_once('core/fields/text.php');
include_once('core/fields/textarea.php');
include_once('core/fields/wysiwyg.php');
include_once('core/fields/image.php');
include_once('core/fields/file.php');
include_once('core/fields/number.php');
include_once('core/fields/select.php');
include_once('core/fields/checkbox.php');
include_once('core/fields/radio.php');
include_once('core/fields/true_false.php');
include_once('core/fields/page_link.php');
include_once('core/fields/post_object.php');
include_once('core/fields/relationship.php');
include_once('core/fields/date_picker/date_picker.php');
include_once('core/fields/color_picker.php');
// add child fields
$this->fields['none'] = new acf_Field($this);
$this->fields['tab'] = new acf_Tab($this);
$this->fields['text'] = new acf_Text($this);
$this->fields['textarea'] = new acf_Textarea($this);
$this->fields['wysiwyg'] = new acf_Wysiwyg($this);
$this->fields['image'] = new acf_Image($this);
$this->fields['file'] = new acf_File($this);
$this->fields['number'] = new acf_Number($this);
$this->fields['select'] = new acf_Select($this);
$this->fields['checkbox'] = new acf_Checkbox($this);
$this->fields['radio'] = new acf_Radio($this);
$this->fields['true_false'] = new acf_True_false($this);
$this->fields['page_link'] = new acf_Page_link($this);
$this->fields['post_object'] = new acf_Post_object($this);
$this->fields['relationship'] = new acf_Relationship($this);
$this->fields['date_picker'] = new acf_Date_picker($this);
$this->fields['color_picker'] = new acf_Color_picker($this);
// add repeater
if($this->is_field_unlocked('repeater'))
{
include_once('core/fields/repeater.php');
$this->fields['repeater'] = new acf_Repeater($this);
}
// add flexible content
if($this->is_field_unlocked('flexible_content'))
{
include_once('core/fields/flexible_content.php');
$this->fields['flexible_content'] = new acf_Flexible_content($this);
}
// add gallery
if($this->is_field_unlocked('gallery'))
{
include_once('core/fields/gallery.php');
$this->fields['gallery'] = new acf_Gallery($this);
}
// hook to load in third party fields
$custom = apply_filters('acf_register_field',array());
if(!empty($custom))
{
foreach($custom as $v)
{
//var_dump($v['url']);
include($v['url']);
$name = $v['class'];
$custom_field = new $name($this);
$this->fields[$custom_field->name] = $custom_field;
}
}
}
/*
* setup_fields
*
* @description:
* @since 3.2.6
* @created: 23/06/12
*/
function setup_controllers()
{
// Settings
include_once('core/controllers/settings.php');
$this->settings = new acf_settings($this);
// upgrade
include_once('core/controllers/upgrade.php');
$this->upgrade = new acf_upgrade($this);
// field_groups
include_once('core/controllers/field_groups.php');
$this->field_groups = new acf_field_groups($this);
// field_group
include_once('core/controllers/field_group.php');
$this->field_group = new acf_field_group($this);
// input
include_once('core/controllers/input.php');
$this->input = new acf_input($this);
// options page
include_once('core/controllers/options_page.php');
$this->options_page = new acf_options_page($this);
// everthing fields
include_once('core/controllers/everything_fields.php');
$this->everything_fields = new acf_everything_fields($this);
// Third Party Compatibility
include_once('core/controllers/third_party.php');
$this->third_party = new acf_third_party($this);
}
/*
* admin_menu
*
* @description:
* @since 1.0.0
* @created: 23/06/12
*/
function admin_menu() {
// add acf page to options menu
add_utility_page(__("Custom Fields",'acf'), __("Custom Fields",'acf'), 'manage_options', 'edit.php?post_type=acf');
}
/*
* post_updated_messages
*
* @description: messages for saving a field group
* @since 1.0.0
* @created: 23/06/12
*/
function post_updated_messages( $messages )
{
global $post, $post_ID;
$messages['acf'] = array(
0 => '', // Unused. Messages start at index 1.
1 => __('Field group updated.', 'acf'),
2 => __('Custom field updated.', 'acf'),
3 => __('Custom field deleted.', 'acf'),
4 => __('Field group updated.', 'acf'),
/* translators: %s: date and time of the revision */
5 => isset($_GET['revision']) ? sprintf( __('Field group restored to revision from %s', 'acf'), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
6 => __('Field group published.', 'acf'),
7 => __('Field group saved.', 'acf'),
8 => __('Field group submitted.', 'acf'),
9 => __('Field group scheduled for.', 'acf'),
10 => __('Field group draft updated.', 'acf'),
);
return $messages;
}
/*--------------------------------------------------------------------------------------
*
* admin_head
*
* @author Elliot Condon
* @since 1.0.0
*
*-------------------------------------------------------------------------------------*/
function admin_head()
{
// hide upgrade page from nav
echo '<style type="text/css">
#toplevel_page_edit-post_type-acf a[href="edit.php?post_type=acf&page=acf-upgrade"]{ display:none; }
#toplevel_page_edit-post_type-acf .wp-menu-image { background: url("../wp-admin/images/menu.png") no-repeat scroll 0 -33px transparent; }
#toplevel_page_edit-post_type-acf:hover .wp-menu-image { background-position: 0 -1px; }
#toplevel_page_edit-post_type-acf .wp-menu-image img { display:none; }
</style>';
}
/*--------------------------------------------------------------------------------------
*
* get_field_groups
*
* This function returns an array of post objects found in the get_posts and the
* register_field_group calls.
*
* @author Elliot Condon
* @since 3.0.6
*
*-------------------------------------------------------------------------------------*/
function get_field_groups()
{
// return cache
$cache = $this->get_cache('acf_field_groups');
if($cache != false)
{
return $cache;
}
// vars
$acfs = array();
// get acf's
$result = get_posts(array(
'numberposts' => -1,
'post_type' => 'acf',
'orderby' => 'menu_order title',
'order' => 'asc',
'suppress_filters' => false,
));
// populate acfs
if($result)
{
foreach($result as $acf)
{
$acfs[] = array(
'id' => $acf->ID,
'title' => get_the_title($acf->ID),
'fields' => $this->get_acf_fields($acf->ID),
'location' => $this->get_acf_location($acf->ID),
'options' => $this->get_acf_options($acf->ID),
'menu_order' => $acf->menu_order,
);
}
}
// hook to load in registered field groups
$acfs = apply_filters('acf_register_field_group', $acfs);
// update cache
$this->set_cache('acf_field_groups', $acfs);
// return
if(empty($acfs))
{
return false;
}
return $acfs;
}
/*--------------------------------------------------------------------------------------
*
* get_acf_fields
* - returns an array of fields for a acf object
*
* @author Elliot Condon
* @since 1.0.0
*
*-------------------------------------------------------------------------------------*/
function get_acf_fields($post_id)
{
// vars
global $wpdb;
$return = array();
// get field from postmeta
$rows = $wpdb->get_results( $wpdb->prepare("SELECT meta_key FROM $wpdb->postmeta WHERE post_id = %d AND meta_key LIKE %s", $post_id, 'field\_%'), ARRAY_A);
if( $rows )
{
foreach( $rows as $row )
{
$field = $this->get_acf_field( $row['meta_key'], $post_id );
$return[ $field['order_no'] ] = $field;
}
ksort($return);
}
// return
return $return;
}
/*--------------------------------------------------------------------------------------
*
* get_acf_field
* - returns a field
* - $post_id can be passed to make sure the correct field is loaded. Eg: a duplicated
* field group may have the same field_key, but a different post_id
*
* @author Elliot Condon
* @since 1.0.0
*
*-------------------------------------------------------------------------------------*/
function get_acf_field( $field_key, $post_id = false )
{
// return cache
$cache = $this->get_cache('acf_field_' . $field_key);
if($cache != false)
{
return $cache;
}
// vars
global $wpdb;
// get field from postmeta
$sql = $wpdb->prepare("SELECT post_id, meta_value FROM $wpdb->postmeta WHERE meta_key = %s", $field_key);
if( $post_id )
{
$sql .= $wpdb->prepare("AND post_id = %d", $post_id);
}
$row = $wpdb->get_results( $sql, ARRAY_A );
if( $row )
{
$row = $row[0];
// return field if it is not in a trashed field group
if( get_post_status( $row['post_id'] ) != "trash" )
{
$row['meta_value'] = maybe_unserialize( $row['meta_value'] );
$row['meta_value'] = maybe_unserialize( $row['meta_value'] ); // run again for WPML
// store field
$field = $row['meta_value'];
// apply filters
$field = apply_filters('acf_load_field', $field);
$keys = array('type', 'name', 'key');
foreach( $keys as $key )
{
if( isset($field[ $key ]) )
{
$value = apply_filters('acf_load_field-' . $field[ $key ], $field);
}
}
// set cache
$this->set_cache('acf_field_' . $field_key, $field);
return $field;
}
}
// hook to load in registered field groups
$acfs = $this->get_field_groups();
if($acfs)
{
// loop through acfs
foreach($acfs as $acf)
{
// loop through fields
if($acf['fields'])
{
foreach($acf['fields'] as $field)
{
if($field['key'] == $field_key)
{
// apply filters
$field = apply_filters('acf_load_field', $field);
$keys = array('type', 'name', 'key');
foreach( $keys as $key )
{
if( isset($field[ $key ]) )
{
$value = apply_filters('acf_load_field-' . $field[ $key ], $field);
}
}
// set cache
$this->set_cache('acf_field_' . $field_key, $field);
return $field;
}
}
}
// if($acf['fields'])
}
// foreach($acfs as $acf)
}
// if($acfs)
return null;
}
/*
* acf_load_field
*
* @description:
* @since 3.5.1
* @created: 14/10/12
*/
function acf_load_field( $field )
{
if( !is_array($field) )
{
return $field;
}
$defaults = array(
'key' => '',
'label' => '',
'name' => '',
'type' => 'text',
'order_no' => 1,
'instructions' => '',
'required' => 0,
'conditional_logic' => array(
'status' => 0,
'allorany' => 'all',
'rules' => 0
),
);
$field = array_merge($defaults, $field);
// Parse Values
$field = apply_filters( 'acf_parse_value', $field );
return $field;
}
/*
* acf_parse_value
*
* @description:
* @since: 2.0.4
* @created: 9/12/12
*/
function acf_parse_value( $value )
{
// is value another array?
if( is_array($value) )
{
foreach( $value as $k => $v )
{
$value[ $k ] = apply_filters( 'acf_parse_value', $v );
}
}
else
{
// numbers
if( is_numeric($value) )
{
$value = (int) $value;
}
}
// return
return $value;
}
/*--------------------------------------------------------------------------------------
*
* create_field
*
* @author Elliot Condon
* @since 1.0.0
*
*-------------------------------------------------------------------------------------*/
function create_field($field)
{
if(!isset($this->fields[$field['type']]) || !is_object($this->fields[$field['type']]))
{
_e('Error: Field Type does not exist!','acf');
return false;
}
// defaults - class
if( !isset($field['class']) )
{
$field['class'] = $field['type'];
}
// defaults - id
// - isset is needed for the edit field group page where fields are created without many parameters
if( !isset($field['id']) )
{
if( isset($field['key']) )
{
$field['id'] = 'acf-' . $field['key'];
}
else
{
$field['id'] = 'acf-' . $field['name'];
}
}
$this->fields[ $field['type'] ]->create_field($field);
// conditional logic
// - isset is needed for the edit field group page where fields are created without many parameters
if( isset($field['conditional_logic']) && $field['conditional_logic']['status'] ):
$join = ' && ';
if( $field['conditional_logic']['allorany'] == "any" )
{
$join = ' || ';
}
?>
<script type="text/javascript">
(function($){
// create the conditional function
$(document).live('acf/conditional_logic/<?php echo $field['key']; ?>', function(){
var field = $('.field-<?php echo $field['key']; ?>');
<?php
$if = array();
foreach( $field['conditional_logic']['rules'] as $rule )
{
$if[] = 'acf.conditional_logic.calculate({ field : "'. $field['key'] .'", toggle : "' . $rule['field'] . '", operator : "' . $rule['operator'] .'", value : "' . $rule['value'] . '"})' ;
}
?>
if(<?php echo implode( $join, $if ); ?>)
{
field.show();
}
else
{
field.hide();
}
});
// add change events to all fields
<?php foreach( $field['conditional_logic']['rules'] as $rule ): ?>
$('.field-<?php echo $rule['field']; ?> *[name]').live('change', function(){
$(document).trigger('acf/conditional_logic/<?php echo $field['key']; ?>');
});
<?php endforeach; ?>
$(document).live('acf/setup_fields', function(e, postbox){
$(document).trigger('acf/conditional_logic/<?php echo $field['key']; ?>');
});
})(jQuery);
</script>
<?php
endif;
}
/*--------------------------------------------------------------------------------------
*
* get_acf_location
*
* @author Elliot Condon
* @since 1.0.0
*
*-------------------------------------------------------------------------------------*/
function get_acf_location($post_id)
{
// defaults
$return = array(
'rules' => array(),
'allorany' => 'all',
);
// vars
$allorany = get_post_meta($post_id, 'allorany', true);
if( $allorany )
{
$return['allorany'] = $allorany;
}
// get all fields
$rules = get_post_meta($post_id, 'rule', false);
if($rules)
{
foreach($rules as $rule)
{
// if field group was duplicated, it may now be a serialized string!
$rule = maybe_unserialize($rule);
$return['rules'][$rule['order_no']] = $rule;
}
}
// sort
ksort($return['rules']);
// return fields
return $return;
}
/*--------------------------------------------------------------------------------------
*
* get_acf_options
*
* @author Elliot Condon
* @since 1.0.0
*
*-------------------------------------------------------------------------------------*/
function get_acf_options($post_id)
{
// defaults
$options = array(
'position' => 'normal',
'layout' => 'no_box',
'hide_on_screen' => array(),
);
// vars
$position = get_post_meta($post_id, 'position', true);
if( $position )
{
$options['position'] = $position;
}
$layout = get_post_meta($post_id, 'layout', true);
if( $layout )
{
$options['layout'] = $layout;
}
$hide_on_screen = get_post_meta($post_id, 'hide_on_screen', true);
if( $hide_on_screen )
{
$hide_on_screen = maybe_unserialize($hide_on_screen);
$options['hide_on_screen'] = $hide_on_screen;
}
// return
return $options;
}
/*--------------------------------------------------------------------------------------
*
* get_value
*
* @author Elliot Condon
* @since 3.0.0
*
*-------------------------------------------------------------------------------------*/
function get_value($post_id, $field)
{
if( empty($this->fields) )
{
$this->setup_fields();
}
if( !isset($field['type'], $this->fields[ $field['type'] ]) )
{
return false;
}
return $this->fields[$field['type']]->get_value($post_id, $field);
}
/*--------------------------------------------------------------------------------------
*
* get_value_for_api
*
* @author Elliot Condon
* @since 3.0.0
*
*-------------------------------------------------------------------------------------*/
function get_value_for_api($post_id, $field)
{
if( empty($this->fields) )
{
$this->setup_fields();
}
if( !isset($field['type'], $this->fields[ $field['type'] ]) )
{
return false;
}
return $this->fields[$field['type']]->get_value_for_api($post_id, $field);