x Sorry, these patches are not available anymore due to data migration. Please run a fresh inspection.
Test Failed
Push — master ( 785694...def0c6 )
by Brandon
03:14
created

REProSettings::greatschools_module()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 0
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 11 and the first side effect is on line 181.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
/**
3
 * RE Pro Settings
4
 *
5
 * @package re-pro
6
 */
7
8
/**
9
 * REProSettings.
10
 */
11
class REProSettings {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
12
13
	/**
14
	 * General settings.
15
	 *
16
	 * @var [Array]
17
	 */
18
	private $general_settings;
19
20
	/**
21
	 * Settings constructor.
22
	 */
23
	public function __construct() {
24
		if ( is_admin() ) {
25
			$this->general_settings = get_option('repro_settings');
26
27
			add_action( 'admin_menu', array( $this, 'add_admin_menu' ) );
28
			add_action( 'admin_init', array( $this, 'settings_init' ) );
29
		}
30
	}
31
32
	/**
33
	 * Add admin menu.
34
	 */
35
	public function add_admin_menu() {
36
		add_options_page( __( 'Real Estate Pro' ), __( 'Real Estate Pro' ), 'manage_options', 're-pro-settings', array( $this, 'render_settings' ) );
37
	}
38
39
	/**
40
	 * Initialize settings fields and sections.
41
	 */
42
	public function settings_init() {
43
		register_setting( 'repro_settings', 'repro_settings' );
44
45
		// General Settings.
46
		add_settings_section(
47
			'repro_settings',
48
			__( 'General Settings', 're-pro' ),
49
			array( $this, 'general_callback' ),
50
			'repro_general_settings'
51
		);
52
53
		add_settings_field(
54
			'google_maps',
55
			__( 'Google Maps Module', 're-pro' ),
56
			array( $this, 'google_maps' ),
57
			'repro_general_settings',
58
			'repro_settings'
59
		);
60
61
62
		add_settings_field(
63
			'greatschools_apikey',
64
			__( 'Great Schools API Key', 're-pro' ),
65
			array( $this, 'greatschools_module' ),
66
			'repro_general_settings',
67
			'repro_settings'
68
		);
69
70
71
		add_settings_field(
72
			'zillow_apikey',
73
			__( 'Zillow API Key', 're-pro' ),
74
			array( $this, 'zillow_module' ),
75
			'repro_general_settings',
76
			'repro_settings'
77
		);
78
79
80
		add_settings_field(
81
			'sa_apikey',
82
			__( 'Street Advisor API Key', 're-pro' ),
83
			array( $this, 'street_advisor' ),
84
			'repro_general_settings',
85
			'repro_settings'
86
		);
87
88
	}
89
90
	/**
91
	 * Feed section callback.
92
	 */
93
	public function general_callback() {
94
		echo esc_attr( 'Activate the modules you would like to use.', 're-pro' );
95
	}
96
97
	/**
98
	 * Render Christies field.
99
	 */
100
	public function google_maps() {
101
		$gmaps_active = isset( $this->general_settings['gmaps_active'] ) ? $this->general_settings['gmaps_active'] : '0';
102
		$gmaps_key = isset( $this->general_settings['gmaps_key'] ) ? $this->general_settings['gmaps_key'] : '';
103
		$gmaps_style = isset( $this->general_settings['gmaps_style'] ) ? $this->general_settings['gmaps_style'] : '';
104
		$gmaps_zoom = isset( $this->general_settings['gmaps_zoom'] ) ? $this->general_settings['gmaps_zoom'] : '';
105
106
		$checked = checked( '1', $gmaps_active, false );
107
		$is_active = ( '1' === $gmaps_active ) ? 'Deactivate Google maps module?' : 'Activate Google maps module?';
108
		$disable_zoom = checked( '1', $gmaps_zoom, false );
109
110
		echo '<input style="vertical-align: top;" type="checkbox" name="repro_settings[gmaps_active]"' . esc_attr( $checked ) . ' value="1"> ';
111
		echo '<div style="display: inline-block;">';
112
		esc_attr_e( $is_active );
113
		echo '</div><br><br>';
114
115
		echo '<input class="widefat" type="password" name="repro_settings[gmaps_key]" placeholder="Google maps API key" value="' . $gmaps_key . '">';
116
		echo '<span class="description"> Enter your google maps javascript api key</span><br><br>';
117
118
		echo '<textarea style="width:500px;" rows="10" cols="50" name="repro_settings[gmaps_style]">';
119
		esc_attr_e( $gmaps_style );
120
		echo '</textarea>';
121
		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&nbsp;Maps</a> or the <a target="_blank" href="https://mapstyle.withgoogle.com/">Google&nbsp;Maps&nbsp;Styling&nbsp;Wizard</a></span><br><br>';
122
123
		echo '<input style="vertical-align: top;" type="checkbox" name="repro_settings[gmaps_zoom]"' . esc_attr( $disable_zoom ) . ' value="1"> ';
124
		echo '<div style="display: inline-block;">';
125
		echo 'Disable scroll zoom in Google Maps';
126
		echo '</div>';
127
	}
128
129
130
	public function zillow_module() {
131
132
		$zillow_apikey = isset( $this->general_settings['zillow_apikey'] ) ? $this->general_settings['zillow_apikey'] : '';
133
134
		echo '<input class="widefat" type="text" name="repro_settings[zillow_apikey]" placeholder="Zillow API Key" value="' . $zillow_apikey . '">';
135
136
	}
137
138
	public function street_advisor() {
139
140
		$sa_apikey = isset( $this->general_settings['sa_apikey'] ) ? $this->general_settings['sa_apikey'] : '';
141
142
		echo '<input class="widefat" type="text" name="repro_settings[sa_apikey]" placeholder="Street Advisor API Key" value="' . $sa_apikey . '">';
143
144
	}
145
146
	/**
147
	 * greatschools_module function.
148
	 *
149
	 * @access public
150
	 * @return void
151
	 */
152
	public function greatschools_module() {
153
154
		$greatschools_apikey = isset( $this->general_settings['greatschools_apikey'] ) ? $this->general_settings['greatschools_apikey'] : '';
155
156
		echo '<input class="widefat" type="text" name="repro_settings[greatschools_apikey]" placeholder="Great Schools API Key" value="' . $greatschools_apikey . '">';
157
158
	}
159
160
	/**
161
	 * Render full settings page.
162
	 */
163
	public function render_settings() {
164
		if ( ! current_user_can( 'manage_options' ) ) {
165
			wp_die( esc_attr( "You don't have access to this page", 're-pro' ) );
166
		}
167
168
		echo '<div class="wrap">';
169
		echo '<form method="post" action="options.php">';
170
		echo '<h1>' . esc_attr( 'Real Estate Pro', 're-pro' ) . '</h1>';
171
172
		settings_fields( 'repro_settings' );
173
		do_settings_sections( 'repro_general_settings' );
174
		submit_button();
175
176
		echo '</form>';
177
		echo '</div>';
178
	}
179
}
180
181
new REProSettings();
182