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
<?php
class WooCommerce_Quick_Donation_Settings {
private $page_hook = '';
public $settings;
private $settings_page;
private $settings_section;
private $settings_fields;
private $create_function;
private $settings_key;
private $settings_values;
function __construct($page_hook = '') {
$this->settings_section = array();
$this->settings_fields = array();
$this->create_function = array();
$this->add_settings_pages();
$this->get_settings();
$this->add_settings_section();
$this->create_callback_function();
$this->add_settings_fields();
$this->page_hook = $page_hook;
$this->settings = new WC_Quick_Donation_Settings();
if(empty($page_hook)) {
add_action( 'admin_menu', array( $this, 'admin_menu' ) );
}
add_action( 'admin_init', array( $this, 'admin_init' ) );
}
function admin_menu() {
$this->page_hook = add_submenu_page('edit.php?post_type=wcqd_project','Settings Page','Settings Page','administrator','WC_QD_settings', array( $this, 'admin_page' ) );
$this->page_hook = 'wc_qd';
}
private function add_settings_pages(){
global $pages;
$pages = array();
include(WC_QD_ADMIN.'settings/pages.php');
$this->settings_page = $pages;
}
private function add_settings_section(){
global $section;
$section = array();
include(WC_QD_ADMIN.'settings/section.php');
$this->settings_section = $section;
}
private function create_callback_function(){
$sec = $this->settings_section;
foreach($sec as $sk => $s){
if(is_array($s)){
$c = count($s);
$a = 0;
while($a < $c){
if(isset($s[$a]['validate_callback'])){
$this->create_function[] = $s[$a]['id'];
$s[$a]['validate_callback'] = '';
$file = addslashes(WC_QD_ADMIN.'settings/validate-'.$s[$a]['id'].'.php');
$s[$a]['validate_callback'] = create_function('$fields', 'global $send_fields; $send_fields = $fields; require("'.$file.'"); return $fields;');
}
$a++;
}
}
$this->settings_section[$sk] = $s;
}
}
private function add_settings_fields(){
global $fields;
$fields = array();
include(WC_QD_ADMIN.'settings/fields.php');
$this->settings_field = $fields;
}
function admin_init(){
$this->settings->add_pages($this->settings_page);
$sections = $this->settings_section;
foreach ($sections as $page_id => $section_value){
$pages = $this->settings->add_sections($page_id,$section_value);
}
$fields = $this->settings_field;
foreach($fields as $page_id => $section_fields){
foreach($section_fields as $section_id => $sfields){
if(is_array($sfields)){
foreach($sfields as $f){
$pages = $this->settings->add_field($page_id,$section_id,$f);
}
} else {
$pages = $this->settings->add_field($page_id,$section_id,$sfields);
}
}
}
$this->settings->init( $pages, $this->page_hook );
}
public function admin_page(){
echo '<div class="wrap wc_qd_settings">';
settings_errors();
$this->settings->render_header();
echo $this->settings->debug;
$this->settings->render_form();
echo '</div>';
}
//function validate_section( $fields ) {
// global $send_fields;
// $send_fields = $fields;
// include(WC_QD_ADMIN.'settings/validate.php');
// return $fields;
//}
function get_option($id = ''){
if( ! empty($this->settings_values) && ! empty($id)){
if(isset($this->settings_values[$id])){
return $this->settings_values[$id];
}
}
return false;
}
function get_settings($key = ''){
$values = array();
foreach($this->settings_page as $settings){
$this->settings_key[] = WC_QD_DB.$settings['slug'];
$db_val = get_option(WC_QD_DB.$settings['slug']);
if(is_array($db_val)){
unset($db_val['section_id']);
$values = array_merge($db_val,$values);
}
}
$this->settings_values = $values;
return $values;
}
}
?>