-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsettings.php
98 lines (96 loc) · 3.09 KB
/
settings.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
<?php
/*
* Build settings page and handle options
*/
if(!class_exists('SSC_Locations_Settings')) {
class SSC_Locations_Settings {
public function __construct() {
add_action( 'admin_menu', array( &$this, 'add_menu' ) );
add_action( 'admin_init', array( &$this, 'admin_init' ) );
}
public function admin_init(){
global $ssc_location_options;
$options = $ssc_location_options;
foreach ( $options['settings'] as $settings_group ) {
$group_name = $settings_group['group_name'];
$group_title = $settings_group['group_title'];
$group_section = $settings_group['group_section'];
$section_name = 'ssc_admin_' . $group_name . '_settings_section_' . $group_section;
add_settings_section(
$section_name,
$group_title,
array( &$this, 'ssc_admin_settings_section_callback' ),
$group_section
);
foreach ( $settings_group['group_fields'] as $fields ) {
$args = array();
$args = $fields;
$args['group_name'] = $group_name;
$args['group_section'] = $group_section;
$field_name = 'ssc_admin_' . $group_name . '_settings_' . $fields['name'];
add_settings_field(
$field_name,
$fields['title'],
array( &$this, 'ssc_admin_settings_fields_callback' ),
$group_section,
$section_name,
$args
);
$tabs[] = $group_section;
register_setting( $group_section, $field_name );
}
}
}
public function ssc_admin_settings_fields_callback( array $args ) {
$field_name = 'ssc_admin_' . $args['group_name'] . '_settings_' .$args['name'];
if ( 'text' == $args['type'] || 'time' == $args['type'] ){
echo '<input type="text" name="' . $field_name . '" ';
if ( get_option( $field_name ) ) {
echo 'value="' . get_option( $field_name ) . '" ';
}
echo 'class="' . $field_name;
if ( 'time' == $args['type'] ) {
echo ' time ';
}
echo '"/>';
}
if ( 'select' == $args['type'] ) {
$options = array();
echo '<select name="' . $field_name . '" class="' . $field_name . '">';
if ( 'us_state_abbrevs_names' == $args['options'] ) {
$options = ssc_us_states();
}
elseif ( is_array( $args['options'] ) ) {
$options = $args['options'];
}
foreach ( $options as $key => $value ) {
echo '<option value="' .$key . '" ';
if ( get_option( $field_name ) == $key ) {
echo 'selected';
}
echo '>' . $value . '</option>';
}
echo '</select>';
}
}
public function ssc_admin_settings_section_callback( $section_passed ) {
echo '<p>' . $section_passed['title'] . '</p>';
}
public function add_menu(){
add_menu_page(
'Location Settings',
'Location Information',
'administrator',
'ssc_location_settings',
array( &$this, 'ssc_location_settings_page')
);
}
public function ssc_location_settings_page() {
if(!current_user_can( 'manage_options' ) ) {
wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
}
include( sprintf( "%s/templates/settings.php", dirname(__FILE__) ) );
}
}
}
?>