forked from reduxframework/redux-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathframework.php
4304 lines (3619 loc) · 204 KB
/
framework.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
/**
* 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 3 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 Redux_Framework
* @subpackage Core
* @author Redux Framework Team
*/
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
// Fix for the GT3 page builder: http://www.gt3themes.com/wordpress-gt3-page-builder-plugin/
/** @global string $pagenow */
if ( has_action( 'ecpt_field_options_' ) ) {
global $pagenow;
if ( $pagenow === 'admin.php' ) {
/** @noinspection PhpUndefinedCallbackInspection */
remove_action( 'admin_init', 'pb_admin_init' );
}
}
if ( ! class_exists( 'ReduxFrameworkInstances' ) ) {
// Instance Container
require_once( dirname( __FILE__ ) . '/inc/class.redux_instances.php' );
require_once( dirname( __FILE__ ) . '/inc/lib.redux_instances.php' );
}
if ( class_exists( 'ReduxFrameworkInstances' ) ) {
add_action( 'redux/init', 'ReduxFrameworkInstances::get_instance' );
}
// Don't duplicate me!
if ( ! class_exists( 'ReduxFramework' ) ) {
// General helper functions
require_once( dirname( __FILE__ ) . '/inc/class.redux_helpers.php' );
// General functions
require_once( dirname( __FILE__ ) . '/inc/class.redux_functions.php' );
require_once( dirname( __FILE__ ) . '/inc/class.p.php' );
require_once( dirname( __FILE__ ) . '/inc/class.redux_filesystem.php' );
// ThemeCheck checks
require_once( dirname( __FILE__ ) . '/inc/class.redux_themecheck.php' );
/**
* Main ReduxFramework class
*
* @since 1.0.0
*/
class ReduxFramework {
// ATTENTION DEVS
// Please update the build number with each push, no matter how small.
// This will make for easier support when we ask users what version they are using.
public static $_version = '3.3.8.8';
public static $_dir;
public static $_url;
public static $_upload_dir;
public static $_upload_url;
public static $wp_content_url;
public static $base_wp_content_url;
public static $_is_plugin = true;
public static $_as_plugin = false;
public static function init() {
$dir = Redux_Helpers::cleanFilePath( dirname( __FILE__ ) );
// Windows-proof constants: replace backward by forward slashes. Thanks to: @peterbouwmeester
self::$_dir = trailingslashit( $dir );
self::$wp_content_url = trailingslashit( Redux_Helpers::cleanFilePath( ( is_ssl() ? str_replace( 'http://', 'https://', WP_CONTENT_URL ) : WP_CONTENT_URL ) ) );
// See if Redux is a plugin or not
if ( strpos( Redux_Helpers::cleanFilePath( __FILE__ ), Redux_Helpers::cleanFilePath( get_stylesheet_directory() ) ) !== false || strpos( Redux_Helpers::cleanFilePath( __FILE__ ), Redux_Helpers::cleanFilePath( get_template_directory_uri() ) ) !== false || strpos( Redux_Helpers::cleanFilePath( __FILE__ ), Redux_Helpers::cleanFilePath( WP_CONTENT_DIR . '/themes/' ) ) !== false ) {
self::$_is_plugin = false;
} else {
// Check if plugin is a symbolic link, see if it's a plugin. If embedded, we can't do a thing.
if ( strpos( self::$_dir, ABSPATH ) === false ) {
if ( ! function_exists( 'get_plugins' ) ) {
require_once ABSPATH . 'wp-admin/includes/plugin.php';
}
$is_plugin = false;
foreach ( get_plugins() as $key => $value ) {
if ( strpos( $key, 'redux-framework.php' ) !== false ) {
self::$_dir = trailingslashit( Redux_Helpers::cleanFilePath( WP_CONTENT_DIR . '/plugins/' . plugin_dir_path( $key ) . 'ReduxCore/' ) );
$is_plugin = true;
}
}
if ( ! $is_plugin ) {
self::$_is_plugin = false;
}
}
}
if ( self::$_is_plugin == true || self::$_as_plugin == true ) {
self::$_url = plugin_dir_url( __FILE__ );
} else {
if ( strpos( Redux_Helpers::cleanFilePath( __FILE__ ), Redux_Helpers::cleanFilePath( get_template_directory() ) ) !== false ) {
$relative_url = str_replace( Redux_Helpers::cleanFilePath( get_template_directory() ), '', self::$_dir );
self::$_url = trailingslashit( get_template_directory_uri() . $relative_url );
} else if ( strpos( Redux_Helpers::cleanFilePath( __FILE__ ), Redux_Helpers::cleanFilePath( get_stylesheet_directory() ) ) !== false ) {
$relative_url = str_replace( Redux_Helpers::cleanFilePath( get_stylesheet_directory() ), '', self::$_dir );
self::$_url = trailingslashit( get_stylesheet_directory_uri() . $relative_url );
} else {
$wp_content_dir = trailingslashit( Redux_Helpers::cleanFilePath( WP_CONTENT_DIR ) );
$wp_content_dir = trailingslashit( str_replace( '//', '/', $wp_content_dir ) );
$relative_url = str_replace( $wp_content_dir, '', self::$_dir );
self::$_url = trailingslashit( self::$wp_content_url . $relative_url );
}
}
self::$_url = apply_filters( "redux/_url", self::$_url );
self::$_dir = apply_filters( "redux/_dir", self::$_dir );
self::$_is_plugin = apply_filters( "redux/_is_plugin", self::$_is_plugin );
}
// ::init()
public $framework_url = 'http://www.reduxframework.com/';
public static $instance = null;
public $admin_notices = array();
public $page = '';
public $saved = false;
public $fields = array(); // Fields by type used in the panel
public $current_tab = ''; // Current section to display, cookies
public $extensions = array(); // Extensions by type used in the panel
public $sections = array(); // Sections and fields
public $errors = array(); // Errors
public $warnings = array(); // Warnings
public $options = array(); // Option values
public $options_defaults = null; // Option defaults
public $notices = array(); // Option defaults
public $compiler_fields = array(); // Fields that trigger the compiler hook
public $required = array(); // Information that needs to be localized
public $required_child = array(); // Information that needs to be localized
public $localize_data = array(); // Information that needs to be localized
public $fonts = array(); // Information that needs to be localized
public $folds = array(); // The itms that need to fold.
public $path = '';
public $changed_values = array(); // Values that have been changed on save. Orig values.
public $output = array(); // Fields with CSS output selectors
public $outputCSS = null; // CSS that get auto-appended to the header
public $compilerCSS = null; // CSS that get sent to the compiler hook
public $customizerCSS = null; // CSS that goes to the customizer
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
public $toHide = array(); // Values to hide on page load
public $typography = null; //values to generate google font CSS
public $import_export = null;
public $debug = null;
public $no_panel = array(); // Fields that are not visible in the panel
private $show_hints = false;
private $hidden_perm_fields = array(); // Hidden fields specified by 'permissions' arg.
private $hidden_perm_sections = array(); // Hidden sections specified by 'permissions' arg.
public $typography_preview = array();
public $args = array();
public $filesystem = null;
/**
* 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() ) {
// Disregard WP AJAX 'heartbeat'call. Why waste resources?
if ( isset( $_POST ) && isset( $_POST['action'] ) && $_POST['action'] == 'heartbeat' ) {
// Hook, for purists.
if ( ! has_action( 'redux/ajax/heartbeat' ) ) {
do_action( 'redux/ajax/heartbeat', $this );
}
// Buh bye!
return;
}
// Pass parent pointer to function helper.
Redux_Functions::$_parent = $this;
// Set values
$this->set_default_args();
$this->args = wp_parse_args( $args, $this->args );
if ( empty( $this->args['transient_time'] ) ) {
$this->args['transient_time'] = 60 * MINUTE_IN_SECONDS;
}
if ( empty( $this->args['footer_credit'] ) ) {
$this->args['footer_credit'] = '<span id="footer-thankyou">' . sprintf( __( 'Options panel created using %1$s', 'redux-framework' ), '<a href="' . esc_url( $this->framework_url ) . '" target="_blank">' . __( 'Redux Framework', 'redux-framework' ) . '</a> v' . self::$_version ) . '</span>';
}
if ( empty( $this->args['menu_title'] ) ) {
$this->args['menu_title'] = __( 'Options', 'redux-framework' );
}
if ( empty( $this->args['page_title'] ) ) {
$this->args['page_title'] = __( 'Options', 'redux-framework' );
}
/**
* filter 'redux/args/{opt_name}'
*
* @param array $args ReduxFramework configuration
*/
$this->args = apply_filters( "redux/args/{$this->args['opt_name']}", $this->args );
/**
* filter 'redux/options/{opt_name}/args'
*
* @param array $args ReduxFramework configuration
*/
$this->args = apply_filters( "redux/options/{$this->args['opt_name']}/args", $this->args );
if ( ! empty( $this->args['opt_name'] ) ) {
/**
* SHIM SECTION
* Old variables and ways of doing things that need correcting. ;)
**/
// Variable name change
if ( ! empty( $this->args['page_cap'] ) ) {
$this->args['page_permissions'] = $this->args['page_cap'];
unset( $this->args['page_cap'] );
}
if ( ! empty( $this->args['page_position'] ) ) {
$this->args['page_priority'] = $this->args['page_position'];
unset( $this->args['page_position'] );
}
if ( ! empty( $this->args['page_type'] ) ) {
$this->args['menu_type'] = $this->args['page_type'];
unset( $this->args['page_type'] );
}
// Get rid of extra_tabs! Not needed.
if ( is_array( $extra_tabs ) && ! empty( $extra_tabs ) ) {
foreach ( $extra_tabs as $tab ) {
array_push( $this->sections, $tab );
}
}
// Move to the first loop area!
/**
* filter 'redux-sections'
*
* @deprecated
*
* @param array $sections field option sections
*/
$this->sections = apply_filters( 'redux-sections', $sections ); // REMOVE LATER
/**
* filter 'redux-sections-{opt_name}'
*
* @deprecated
*
* @param array $sections field option sections
*/
$this->sections = apply_filters( "redux-sections-{$this->args['opt_name']}", $this->sections ); // REMOVE LATER
/**
* filter 'redux/options/{opt_name}/sections'
*
* @param array $sections field option sections
*/
$this->sections = apply_filters( "redux/options/{$this->args['opt_name']}/sections", $this->sections );
/**
* Construct hook
* action 'redux/construct'
*
* @param object $this ReduxFramework
*/
do_action( 'redux/construct', $this );
$this->filesystem = new Redux_Filesystem( $this );
//set redux upload folder
$this->set_redux_content();
// Set the default values
$this->_default_cleanup();
// Internataionalization
$this->_internationalization();
// Register extra extensions
$this->_register_extensions();
// Grab database values
$this->get_options();
// Tracking
$this->_tracking();
// Set option with defaults
//add_action( 'init', array( &$this, '_set_default_options' ), 101 );
//logconsole('post', $_GET['page']);
//DOVY!! HERE!!!
// Getting started page
// if ( is_admin () && $this->args['dev_mode'] ) {
//
// if ( isset($_GET['page']) && ($_GET['page'] == 'redux-about' || $_GET['page'] == 'redux-getting-started' || $_GET['page'] == 'redux-credits' || $_GET['page'] == 'redux-changelog' )) {
// //logconsole('inc');
// require_once( dirname( __FILE__ ) . '/inc/welcome.php' );
// } else {
// //logconsole('compare');
// if (isset($_GET['page']) && $_GET['page'] == $this->args['page_slug']) {
// $saveVer = get_option('redux_version_upgraded_from');
// $curVer = self::$_version;
//
// if (empty($saveVer)) {
// //logconsole('redir');
// wp_safe_redirect ( admin_url ( 'index.php?page=redux-getting-started' ) );
// exit;
// } else if (version_compare($curVer, $saveVer, '>')) {
// wp_safe_redirect ( admin_url ( 'index.php?page=redux-about' ) );
// exit;
// }
// }
// }
// }
// Options page
add_action( 'admin_menu', array( $this, '_options_page' ) );
// Add a network menu
if ( $this->args['database'] == "network" && $this->args['network_admin'] ) {
add_action( 'network_admin_menu', array( $this, '_options_page' ) );
}
// Admin Bar menu
add_action( 'admin_bar_menu', array(
$this,
'_admin_bar_menu'
), $this->args['admin_bar_priority'] );
// Register setting
add_action( 'admin_init', array( $this, '_register_settings' ) );
// Display admin notices in dev_mode
if ( true == $this->args['dev_mode'] ) {
require_once( self::$_dir . 'inc/debug.php' );
$this->debug = new ReduxDebugObject( $this );
if ( true == $this->args['update_notice'] ) {
add_action( 'admin_init', array( $this, '_update_check' ) );
}
}
// Display admin notices
add_action( 'admin_notices', array( $this, '_admin_notices' ) );
// Check for dismissed admin notices.
add_action( 'admin_init', array( $this, '_dismiss_admin_notice' ), 9 );
// Enqueue the admin page CSS and JS
if ( isset( $_GET['page'] ) && $_GET['page'] == $this->args['page_slug'] ) {
add_action( 'admin_enqueue_scripts', array( $this, '_enqueue' ), 1 );
}
// Output dynamic CSS
// Frontend: Maybe enqueue dynamic CSS and Google fonts
if( empty( $this->args['output_location'] ) || in_array( 'frontend', $this->args['output_location'] ) ) {
add_action( 'wp_head', array( &$this, '_output_css' ), 150 );
add_action( 'wp_enqueue_scripts', array( &$this, '_enqueue_output' ), 150 );
}
// Login page: Maybe enqueue dynamic CSS and Google fonts
if( in_array( 'login', $this->args['output_location'] ) ) {
add_action( 'login_head', array( &$this, '_output_css' ), 150 );
add_action( 'login_enqueue_scripts', array( &$this, '_enqueue_output' ), 150 );
}
// Admin area: Maybe enqueue dynamic CSS and Google fonts
if( in_array( 'admin', $this->args['output_location'] ) ) {
add_action( 'admin_head', array( &$this, '_output_css' ), 150 );
add_action( 'admin_enqueue_scripts', array( &$this, '_enqueue_output' ), 150 );
}
add_action( 'wp_print_scripts', array( $this, 'vc_fixes' ), 100 );
add_action( 'admin_enqueue_scripts', array( $this, 'vc_fixes' ), 100 );
require_once( self::$_dir . 'inc/import_export.php' );
$this->import_export = new Redux_import_export( $this );
if ( $this->args['database'] == "network" && $this->args['network_admin'] ) {
add_action( 'network_admin_edit_redux_' . $this->args['opt_name'], array(
$this,
'save_network_page'
), 10, 0 );
add_action( 'admin_bar_menu', array( $this, 'network_admin_bar' ), 999 );
}
// mod_rewrite check
//Redux_Functions::modRewriteCheck();
}
/**
* Loaded hook
* action 'redux/loaded'
*
* @param object $this ReduxFramework
*/
do_action( 'redux/loaded', $this );
} // __construct()
private function set_redux_content() {
$upload_dir = wp_upload_dir();
self::$_upload_dir = $upload_dir['basedir'] . '/redux/';
self::$_upload_url = $upload_dir['baseurl'] . '/redux/';
if ( ! is_dir( self::$_upload_dir ) ) {
$this->filesystem->execute( 'mkdir', self::$_upload_dir );
}
}
private function set_default_args() {
$this->args = array(
'opt_name' => '',
// Must be defined by theme/plugin
'google_api_key' => '',
// Must be defined to update the google fonts cache for the typography module
'google_update_weekly' => false,
// Set to keep your google fonts updated weekly
'last_tab' => '',
// force a specific tab to always show on reload
'menu_icon' => '',
// menu icon
'menu_title' => '',
// menu title/text
'page_title' => '',
// option page title
'page_slug' => '_options',
'page_permissions' => 'manage_options',
'menu_type' => 'menu',
// ('menu'|'submenu')
'page_parent' => 'themes.php',
// requires menu_type = 'submenu
'page_priority' => null,
'allow_sub_menu' => true,
// allow submenus to be added if menu_type == menu
'save_defaults' => true,
// Save defaults to the DB on it if empty
'footer_credit' => '',
'async_typography' => false,
'disable_google_fonts_link' => false,
'class' => '',
// Class that gets appended to all redux-containers
'admin_bar' => true,
'admin_bar_priority' => 999,
// Show the panel pages on the admin bar
'admin_bar_icon' => '',
// admin bar icon
'help_tabs' => array(),
'help_sidebar' => '',
'database' => '',
// possible: options, theme_mods, theme_mods_expanded, transient, network
'customizer' => false,
// setting to true forces get_theme_mod_expanded
'global_variable' => '',
// Changes global variable from $GLOBALS['YOUR_OPT_NAME'] to whatever you set here. false disables the global variable
'output' => true,
// Dynamically generate CSS
'compiler' => true,
// Initiate the compiler hook
'output_tag' => true,
// Print Output Tag
'output_location' => array( 'frontend' ),
// Where the dynamic CSS will be added. Can be any combination from: 'frontend', 'login', 'admin'
'transient_time' => '',
'default_show' => false,
// If true, it shows the default value
'default_mark' => '',
// What to print by the field's title if the value shown is default
'update_notice' => true,
// Recieve an update notice of new commits when in dev mode
'disable_save_warn' => false,
// Disable the save warn
'open_expanded' => false,
// Start the panel fully expanded to start with
'network_admin' => false,
// Enable network admin when using network database mode
'network_sites' => true,
// Enable sites as well as admin when using network database mode
'hide_reset' => false,
'hints' => array(
'icon' => 'icon-question-sign',
'icon_position' => 'right',
'icon_color' => 'lightgray',
'icon_size' => 'normal',
'tip_style' => array(
'color' => 'light',
'shadow' => true,
'rounded' => false,
'style' => '',
),
'tip_position' => array(
'my' => 'top_left',
'at' => 'bottom_right',
),
'tip_effect' => array(
'show' => array(
'effect' => 'slide',
'duration' => '500',
'event' => 'mouseover',
),
'hide' => array(
'effect' => 'fade',
'duration' => '500',
'event' => 'click mouseleave',
),
),
),
'show_import_export' => true,
'dev_mode' => false,
'system_info' => false,
);
}
// Fix conflicts with Visual Composer.
public function vc_fixes() {
if ( redux_helpers::isFieldInUse( $this, 'ace_editor' ) ) {
wp_dequeue_script( 'wpb_ace' );
wp_deregister_script( 'wpb_ace' );
}
}
public function network_admin_bar( $wp_admin_bar ) {
$args = array(
'id' => $this->args['opt_name'] . '_network_admin',
'title' => $this->args['menu_title'],
'parent' => 'network-admin',
'href' => network_admin_url( 'settings.php' ) . '?page=' . $this->args['page_slug'],
'meta' => array( 'class' => 'redux-network-admin' )
);
$wp_admin_bar->add_node( $args );
}
private function stripslashes_deep( $value ) {
$value = is_array( $value ) ?
array_map( 'stripslashes_deep', $value ) :
stripslashes( $value );
return $value;
}
public function save_network_page() {
$data = $this->_validate_options( $_POST[ $this->args['opt_name'] ] );
if ( ! empty( $data ) ) {
$this->set_options( $data );
}
wp_redirect( add_query_arg( array(
'page' => $this->args['page_slug'],
'updated' => 'true'
), network_admin_url( 'settings.php' ) ) );
exit();
}
public function _update_check() {
// Only one notice per instance please
if ( ! isset( $GLOBALS['redux_update_check'] ) ) {
Redux_Functions::updateCheck( self::$_version );
$GLOBALS['redux_update_check'] = 1;
}
}
public function _admin_notices() {
Redux_Functions::adminNotices();
}
public function _dismiss_admin_notice() {
Redux_Functions::dismissAdminNotice();
}
/**
* Load the plugin text domain for translation.
*
* @since 3.0.5
*/
private function _internationalization() {
/**
* Locale for text domain
* filter 'redux/textdomain/{opt_name}'
*
* @param string The locale of the blog or from the 'locale' hook
* @param string 'redux-framework' text domain
*/
$locale = apply_filters( "redux/textdomain/{$this->args['opt_name']}", get_locale(), 'redux-framework' );
if ( strpos( $locale, '_' ) === false ) {
if ( file_exists( self::$_dir . 'languages/' . strtolower( $locale ) . '_' . strtoupper( $locale ) . '.mo' ) ) {
$locale = strtolower( $locale ) . '_' . strtoupper( $locale );
}
}
load_textdomain( 'redux-framework', self::$_dir . 'languages/' . $locale . '.mo' );
} // _internationalization()
/**
* @return ReduxFramework
*/
public function get_instance() {
//self::$_instance = $this;
return self::$instance;
} // get_instance()
private function _tracking() {
require_once( dirname( __FILE__ ) . '/inc/tracking.php' );
$tracking = Redux_Tracking::get_instance();
$tracking->load( $this );
} // _tracking()
/**
* ->_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 ( empty( $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_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 );
} // get()
/**
* ->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()
/**
* Set a global variable by the global_variable argument
*
* @since 3.1.5
* @return bool (global was set)
*/
private function set_global_variable() {
if ( $this->args['global_variable'] ) {
$option_global = $this->args['global_variable'];
/**
* filter 'redux/options/{opt_name}/global_variable'
*
* @param array $value option value to set global_variable with
*/
$GLOBALS[ $this->args['global_variable'] ] = apply_filters( "redux/options/{$this->args['opt_name']}/global_variable", $this->options );
if ( isset( $this->transients['last_save'] ) ) {
// Deprecated
$GLOBALS[ $this->args['global_variable'] ]['REDUX_last_saved'] = $this->transients['last_save'];
// Last save key
$GLOBALS[ $this->args['global_variable'] ]['REDUX_LAST_SAVE'] = $this->transients['last_save'];
}
if ( isset( $this->transients['last_compiler'] ) ) {
// Deprecated
$GLOBALS[ $this->args['global_variable'] ]['REDUX_COMPILER'] = $this->transients['last_compiler'];
// Last compiler hook key
$GLOBALS[ $this->args['global_variable'] ]['REDUX_LAST_COMPILER'] = $this->transients['last_compiler'];
}
return true;
}
return false;
} // set_global_variable()
/**
* ->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
*/
public function set_options( $value = '' ) {
$this->transients['last_save'] = time();
if ( ! empty( $value ) ) {
$this->options = $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 if ( $this->args['database'] === 'network' ) {
// Strip those slashes!
$value = json_decode( stripslashes( json_encode( $value ) ), true );
update_site_option( $this->args['opt_name'], $value );
} else {
update_option( $this->args['opt_name'], $value );
}
// Store the changed values in the transient
if ( $value != $this->options ) {
foreach ( $value as $k => $v ) {
if ( ! isset( $this->options[ $k ] ) ) {
$this->options[ $k ] = "";
} else if ( $v == $this->options[ $k ] ) {
unset( $this->options[ $k ] );
}
}
$this->transients['changed_values'] = $this->options;
}
$this->options = $value;
// Set a global variable by the global_variable argument.
$this->set_global_variable();
// Saving the transient values
$this->set_transients();
//do_action( "redux-saved-{$this->args['opt_name']}", $value ); // REMOVE
//do_action( "redux/options/{$this->args['opt_name']}/saved", $value, $this->transients['changed_values'] );
}
} // set_options()
/**
* ->get_options(); This is used to get options from the database
*
* @since ReduxFramework 3.0.0
*/
public 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 if ( $this->args['database'] === 'network' ) {
$result = get_site_option( $this->args['opt_name'], array() );
$result = json_decode( stripslashes( json_encode( $result ) ), true );
} else {
$result = get_option( $this->args['opt_name'], array() );
}
if ( empty( $result ) && ! empty( $defaults ) ) {
$results = $defaults;
$this->set_options( $results );
} else {
$this->options = $result;
}
/**
* action 'redux/options/{opt_name}/options'
*
* @param mixed $value option values
*/
$this->options = apply_filters( "redux/options/{$this->args['opt_name']}/options", $this->options );
// Get transient values
$this->get_transients();
// Set a global variable by the global_variable argument.
$this->set_global_variable();
} // get_options()
/**
* ->get_wordpress_date() - Get Wordpress specific data from the DB and return in a usable array
*
* @since ReduxFramework 3.0.0
*/
public function get_wordpress_data( $type = false, $args = array() ) {
$data = "";
/**
* filter 'redux/options/{opt_name}/wordpress_data/{type}/'
*
* @deprecated
*
* @param string $data
*/
$data = apply_filters( "redux/options/{$this->args['opt_name']}/wordpress_data/$type/", $data ); // REMOVE LATER
/**
* filter 'redux/options/{opt_name}/data/{type}'
*
* @param string $data
*/
$data = apply_filters( "redux/options/{$this->args['opt_name']}/data/$type", $data );
$argsKey = "";
foreach ( $args as $key => $value ) {
if ( ! is_array( $value ) ) {
$argsKey .= $value . "-";
} else {
$argsKey .= implode( "-", $value );
}
}
if ( empty( $data ) && isset( $this->wp_data[ $type . $argsKey ] ) ) {
$data = $this->wp_data[ $type . $argsKey ];
}
if ( empty( $data ) && ! empty( $type ) ) {
/**
* 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" ) {
if ( ! isset( $args['posts_per_page'] ) ) {
$args['posts_per_page'] = 20;
}
$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'] );
$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 == "taxonomy" || $type == "taxonomies" ) {
$taxonomies = get_taxonomies( $args );
if ( ! empty( $taxonomies ) ) {
foreach ( $taxonomies as $key => $taxonomy ) {
$data[ $key ] = $taxonomy;
}
//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" ) {
global $wp_post_types;
$defaults = array(
'public' => true,
'exclude_from_search' => false,
);
$args = wp_parse_args( $args, $defaults );
$output = 'names';
$operator = 'and';
$post_types = get_post_types( $args, $output, $operator );
ksort( $post_types );
foreach ( $post_types as $name => $title ) {
if ( isset( $wp_post_types[ $name ]->labels->menu_name ) ) {
$data[ $name ] = $wp_post_types[ $name ]->labels->menu_name;
} else {
$data[ $name ] = ucfirst( $name );
}
}
} else if ( $type == "tags" || $type == "tag" ) { // NOT WORKING!
$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;
}
} else if ( $type == "image_size" || $type == "image_sizes" ) {
global $_wp_additional_image_sizes;
foreach ( $_wp_additional_image_sizes as $size_name => $size_attrs ) {
$data[ $size_name ] = $size_name . ' - ' . $size_attrs['width'] . ' x ' . $size_attrs['height'];
}
} else if ( $type == "elusive-icons" || $type == "elusive-icon" || $type == "elusive" ||
$type == "font-icon" || $type == "font-icons" || $type == "icons"
) {
/**
* filter 'redux-font-icons'
*
* @deprecated
*
* @param array $font_icons array of elusive icon classes
*/