-
Notifications
You must be signed in to change notification settings - Fork 1
/
settings.php
178 lines (141 loc) · 5.25 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
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
<?php
/**
* RE Pro Settings
*
* @package re-pro
*/
/**
* REProSettings.
*/
class REProSettings {
/**
* General settings.
*
* @var [Array]
*/
private $general_settings;
/**
* Settings constructor.
*/
public function __construct() {
if ( is_admin() ) {
$this->general_settings = get_option( 'repro_settings' );
add_action( 'admin_menu', array( $this, 'add_admin_menu' ) );
add_action( 'admin_init', array( $this, 'settings_init' ) );
}
}
/**
* Add admin menu.
*/
public function add_admin_menu() {
add_options_page( __( 'Real Estate Pro' ), __( 'Real Estate Pro' ), 'manage_options', 're-pro-settings', array( $this, 'render_settings' ) );
}
/**
* Initialize settings fields and sections.
*/
public function settings_init() {
register_setting( 'repro_settings', 'repro_settings' );
// General Settings.
add_settings_section(
'repro_settings',
__( 'General Settings', 're-pro' ),
array( $this, 'general_callback' ),
'repro_general_settings'
);
add_settings_field(
'google_maps',
__( 'Google Maps Module', 're-pro' ),
array( $this, 'google_maps' ),
'repro_general_settings',
'repro_settings'
);
add_settings_field(
'greatschools_apikey',
__( 'Great Schools API Key', 're-pro' ),
array( $this, 'greatschools_module' ),
'repro_general_settings',
'repro_settings'
);
add_settings_field(
'zillow_apikey',
__( 'Zillow API Key', 're-pro' ),
array( $this, 'zillow_module' ),
'repro_general_settings',
'repro_settings'
);
add_settings_field(
'sa_apikey',
__( 'Street Advisor API Key', 're-pro' ),
array( $this, 'street_advisor' ),
'repro_general_settings',
'repro_settings'
);
}
/**
* Feed section callback.
*/
public function general_callback() {
echo esc_attr( 'Activate the modules you would like to use.', 're-pro' );
}
/**
* Render Christies field.
*/
public function google_maps() {
$gmaps_active = isset( $this->general_settings['gmaps_active'] ) ? $this->general_settings['gmaps_active'] : '0';
$gmaps_key = isset( $this->general_settings['gmaps_key'] ) ? $this->general_settings['gmaps_key'] : '';
$gmaps_style = isset( $this->general_settings['gmaps_style'] ) ? $this->general_settings['gmaps_style'] : '';
$gmaps_zoom = isset( $this->general_settings['gmaps_zoom'] ) ? $this->general_settings['gmaps_zoom'] : '';
$checked = checked( '1', $gmaps_active, false );
$is_active = ( '1' === $gmaps_active ) ? 'Deactivate Google maps module?' : 'Activate Google maps module?';
$disable_zoom = checked( '1', $gmaps_zoom, false );
echo '<input style="vertical-align: top;" type="checkbox" name="repro_settings[gmaps_active]"' . esc_attr( $checked ) . ' value="1"> ';
echo '<div style="display: inline-block;">';
esc_attr_e( $is_active );
echo '</div><br><br>';
echo '<input class="widefat" type="password" name="repro_settings[gmaps_key]" placeholder="Google maps API key" value="' . $gmaps_key . '">';
echo '<span class="description"> Enter your google maps javascript api key</span><br><br>';
echo '<textarea style="width:500px;" rows="10" cols="50" name="repro_settings[gmaps_style]">';
esc_attr_e( $gmaps_style );
echo '</textarea>';
echo '<br /><span class="description">Insert valid json to add custom style to maps. Json styles can be generated using <a target="_blank" href="https://snazzymaps.com/">Snazzy Maps</a> or the <a target="_blank" href="https://mapstyle.withgoogle.com/">Google Maps Styling Wizard</a></span><br><br>';
echo '<input style="vertical-align: top;" type="checkbox" name="repro_settings[gmaps_zoom]"' . esc_attr( $disable_zoom ) . ' value="1"> ';
echo '<div style="display: inline-block;">';
echo 'Disable scroll zoom in Google Maps';
echo '</div>';
}
public function zillow_module() {
$zillow_apikey = isset( $this->general_settings['zillow_apikey'] ) ? $this->general_settings['zillow_apikey'] : '';
echo '<input class="widefat" type="text" name="repro_settings[zillow_apikey]" placeholder="Zillow API Key" value="' . $zillow_apikey . '">';
}
public function street_advisor() {
$sa_apikey = isset( $this->general_settings['sa_apikey'] ) ? $this->general_settings['sa_apikey'] : '';
echo '<input class="widefat" type="text" name="repro_settings[sa_apikey]" placeholder="Street Advisor API Key" value="' . $sa_apikey . '">';
}
/**
* greatschools_module function.
*
* @access public
* @return void
*/
public function greatschools_module() {
$greatschools_apikey = isset( $this->general_settings['greatschools_apikey'] ) ? $this->general_settings['greatschools_apikey'] : '';
echo '<input class="widefat" type="text" name="repro_settings[greatschools_apikey]" placeholder="Great Schools API Key" value="' . $greatschools_apikey . '">';
}
/**
* Render full settings page.
*/
public function render_settings() {
if ( ! current_user_can( 'manage_options' ) ) {
wp_die( esc_attr( "You don't have access to this page", 're-pro' ) );
}
echo '<div class="wrap">';
echo '<form method="post" action="options.php">';
echo '<h1>' . esc_attr( 'Real Estate Pro', 're-pro' ) . '</h1>';
settings_fields( 'repro_settings' );
do_settings_sections( 'repro_general_settings' );
submit_button();
echo '</form>';
echo '</div>';
}
}
new REProSettings();