This repository was archived by the owner on Sep 15, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadminoptions.php
More file actions
343 lines (280 loc) · 12.7 KB
/
Copy pathadminoptions.php
File metadata and controls
343 lines (280 loc) · 12.7 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
<?php
/**** Registering the admin options page with Wordpress *****/
add_action('admin_menu', 'wviewforwp_admin_add_page');
function wviewforwp_admin_add_page() {
add_options_page('Wview for WP Plugin Options', 'Wview for WP', 'manage_options', 'wviewforwp', 'wviewforwp_options_page');
}
/*********** **********/
// Function to Display the options page
function wviewforwp_options_page() {
?>
<div>
<h2>Wview for WP Options Page</h2>
<form action="options.php" method="post">
<?php settings_fields('wviewforwp'); //The Settings Page Name?>
<?php do_settings_sections('wviewforwp'); ?>
<input name="Submit" type="submit" value="<?php esc_attr_e('Save Changes'); ?>" />
</form></div>
<?php }
// add the admin Settings and such
add_action('admin_init', 'wviewforwp_admin_init');
// Function to create the options in Wordpress database, create a section for them, and create the individual settings.
function wviewforwp_admin_init(){
register_setting( 'wviewforwp', //the settings page name
'wviewforwp_options', //the option name
'wviewforwp_options_validate' //the validating function
);
add_settings_section( 'wviewforwp_main', //the unique id of the field
'Main', //The Title of the Section
'wviewforwp_main_section_text', //The function for Display
'wviewforwp' //the settings page name
);
add_settings_field( 'wviewforwp_param_file', //the unique id of the setting
'WView Parameter CSV File Name<br/>
(Must be updating into your root wordpress website folder)',
//the Title of the Setting
'wviewforwp_param_input', //The Function for display
'wviewforwp', //The Settings Page Name
'wviewforwp_main' //The Section to put it in.
);
add_settings_field( 'wviewforwp_servertime_file', //the unique id of the setting
'Web Server Timezone <br/>
(Valid Timezones only <a
href="http://php.net/manual/en/timezones.php">list here</a>)',
//the Title of the Setting
'wviewforwp_webtime_input', //The Function for display
'wviewforwp', //The Settings Page Name
'wviewforwp_main' //The Section to put it in.
);
add_settings_field( 'wviewforwp_wviewtime_file', //the unique id of the setting
'Timezone at Weather Station<br/>
(Valid Timezones only <a
href="http://php.net/manual/en/timezones.php">list here</a>)',
//the Title of the Setting
'wviewforwp_wviewtime_input', //The Function for display
'wviewforwp', //The Settings Page Name
'wviewforwp_main' //The Section to put it in.
);
add_settings_field( 'wviewforwp_wviewunits', //the unique id of the setting
'Weather Units', //the Title of the Setting
'wviewforwp_wviewunits_input', //The Function for display
'wviewforwp', //The Settings Page Name
'wviewforwp_main' //The Section to put it in.
);
add_settings_field( 'wviewforwp_wviewsensors_file', //the unique id of the setting
'Wview Sensors Mode', //the Title of the Setting
'wviewforwp_wviewsensors_input', //The Function for display
'wviewforwp', //The Settings Page Name
'wviewforwp_main' //The Section to put it in.
);
add_settings_field( 'wviewforwp_data_delay', //the unique id of the setting
'Time Before Data Delay Warning', //the Title of the Setting
'wviewforwp_data_delay_input', //The Function for display
'wviewforwp', //The Settings Page Name
'wviewforwp_main' //The Section to put it in.
);
add_settings_section( 'wviewforwp_db_graphing', //the unique id of the field
'Database and Graphing (optional)', //The Title of the Section
'wviewforwp_db_graph_section_text', //The function for Display
'wviewforwp' //the settings page name
);
add_settings_field( 'wviewforwp_wviewdb_on', //the unique id of the setting
'Include Wview mySQL Database',
//the Title of the Setting
'wviewforwp_wviewdb_on_input', //The Function for display
'wviewforwp', //The Settings Page Name
'wviewforwp_db_graphing' //The Section to put it in.
);
/* THIS SETTING REMOVED TO COMPLY WITH GPL WILL BE REPLACING JPGRAPH WITH A DIFFERENT GRAPHING METHOD
add_settings_field( 'wviewforwp_jpgraph_images', //the unique id of the setting
'Graph Image Folder
<br/>(include trailing slash)',
//the Title of the Setting
'wviewforwp_jpgraph_images_input', //The Function for display
'wviewforwp', //The Settings Page Name
'wviewforwp_db_graphing' //The Section to put it in.
);
*/
add_settings_field( 'wviewforwp_mysql_dbname', //the unique id of the setting
'Database Name',
//the Title of the Setting
'wviewforwp_mysql_dbname_input', //The Function for display
'wviewforwp', //The Settings Page Name
'wviewforwp_db_graphing' //The Section to put it in.
);
add_settings_field( 'wviewforwp_mysql_dbuser', //the unique id of the setting
'Database UserName',
//the Title of the Setting
'wviewforwp_mysql_dbuser_input', //The Function for display
'wviewforwp', //The Settings Page Name
'wviewforwp_db_graphing' //The Section to put it in.
);
add_settings_field( 'wviewforwp_mysql_dbpass', //the unique id of the setting
'Database Password',
//the Title of the Setting
'wviewforwp_mysql_dbpass_input', //The Function for display
'wviewforwp', //The Settings Page Name
'wviewforwp_db_graphing' //The Section to put it in.
);
add_settings_field( 'wviewforwp_mysql_table', //the unique id of the setting
'Database Table Name',
//the Title of the Setting
'wviewforwp_mysql_table_input', //The Function for display
'wviewforwp', //The Settings Page Name
'wviewforwp_db_graphing' //The Section to put it in.
);
add_settings_field( 'wviewforwp_mysql_host', //the unique id of the setting
'Database Host Name',
//the Title of the Setting
'wviewforwp_mysql_host_input', //The Function for display
'wviewforwp', //The Settings Page Name
'wviewforwp_db_graphing' //The Section to put it in.
);
}
function wviewforwp_main_section_text() {
echo '<h4>Initial setup for Wview for WP.</h4>';
}
function wviewforwp_db_graph_section_text() {
echo '<h4>Access to More Data and Graphs - Requires Wview mySQL setup</h4>';
}
function wviewforwp_param_input() {
$options = get_option('wviewforwp_options');
$value = $options['paramFile']; //Name of the parameter we want to get and update
?>
<input id='paramFile' name='wviewforwp_options[paramFile]'
type='text' size='40' value='<?php echo esc_attr( $value ); ?>' />
<?php
}
function wviewforwp_webtime_input() {
$options = get_option('wviewforwp_options');
$value = $options['webTime']; //Name of the parameter we want to get and update
?>
<input id='webTime' name='wviewforwp_options[webTime]'
type='text' size='40' value='<?php echo esc_attr( $value ); ?>' />
<?php
}
function wviewforwp_wviewtime_input() {
$options = get_option('wviewforwp_options');
$value = $options['wviewTime']; //Name of the parameter we want to get and update
?>
<input id='wviewTime' name='wviewforwp_options[wviewTime]'
type='text' size='40' value='<?php echo esc_attr( $value ); ?>' />
<?php
}
function wviewforwp_wviewunits_input() {
$options = get_option('wviewforwp_options');
$value = $options['currentSys']; //Name of the parameter we want to get and update
//if ($value==0) {
?>
<select id='currentSysselect' name='wviewforwp_options[currentSys]'>
<option id='currentSys' name='wviewforwp_options[currentSys]' value='1'<?php selected( '1', $value ); ?>>Canadian Metric</option>';
<option id='currentSys' name='wviewforwp_options[currentSys]' value='2' <?php selected( '2', $value ); ?>>US</option>';
<option id='currentSys' name='wviewforwp_options[currentSys]' value='3' <?php selected( '3', $value ); ?>>UK</option>';
<option id='currentSys' name='wviewforwp_options[currentSys]' value='4' <?php selected( '4', $value ); ?>>Marine</option>';
<option id='currentSys' name='wviewforwp_options[currentSys]' value='5' <?php selected( '5', $value ); ?>>EU</option>';
<option id='currentSys' name='wviewforwp_options[currentSys]' value='6' <?php selected( '6', $value ); ?>>Scientific</option>';
</select>
<?php
}
function wviewforwp_wviewsensors_input() {
$options = get_option('wviewforwp_options');
$value = $options['wviewsensors']; //Name of the parameter we want to get and update
?>
<select id='wviewsensorsselect' name='wviewforwp_options[wviewsensors]'>
<option id='wviewsensors' name='wviewforwp_options[wviewsensors]' value='0' <?php selected( '0', $value ); ?>>Standard</option>';
<option id='wviewsensors' name='wviewforwp_options[wviewsensors]' value='1' <?php selected( '1', $value ); ?>>Extended</option>';
</select>
<?php
}
function wviewforwp_data_delay_input() {
$options = get_option('wviewforwp_options');
$value = $options['timedelay']; //Name of the parameter we want to get and update
if ($value==5) {
?>
<select id='timedelayselect' name='wviewforwp_options[timedelay]'>
<option id='timedelay' name='wviewforwp_options[timedelay]' value='5' selected='selected'>5 Minute</option>';
<option id='timedelay' name='wviewforwp_options[timedelay]' value='10' >10 Minutes</option>';
</select>
<?php
}
else {
?>
<select id='timedelayselect' name='wviewforwp_options[timedelay]'>
<option id='timedelay' name='wviewforwp_options[timedelay]' value='5' selected='selected'>5 Minute</option>';
<option id='timedelay' name='wviewforwp_options[timedelay]' value='10' >10 Minutes</option>';
</select>
<?php
}
}
function wviewforwp_wviewdb_on_input() {
$options = get_option('wviewforwp_options');
$value = $options['wviewdbtoggle']; //Name of the parameter we want to get and update
//For CHECKBOXES -- > The id must be the name of the option. The name must be the options array and the value is the numeric hard-coded value. The php at the end checks that there is a 1 in $value and if so makes the box checked.
?>
<input id="wviewdbtoggle" name="wviewforwp_options[wviewdbtoggle]" type="checkbox" value="1" <?php checked( '1', $value ); ?>>
<?php
}
function wviewforwp_mysql_dbname_input() {
$options = get_option('wviewforwp_options');
$value = $options['mysqldbname']; //Name of the parameter we want to get and update
?>
<input id='mysqldbname' name='wviewforwp_options[mysqldbname]'
type='text' size='40' value='<?php echo esc_attr( $value ); ?>' />
<?php
}
function wviewforwp_mysql_table_input() {
$options = get_option('wviewforwp_options');
$value = $options['mysqltable']; //Name of the parameter we want to get and update
?>
<input id='mysqltable' name='wviewforwp_options[mysqltable]'
type='text' size='40' value='<?php echo esc_attr( $value ); ?>' />
<?php
}
function wviewforwp_mysql_dbuser_input() {
$options = get_option('wviewforwp_options');
$value = $options['mysqluser']; //Name of the parameter we want to get and update
?>
<input id='mysqluser' name='wviewforwp_options[mysqluser]'
type='text' size='40' value='<?php echo esc_attr( $value ); ?>' />
<?php
}
function wviewforwp_mysql_dbpass_input() {
$options = get_option('wviewforwp_options');
$value = $options['mysqlpass']; //Name of the parameter we want to get and update
?>
<input id='mysqlpass' name='wviewforwp_options[mysqlpass]'
type='password' size='40' value='<?php echo esc_attr( $value ); ?>' />
<?php
}
function wviewforwp_mysql_host_input() {
$options = get_option('wviewforwp_options');
$value = $options['mysqlhost']; //Name of the parameter we want to get and update
?>
<input id='mysqlhost' name='wviewforwp_options[mysqlhost]'
type='text' size='40' value='<?php echo esc_attr( $value ); ?>' />
<?php
}
/*SEE NOTE ABOVE in SETTINGS ON REMOVAL OF JPGRAPH
function wviewforwp_jpgraph_images_input() {
$options = get_option('wviewforwp_options');
$value = $options['jpgraphimages']; //Name of the parameter we want to get and update
?>
<input id='jpgraphimages' name='wviewforwp_options[jpgraphimages]'
type='text' size='40' value='<?php echo esc_attr( $value ); ?>' />
<?php
}*/
function wviewforwp_options_validate($input) {
/* $valid = array();
$valid['paramFile'] = sanitize_email( $input['paramFile'] );
// Something dirty entered? Warn user.
if( $valid['paramFile'] != $input['paramFile'] ) {
add_settings_error(
'ozhwpe_boss_email', // setting title
'ozhwpe_texterror', // error ID
'Invalid email, please fix', // error message
'error' // type of message
);
}*/
return $input;
}
?>