-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathframework.php
More file actions
executable file
·2144 lines (1842 loc) · 97.1 KB
/
framework.php
File metadata and controls
executable file
·2144 lines (1842 loc) · 97.1 KB
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
/**
* Redux Framework is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* any later version.
*
* Redux Framework is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Redux Framework. If not, see <http://www.gnu.org/licenses/>.
*
* @package ReduxFramework
* @author ReduxFramework Team
* @version 3.0.9
*/
// Exit if accessed directly
if( !defined( 'ABSPATH' ) ) exit;
if ( !function_exists( 'wp_get_current_user' ) ) {
// Fix from @kprovance. Bug #265.
require( ABSPATH . WPINC . '/pluggable.php' );
}
// Don't duplicate me!
if( !class_exists( 'ReduxFramework' ) ) {
/**
* Main ReduxFramework class
*
* @since 1.0.0
*/
class ReduxFramework {
public static $_version = '3.0.9';
public static $_dir;
public static $_url;
public static $_properties;
static function init() {
// Windows-proof constants: replace backward by forward slashes. Thanks to: @peterbouwmeester
self::$_dir = trailingslashit( str_replace( '\\', '/', dirname( __FILE__ ) ) );
$wp_content_dir = trailingslashit( str_replace( '\\', '/', WP_CONTENT_DIR ) );
$relative_url = str_replace( $wp_content_dir, '', self::$_dir );
self::$_url = trailingslashit( WP_CONTENT_URL ) . $relative_url;
/**
Still need to port these.
$defaults['footer_credit'] = '<span id="footer-thankyou">' . __( 'Options panel created using', 'redux-framework') . ' <a href="' . $this->framework_url . '" target="_blank">' . __('Redux Framework', 'redux-framework') . '</a> v' . self::$_version . '</span>';
$defaults['help_tabs'] = array();
$defaults['help_sidebar'] = ''; // __( '', 'redux-framework' );
$defaults['database'] = ''; // possible: options, theme_mods, theme_mods_expanded, transient
$defaults['customizer'] = false; // setting to true forces get_theme_mod_expanded
$defaults['global_variable'] = '';
$defaults['output'] = true; // Dynamically generate CSS
$defaults['transient_time'] = 60 * MINUTE_IN_SECONDS;
// The defaults are set so it will preserve the old behavior.
$defaults['default_show'] = false; // If true, it shows the default value
$defaults['default_mark'] = ''; // What to print by the field's title if the value shown is default
**/
self::$_properties = array(
'args' => array(
'opt_name' => array(
'required',
'data_type'=>'string',
'label'=>'Option Name',
'desc'=>'Must be defined by theme/plugin. Is the unique key allowing multiple instance of Redux within a single Wordpress instance.',
'default'=>''
),
'google_api_key' => array(
'data_type'=>'string',
'label'=>'Google Web Fonts API Key',
'desc'=>'Key used to request Google Webfonts. Google fonts are omitted without this.',
'default'=>''
),
'last_tab' => array( // Do we need this?
'data_type'=>'string',
'label'=>'Last Tab',
'desc'=>'Last tab used.',
'default'=>'0'
),
'menu_icon' => array(
'data_type'=>'string',
'label'=>'Default Menu Icon',
'desc'=>'Default menu icon used by sections when one is not specified.',
'default'=> self::$_url . 'assets/img/menu_icon.png'
),
'menu_title' => array(
'data_type'=>'string',
'label'=>'Menu Title',
'desc'=>'Label displayed when the admin menu is available.',
'default'=> __( 'Options', 'redux-framework' )
),
'page_title' => array(
'data_type'=>'string',
'label'=>'Page Title',
'desc'=>'Title used on the panel page.',
'default'=> __( 'Options', 'redux-framework' )
),
'page_icon' => array(
'data_type'=>'string',
'label'=>'Page Title',
'desc'=>'Icon class to be used on the options page.',
'default'=> 'icon-themes'
),
'page_slug' => array(
'required',
'data_type'=>'string',
'label'=>'Page Slug',
'desc'=>'Slug used to access options panel.',
'default'=> '_options'
),
'page_cap' => array(
'required',
'data_type'=>'string',
'label'=>'Page Capabilities',
'desc'=>'Permissions needed to access the options panel.',
'default'=> 'manage_options'
),
'page_type' => array(
'required',
'data_type' => 'varchar',
'label' => 'Page Type',
'desc' => 'Specify if the admin menu should appear or not.',
'default' => 'menu',
'form' => array('type' => 'select', 'options' => array('menu' => 'Admin Menu', 'submenu' => 'Submenu Only')),
'validation' => array('required'),
),
'page_parent' => array(
'required',
'data_type' => 'varchar',
'label' => 'Page Parent',
'desc' => 'Specify if the admin menu should appear or not.',
'default' => 'themes.php',
'form' => array('type' => 'select', 'options' => array('index.php' => 'Dashboard', 'edit.php' => 'Posts', 'upload.php' => 'Media', 'link-manager.php' => 'Links', 'edit.php?post_type=page' => 'pages', 'edit-comments.php' => 'Comments', 'themes.php' => 'Appearance', 'plugins.php' => 'Plugins', 'users.php' => 'Users', 'tools.php' => 'Tools', 'options-general.php' => 'Settings', )),
'validation' => array('required'),
),
'page_position' => array(
'type'=>'int',
'label'=>'Page Position',
'desc'=>'Location where this menu item will appear in the admin menu. Warning, beware of overrides.',
'default'=> null
),
'enqueue' => array(
'required',
'data_type'=>'bool',
'form' => array('type' => 'radio', 'options' => array(true => 'Enabled', false => 'Disabled')),
'label'=>'Enqueue Files',
'desc'=>'Global shut-off for custom CSS enqueing by the framework',
'default'=>true
),
'allow_sub_menu' => array(
'data_type'=>'bool',
'form' => array('type' => 'radio', 'options' => array(true => 'Enabled', false => 'Disabled')),
'label'=>'Allow Submenu',
'desc'=>'Turn on or off the submenu that will typically be shown under Appearance.',
'default'=>true
),
'show_import_export' => array(
'data_type'=>'bool',
'form' => array('type' => 'radio', 'options' => array(true => 'Show', false => 'Hide')),
'label'=>'Show Import/Export',
'desc'=>'Show/Hide the import/export tab.',
'default'=>true
),
'dev_mode' => array(
'data_type'=>'bool',
'form' => array('type' => 'radio', 'options' => array(true => 'Enabled', false => 'Disabled')),
'label'=>'Developer Mode',
'desc'=>'Turn on or off the dev mode tab.',
'default'=>false
),
'system_info' => array(
'data_type'=>'bool',
'form' => array('type' => 'radio', 'options' => array(true => 'Enabled', false => 'Disabled')),
'label'=>'System Info',
'desc'=>'Turn on or off the system info tab.',
'default'=>false
),
),
);
}
// Protected vars
// These two are actually really unnecessary and should be deprecated
protected $framework_url = 'http://www.reduxframework.com/';
/** @var ReduxFramework $instance */
public $instance = null;
// Public vars
public $page = '';
public $args = array();
public $sections = array();
public $errors = array();
public $warnings = array();
public $options = array();
public $options_defaults = null;
public $folds = array();
public $path = '';
public $output = array(); // Fields with CSS output selectors
public $fieldsValues = array(); //all fields values in an id=>value array so we can check dependencies
public $fieldsHidden = array(); //all fields that didn't pass the dependency test and are hidden
/**
* Class Constructor. Defines the args for the theme options class
* @since 1.0.0
* @param array $sections Panel sections.
* @param array $args Class constructor arguments.
* @param array $extra_tabs Extra panel tabs. // REMOVE
* @return \ReduxFramework
*/
public function __construct( $sections = array(), $args = array(), $extra_tabs = array() ) {
// Create defaults array
$defaults = array();
$defaults['opt_name'] = ''; // Must be defined by theme/plugin
$defaults['google_api_key'] = ''; // Must be defined to add google fonts to the typography module
$defaults['last_tab'] = '0';
$defaults['menu_icon'] = self::$_url . 'assets/img/menu_icon.png';
if (defined('MP6')) {
$defaults['menu_icon'] = '';
}
$defaults['menu_title'] = __( 'Options', 'redux-framework' );
$defaults['page_icon'] = 'icon-themes';
$defaults['page_title'] = __( 'Options', 'redux-framework' );
$defaults['page_slug'] = '_options';
$defaults['page_cap'] = 'manage_options';
$defaults['page_type'] = 'menu';
$defaults['page_parent'] = 'themes.php';
$defaults['page_position'] = null;
$defaults['enqueue'] = true;
$defaults['allow_sub_menu'] = true;
$defaults['show_import_export'] = true; // REMOVE
$defaults['dev_mode'] = false; // REMOVE
$defaults['system_info'] = false; // REMOVE
$defaults['footer_credit'] = '<span id="footer-thankyou">' . __( 'Options panel created using', 'redux-framework') . ' <a href="' . $this->framework_url . '" target="_blank">' . __('Redux Framework', 'redux-framework') . '</a> v' . self::$_version . '</span>';
$defaults['help_tabs'] = array();
$defaults['help_sidebar'] = ''; // __( '', 'redux-framework' );
$defaults['database'] = ''; // possible: options, theme_mods, theme_mods_expanded, transient
$defaults['customizer'] = false; // setting to true forces get_theme_mod_expanded
$defaults['global_variable'] = '';
$defaults['output'] = true; // Dynamically generate CSS
/** @noinspection PhpUndefinedConstantInspection */
$defaults['transient_time'] = 60 * MINUTE_IN_SECONDS;
// The defaults are set so it will preserve the old behavior.
$defaults['default_show'] = false; // If true, it shows the default value
$defaults['default_mark'] = ''; // What to print by the field's title if the value shown is default
// Set values
$this->args = wp_parse_args( $args, $defaults );
if ( empty( $this->path ) ) {
$this->path = trailingslashit( str_replace( '\\', '/', dirname( __FILE__ ) ) );
$this->url = site_url( str_replace( trailingslashit( str_replace( '\\', '/', ABSPATH ) ), '', $this->path ) );
}
if ( $this->args['global_variable'] !== false ) {
if ( $this->args['global_variable'] == "" ) {
$this->args['global_variable'] = str_replace('-', '_', $this->args['opt_name']);
}
$variable = $this->args['global_variable'];
global $$variable;
if ( empty( $$variable ) ) {
$this->options = $this->get_options();
}
}
$this->sections = apply_filters('redux-sections',$sections); // REMOVE LATER
$this->sections = apply_filters('redux/options/'.$this->args['opt_name'].'/sections',$sections);
if( is_array( $extra_tabs ) && !empty( $extra_tabs ) ) {
foreach( $extra_tabs as $k => $tab ) {
array_push($this->sections, $tab);
}
}
// Set option with defaults
add_action( 'init', array( &$this, '_set_default_options' ) );
// Options page
add_action( 'admin_menu', array( &$this, '_options_page' ) );
// Register extensions
add_action( 'init', array( &$this, '_register_extensions' ) );
// Register setting
add_action( 'admin_init', array( &$this, '_register_setting' ) );
// Register extensions
add_action( 'init', array( &$this, '_register_extensions' ) );
// Any dynamic CSS output, let's run
if( $this -> args[ 'output' ] == true ){
add_action( 'wp_head', array( &$this, '_enqueue_output' ), 100 );
}
// Add tracking. PLEASE leave this in tact! It helps us gain needed statistics of uses. Opt-in of course.
add_action( 'init', array( &$this, '_tracking' ), 3 );
// Hook into the WP feeds for downloading exported settings
add_action( 'do_feed_reduxopts-' . $this->args['opt_name'], array( &$this, '_download_options' ), 1, 1 );
// Load plugin text domain
add_action( 'wp_loaded', array( &$this, '_internationalization' ) );
}
/**
* Load the plugin text domain for translation.
*
* @since 3.0.5
*/
public function _internationalization() {
$domain = 'redux-framework';
$locale = apply_filters( 'redux/textdomain/'.$this->args['opt_name'], get_locale(), $domain );
load_textdomain( $domain, trailingslashit( WP_LANG_DIR ) . $domain . '/' . $domain . '-' . $locale . '.mo' );
load_textdomain( $domain, dirname( __FILE__ ) . '/languages/' . $domain . '-' . $locale . '.mo' );
}
/**
* @return ReduxFramework
*/
public function get_instance() {
return $this->instance;
}
public function _tracking() {
include_once( dirname( __FILE__ ) . '/inc/tracking.php' );
/** @noinspection PhpUnusedLocalVariableInspection */
$redux_tracking = new Redux_Tracking($this);
}
/**
* ->_get_default(); This is used to return the default value if default_show is set
*
* @since 1.0.1
* @access public
* @param string $opt_name The option name to return
* @param mixed $default (null) The value to return if default not set
* @return mixed $default
*/
public function _get_default( $opt_name, $default = null ) {
if( $this->args['default_show'] == true ) {
if( is_null( $this->options_defaults ) ) {
$this->_default_values(); // fill cache
}
$default = array_key_exists( $opt_name, $this->options_defaults ) ? $this->options_defaults[$opt_name] : $default;
}
return $default;
}
/**
* ->get(); This is used to return and option value from the options array
*
* @since 1.0.0
* @access public
* @param string $opt_name The option name to return
* @param mixed $default (null) The value to return if option not set
* @return mixed
*/
public function get( $opt_name, $default = null ) {
return ( !empty( $this->options[$opt_name] ) ) ? $this->options[$opt_name] : $this->_get_default( $opt_name, $default );
}
/**
* ->set(); This is used to set an arbitrary option in the options array
*
* @since 1.0.0
* @access public
* @param string $opt_name The name of the option being added
* @param mixed $value The value of the option being added
* @return void
*/
public function set( $opt_name = '', $value = '' ) {
if( $opt_name != '' ) {
$this->options[$opt_name] = $value;
$this->set_options( $this->options );
}
}
/**
* ->set_options(); This is used to set an arbitrary option in the options array
*
* @since ReduxFramework 3.0.0
* @param mixed $value the value of the option being added
*/
function set_options( $value = '' ) {
$value['REDUX_last_saved'] = time();
if( !empty($value) ) {
if ( $this->args['database'] === 'transient' ) {
set_transient( $this->args['opt_name'] . '-transient', $value, $this->args['transient_time'] );
} else if ( $this->args['database'] === 'theme_mods' ) {
set_theme_mod( $this->args['opt_name'] . '-mods', $value );
} else if ( $this->args['database'] === 'theme_mods_expanded' ) {
foreach ( $value as $k=>$v ) {
set_theme_mod( $k, $v );
}
} else {
update_option( $this->args['opt_name'], $value );
}
// Set a global variable by the global_variable argument.
if ( $this->args['global_variable'] ) {
$options = $this->args['global_variable'];
global $$options;
$$options = $value;
}
do_action( 'redux-saved-' . $this->args['opt_name'] , $value ); // REMOVE
do_action( 'redux/options/'.$this->args['opt_name'].'/saved', $value );
}
}
/**
* ->get_options(); This is used to get options from the database
*
* @since ReduxFramework 3.0.0
*/
function get_options() {
$defaults = false;
if ( !empty( $this->defaults ) ) {
$defaults = $this->defaults;
}
if ( $this->args['database'] === "transient" ) {
$result = get_transient( $this->args['opt_name'] . '-transient' );
} else if ($this->args['database'] === "theme_mods" ) {
$result = get_theme_mod( $this->args['opt_name'] . '-mods' );
} else if ( $this->args['database'] === 'theme_mods_expanded' ) {
$result = get_theme_mods();
} else {
$result = get_option( $this->args['opt_name']);
}
if ( empty( $result ) && !empty( $defaults ) ) {
$results = $defaults;
$this->set_options($results);
}
// Set a global variable by the global_variable argument.
if ( $this->args['global_variable'] ) {
$options = $this->args['global_variable'];
global $$options;
$$options = $result;
}
//print_r($result);
return $result;
}
/**
* ->get_options(); This is used to get options from the database
*
* @since ReduxFramework 3.0.0
*/
function get_wordpress_data($type = false, $args = array()) {
$data = "";
if ( !empty($type) ) {
$data = apply_filters( 'redux/options/'.$this->args['opt_name'].'/wordpress_data/'.$type.'/', $data ); // REMOVE LATER
$data = apply_filters( 'redux/options/'.$this->args['opt_name'].'/data/'.$type, $data );
/**
Use data from Wordpress to populate options array
**/
if (!empty($type) && empty($data)) {
if (empty($args)) {
$args = array();
}
$data = array();
$args = wp_parse_args($args, array());
if ($type == "categories" || $type == "category") {
$cats = get_categories($args);
if (!empty($cats)) {
foreach ( $cats as $cat ) {
$data[$cat->term_id] = $cat->name;
}//foreach
} // If
} else if ($type == "menus" || $type == "menu") {
$menus = wp_get_nav_menus($args);
if(!empty($menus)) {
foreach ($menus as $item) {
$data[$item->term_id] = $item->name;
}//foreach
}//if
} else if ($type == "pages" || $type == "page") {
$pages = get_pages($args);
if (!empty($pages)) {
foreach ( $pages as $page ) {
$data[$page->ID] = $page->post_title;
}//foreach
}//if
} else if ($type == "terms" || $type == "term") {
$taxonomies = $args['taxonomies'];
unset($args['taxonomies']);
if (empty($args)) {
$args = array();
}
$terms = get_terms($taxonomies, $args); // this will get nothing
if (!empty($terms)) {
foreach ( $terms as $term ) {
$data[$term->term_id] = $term->name;
}//foreach
} // If
} else if ($type == "posts" || $type == "post") {
$posts = get_posts($args);
if (!empty($posts)) {
foreach ( $posts as $post ) {
$data[$post->ID] = $post->post_title;
}//foreach
}//if
} else if ($type == "post_type" || $type == "post_types") {
$post_types = get_post_types($args, 'object');
if (!empty($post_types)) {
foreach ( $post_types as $k => $post_type ) {
$data[$k] = $post_type->labels->name;
}//foreach
}//if
} else if ($type == "tags" || $type == "tag") {
$tags = get_tags($args);
if (!empty($tags)) {
foreach ( $tags as $tag ) {
$data[$tag->term_id] = $tag->name;
}//foreach
}//if
} else if ($type == "menu_location" || $type == "menu_locations") {
global $_wp_registered_nav_menus;
foreach($_wp_registered_nav_menus as $k => $v) {
$data[$k] = $v;
}
}//if
else if ($type == "elusive-icons" || $type == "elusive-icon" || $type == "elusive" ||
$type == "font-icon" || $type == "font-icons" || $type == "icons") {
$font_icons = apply_filters('redux-font-icons',array()); // REMOVE LATER
$font_icons = apply_filters('redux/font-icons',array());
foreach($font_icons as $k) {
$data[$k] = $k;
}
}else if ($type == "roles") {
/** @global WP_Roles $wp_roles */
global $wp_roles;
$data = $wp_roles->get_names();
}else if ($type == "sidebars" || $type == "sidebar") {
/** @global array $wp_registered_sidebars */
foreach ($wp_registered_sidebars as $key=>$value) {
$data[$key] = $value['name'];
}
}else if ($type == "capabilities") {
/** @global WP_Roles $wp_roles */
global $wp_roles;
foreach( $wp_roles->roles as $role ){
foreach( $role['capabilities'] as $key => $cap ){
$data[$key] = ucwords(str_replace('_', ' ', $key));
}
}
}else if ($type == "callback") {
$data = call_user_func($args[0]);
}//if
}//if
}//if
return $data;
}
/**
* ->show(); This is used to echo and option value from the options array
*
* @since 1.0.0
* @access public
* @param string $opt_name The name of the option being shown
* @param mixed $default The value to show if $opt_name isn't set
* @return void
*/
public function show( $opt_name, $default = '' ) {
$option = $this->get( $opt_name );
if( !is_array( $option ) && $option != '' ) {
echo $option;
} elseif( $default != '' ) {
echo $this->_get_default( $opt_name, $default );
}
}
/**
* Get default options into an array suitable for the settings API
*
* @since 1.0.0
* @access public
* @return array $this->options_defaults
*/
public function _default_values() {
if( !is_null( $this->sections ) && is_null( $this->options_defaults ) ) {
// fill the cache
foreach( $this->sections as $section ) {
if( isset( $section['fields'] ) ) {
foreach( $section['fields'] as $field ) {
if( isset( $field['default'] ) ) {
$this->options_defaults[$field['id']] = $field['default'];
}
}
}
}
}
$this->options_defaults = apply_filters( 'redux/options/'.$this->args['opt_name'].'/defaults', $this->options_defaults );
return $this->options_defaults;
}
/**
* Get fold values into an array suitable for setting folds
*
* @since ReduxFramework 1.0.0
*/
function _fold_values() {
/*
Folds work by setting the folds value like so
$this->folds['parentID']['parentValue'][] = 'childId'
*/
// $folds = array();
if( !is_null( $this->sections ) && is_null( $this->options_defaults ) ) {
foreach( $this->sections as $section ) {
if( isset( $section['fields'] ) ) {
foreach( $section['fields'] as $field ) {
//if we have required option in group field
if(isset($field['subfields']) && is_array($field['subfields'])){
foreach ($field['subfields'] as $subfield) {
if(isset($subfield['required']))
$this->get_fold($subfield);
}
}
if( isset( $field['required'] ) ) {
$this->get_fold($field);
}
}
}
}
}
/*
$parents = array();
$toHide = array();
foreach ($folds as $k=>$fold) { // ParentFolds WITHOUT parents
if ( empty( $fold['children'] ) || !empty( $fold['children']['parents'] ) ) {
continue;
}
$fold['value'] = $this->options[$k];
foreach ($fold['children'] as $key =>$value) {
if ($key == $fold['value']) {
unset($fold['children'][$key]);
}
}
if (empty($fold['children'])) {
continue;
}
foreach ($fold['children'] as $key => $value) {
foreach ($value as $k=> $hidden) {
$toHide[$hidden]=true;
}
}
$parents[] = $fold;
}
print_r($parents);
print_r($toHide);
*/
return $this->folds;
}
/**
* @param array $field
* @return array
*/
function get_fold($field){
if ( !is_array( $field['required'] ) ) {
/*
Example variable:
$var = array(
'fold' => 'id'
);
*/
$this->folds[$field['required']]['children'][1][] = $field['id'];
$this->folds[$field['id']]['parent'] = $field['required'];
} else {
// $parent = $foldk = $field['required'][0];
$foldk = $field['required'][0];
// $comparison = $field['required'][1];
$value = $foldv = $field['required'][2];
//foreach( $field['required'] as $foldk=>$foldv ) {
if ( is_array( $value ) ) {
/*
Example variable:
$var = array(
'fold' => array( 'id' , '=', array(1, 5) )
);
*/
foreach ($value as $foldvValue) {
//echo 'id: '.$field['id']." key: ".$foldk.' f-val-'.print_r($foldv)." foldvValue".$foldvValue;
$this->folds[$foldk]['children'][$foldvValue][] = $field['id'];
$this->folds[$field['id']]['parent'] = $foldk;
}
} else {
//!DOVY If there's a problem, this is where it's at. These two cases.
//This may be able to solve this issue if these don't work
//if (count($field['fold']) == count($field['fold'], COUNT_RECURSIVE)) {
//}
if (count($field['required']) === 1 && is_numeric($foldk)) {
/*
Example variable:
$var = array(
'fold' => array( 'id' )
);
*/
$this->folds[$field['id']]['parent'] = $foldk;
$this->folds[$foldk]['children'][1][] = $field['id'];
} else {
/*
Example variable:
$var = array(
'fold' => array( 'id' => 1 )
);
*/
if (empty($foldv)) {
$foldv = 0;
}
$this->folds[$field['id']]['parent'] = $foldk;
$this->folds[$foldk]['children'][$foldv][] = $field['id'];
}
}
//}
}
return $this->folds;
}
/**
* Set default options on admin_init if option doesn't exist
*
* @since 1.0.0
* @access public
* @return void
*/
public function _set_default_options() {
$this->instance = $this;
// Get args
$this->args = apply_filters( 'redux-args-'.$this->args['opt_name'], $this->args ); // REMOVE
$this->args = apply_filters( 'redux/options/'.$this->args['opt_name'].'/args', $this->args );
// Fix the global variable name
if ( $this->args['global_variable'] == "" && $this->args['global_variable'] !== false ) {
$this->args['global_variable'] = str_replace('-', '_', $this->args['opt_name']);
}
// Get sections
$this->sections = apply_filters( 'redux-sections-' . $this->args['opt_name'], $this->sections ); // REMOVE
$this->sections = apply_filters( 'redux/options/' . $this->args['opt_name'].'/sections', $this->sections );
// Grab database values
$this->options = $this->get_options();
// Get the fold values
$this->folds = $this->_fold_values();
// Set defaults if empty
if( empty( $this->options ) && !empty( $this->sections ) ) {
$defaults = $this->_default_values();
$this->set_options( $defaults );
$this->options = $defaults;
}
}
/**
* Class Options Page Function, creates main options page.
* @since 1.0.0
* @access public
* @return void
*/
function _options_page() {
if( $this->args['page_type'] == 'submenu' ) {
$this->page = add_submenu_page(
$this->args['page_parent'],
$this->args['page_title'],
$this->args['menu_title'],
$this->args['page_cap'],
$this->args['page_slug'],
array( &$this, '_options_page_html' )
);
} else {
$this->page = add_menu_page(
$this->args['page_title'],
$this->args['menu_title'],
$this->args['page_cap'],
$this->args['page_slug'],
array( &$this, '_options_page_html' ),
$this->args['menu_icon'],
$this->args['page_position']
);
if( true === $this->args['allow_sub_menu'] ) {
if( !isset( $section['type'] ) || $section['type'] != 'divide' ) {
foreach( $this->sections as $k => $section ) {
if ( !isset( $section['title'] ) )
continue;
if ( isset( $section['submenu'] ) && $section['submenu'] == false )
continue;
add_submenu_page(
$this->args['page_slug'],
$section['title'],
$section['title'],
$this->args['page_cap'],
$this->args['page_slug'] . '&tab=' . $k,
create_function( '$a', "return null;" )
);
}
// Remove parent submenu item instead of adding null item.
remove_submenu_page( $this->args['page_slug'], $this->args['page_slug'] );
}
if( true === $this->args['show_import_export'] ) {
add_submenu_page(
$this->args['page_slug'],
__( 'Import / Export', 'redux-framework' ),
__( 'Import / Export', 'redux-framework' ),
$this->args['page_cap'],
$this->args['page_slug'] . '&tab=import_export_default',
create_function( '$a', "return null;" )
);
}
if( true === $this->args['dev_mode'] ) {
add_submenu_page(
$this->args['page_slug'],
__( 'Options Object', 'redux-framework' ),
__( 'Options Object', 'redux-framework' ),
$this->args['page_cap'],
$this->args['page_slug'] . '&tab=dev_mode_default',
create_function('$a', "return null;")
);
}
if( true === $this->args['system_info'] ) {
add_submenu_page(
$this->args['page_slug'],
__( 'System Info', 'redux-framework' ),
__( 'System Info', 'redux-framework' ),
$this->args['page_cap'],
$this->args['page_slug'] . '&tab=system_info_default',
create_function( '$a', "return null;" )
);
}
}
}
add_action( 'admin_print_styles-' . $this->page, array( &$this, '_enqueue' ) );
add_action( 'load-' . $this->page, array( &$this, '_load_page' ) );
}
/**
* Enqueue CSS/JS for options page
*
* @since 1.0.0
* @access public
* @global $wp_styles
* @return void
*/
public function _enqueue_output() {
/** @noinspection PhpUnusedLocalVariableInspection */
foreach( $this->sections as $k => $section ) {
if( isset($section['type'] ) && $section['type'] == 'divide' ) {
continue;
}
if( isset( $section['fields'] ) ) {
/** @noinspection PhpUnusedLocalVariableInspection */
foreach( $section['fields'] as $fieldk => $field ) {
if( isset( $field['type'] ) ) {
$field_class = 'ReduxFramework_' . $field['type'];
if( !class_exists( $field_class ) ) {
$class_file = apply_filters( 'redux/field/class/'.$field['type'], self::$_dir . 'inc/fields/' . $field['type'] . '/field_' . $field['type'] . '.php', $field );
if( $class_file ) {
/** @noinspection PhpIncludeInspection */
require_once( $class_file );
}
}
if( !empty( $this->options[$field['id']] ) && class_exists( $field_class ) && method_exists( $field_class, 'output' ) ) {
if ( !empty($field['output']) && !is_array( $field['output'] ) ) {
$field['output'] = array( $field['output'] );
}
$value = isset($this->options[$field['id']])?$this->options[$field['id']]:'';
$enqueue = new $field_class( $field, $value, $this );
/** @noinspection PhpUndefinedMethodInspection */
$enqueue->output();
}
}
}
}
}
}
/**
* Enqueue CSS/JS for options page
*
* @since 1.0.0
* @access public
* @global $wp_styles
* @return void
*/
public function _enqueue() {
global $wp_styles;
wp_enqueue_script('jquery');
wp_enqueue_script('jquery-ui-core');
wp_enqueue_script('jquery-ui-sortable');
add_thickbox();
wp_register_style(
'redux-css',
self::$_url . 'assets/css/style.css',
array( 'farbtastic' ),
time(),
'all'
);
wp_register_style(
'redux-elusive-icon',
self::$_url . 'assets/css/vendor/elusive-icons/elusive-webfont.css',
array(),
time(),
'all'
);
wp_register_style(
'redux-elusive-icon-ie7',
self::$_url . 'assets/css/vendor/elusive-icons/elusive-webfont-ie7.css',
array(),
time(),
'all'
);
wp_register_style(
'select2-css',
self::$_url . 'assets/js/vendor/select2/select2.css',
array(),
time(),
'all'
);
$wp_styles->add_data( 'redux-elusive-icon-ie7', 'conditional', 'lte IE 7' );
wp_register_style(
'jquery-ui-css',
apply_filters( 'redux/page/'.$this->args['opt_name'].'/enqueue/jquery-ui-css', self::$_url . 'assets/css/vendor/jquery-ui-bootstrap/jquery-ui-1.10.0.custom.css' ),
'',
time(),
'all'
);
wp_enqueue_style( 'jquery-ui-css' );
wp_enqueue_style( 'redux-lte-ie8' );
wp_enqueue_style( 'redux-css' );
wp_enqueue_style( 'redux-elusive-icon' );
wp_enqueue_style( 'redux-elusive-icon-ie7' );
if ( $this->args['dev_mode'] === true) { // Pretty object output
wp_enqueue_script(
'json-view-js',
self::$_url . 'assets/js/vendor/jsonview.min.js',
array( 'jquery' ),