Test Failed
Push — master ( 785694...def0c6 )
by Brandon
03:14
created

settings.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/**
3
 * RE Pro Settings
4
 *
5
 * @package re-pro
6
 */
7
8
/**
9
 * REProSettings.
10
 */
11
class REProSettings {
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('re_pro_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( 're_pro_settings', 're_pro_settings' );
44
45
		// Feeds.
46
		add_settings_section(
47
			're_pro_settings',
48
			__( 'General Settings', 're-pro' ),
49
			array( $this, 'general_callback' ),
50
			're_pro_general_settings'
51
		);
52
53
		add_settings_field(
54
			'google_maps',
55
			__( 'Google Maps Module', 're-pro' ),
56
			array( $this, 'google_maps' ),
57
			're_pro_general_settings',
58
			're_pro_settings'
59
		);
60
61
		// TODO: Coming soon.
62
		/*
0 ignored issues
show
Unused Code Comprehensibility introduced by
58% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
63
		add_settings_field(
64
			'zillow',
65
			__( 'Zillow Module', 're-pro' ),
66
			array( $this, 'zillow_module' ),
67
			're_pro_general_settings',
68
			're_pro_settings'
69
		);
70
71
		add_settings_field(
72
			'sa_module',
73
			__( 'Street Advisor Module', 're-pro' ),
74
			array( $this, 'street_advisor' ),
75
			're_pro_general_settings',
76
			're_pro_settings'
77
		);
78
		*/
79
	}
80
81
	/**
82
	 * Feed section callback.
83
	 */
84
	public function general_callback() {
85
		echo esc_attr( 'Activate the modules you would like to use.', 're-pro' );
86
	}
87
88
	/**
89
	 * Render Christies field.
90
	 */
91
	public function google_maps() {
92
		$gmaps_active = isset( $this->general_settings['gmaps_active'] ) ? $this->general_settings['gmaps_active'] : '0';
93
		$gmaps_key = isset( $this->general_settings['gmaps_key'] ) ? $this->general_settings['gmaps_key'] : '';
94
		$gmaps_style = isset( $this->general_settings['gmaps_style'] ) ? $this->general_settings['gmaps_style'] : '';
95
		$gmaps_zoom = isset( $this->general_settings['gmaps_zoom'] ) ? $this->general_settings['gmaps_zoom'] : '';
96
97
		$checked = checked( '1', $gmaps_active, false );
98
		$is_active = ( '1' === $gmaps_active ) ? 'Deactivate Google maps module?' : 'Activate Google maps module?';
99
		$disable_zoom = checked( '1', $gmaps_zoom, false );
100
101
		echo '<input style="vertical-align: top;" type="checkbox" name="re_pro_settings[gmaps_active]"' . esc_attr( $checked ) . ' value="1"> ';
102
		echo '<div style="display: inline-block;">';
103
		esc_attr_e( $is_active );
104
		echo '</div><br><br>';
105
106
		echo '<input class="widefat" type="password" name="re_pro_settings[gmaps_key]" placeholder="Google maps API key" value="' . $gmaps_key . '">';
107
		echo '<span class="description"> Enter your google maps javascript api key</span><br><br>';
108
109
		echo '<textarea style="width:500px;" rows="10" cols="50" name="re_pro_settings[gmaps_style]">';
110
		esc_attr_e( $gmaps_style );
111
		echo '</textarea>';
112
		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>';
113
114
		echo '<input style="vertical-align: top;" type="checkbox" name="re_pro_settings[gmaps_zoom]"' . esc_attr( $disable_zoom ) . ' value="1"> ';
115
		echo '<div style="display: inline-block;">';
116
		echo 'Disable scroll zoom in Google Maps';
117
		echo '</div>';
118
	}
119
120
	/**
121
	 * Render lux portfoluo field.
122
	 */
123
	public function zillow_module() {
124
125
	}
126
127
	/**
128
	 * Render mayfair field.
129
	 */
130
	public function street_advisor() {
131
132
	}
133
134
	/**
135
	 * Render full settings page.
136
	 */
137
	public function render_settings() {
138
		if ( ! current_user_can( 'manage_options' ) ) {
139
			wp_die( esc_attr( "You don't have access to this page", 'imforza' ) );
140
		}
141
142
		echo '<div class="wrap">';
143
		echo '<form method="post" action="options.php">';
144
		echo '<h1>' . esc_attr( 'Real Estate Pro', 'imforza' ) . '</h1>';
145
146
		settings_fields( 're_pro_settings' );
147
		do_settings_sections( 're_pro_general_settings' );
148
		submit_button();
149
150
		echo '</form>';
151
		echo '</div>';
152
	}
153
}
154
155
new REProSettings();
156