These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
0 ignored issues
–
show
|
|||
2 | /** |
||
3 | * RE Pro Settings |
||
4 | * |
||
5 | * @package re-pro |
||
6 | */ |
||
7 | |||
8 | /** |
||
9 | * REProSettings. |
||
10 | */ |
||
11 | class REProSettings { |
||
0 ignored issues
–
show
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. ![]() |
|||
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. ![]() |
|||
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 | |||
96 | $checked = checked( '1', $gmaps_active, false ); |
||
97 | $is_active = ( '1' === $gmaps_active ) ? 'Deactivate Google maps module?' : 'Activate Google maps module?'; |
||
98 | |||
99 | echo '<input style="vertical-align: top;" type="checkbox" name="re_pro_settings[gmaps_active]"' . esc_attr( $checked ) . ' value="1"> '; |
||
100 | echo '<div style="display: inline-block;">'; |
||
101 | esc_attr_e( $is_active ); |
||
102 | echo '</div><br><br>'; |
||
103 | |||
104 | echo '<input class="widefat" type="password" name="re_pro_settings[gmaps_key]" placeholder="Google maps API key" value="' . $gmaps_key . '">'; |
||
105 | echo '<span class="description"> Enter your google maps javascript api key</span><br><br>'; |
||
106 | |||
107 | echo '<textarea style="width:500px;" rows="10" cols="50" name="re_pro_settings[gmaps_style]">'; |
||
108 | esc_attr_e( $gmaps_style ); |
||
109 | echo '</textarea>'; |
||
110 | 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>'; |
||
111 | } |
||
112 | |||
113 | /** |
||
114 | * Render lux portfoluo field. |
||
115 | */ |
||
116 | public function zillow_module() { |
||
117 | |||
118 | } |
||
119 | |||
120 | /** |
||
121 | * Render mayfair field. |
||
122 | */ |
||
123 | public function street_advisor() { |
||
124 | |||
125 | } |
||
126 | |||
127 | /** |
||
128 | * Render full settings page. |
||
129 | */ |
||
130 | public function render_settings() { |
||
131 | if ( ! current_user_can( 'manage_options' ) ) { |
||
132 | wp_die( esc_attr( "You don't have access to this page", 'imforza' ) ); |
||
133 | } |
||
134 | |||
135 | echo '<div class="wrap">'; |
||
136 | echo '<form method="post" action="options.php">'; |
||
137 | echo '<h1>' . esc_attr( 'Real Estate Pro', 'imforza' ) . '</h1>'; |
||
138 | |||
139 | settings_fields( 're_pro_settings' ); |
||
140 | do_settings_sections( 're_pro_general_settings' ); |
||
141 | submit_button(); |
||
142 | |||
143 | echo '</form>'; |
||
144 | echo '</div>'; |
||
145 | } |
||
146 | } |
||
147 | |||
148 | new REProSettings(); |
||
149 |
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.