Conditions | 18 |
Paths | 4610 |
Total Lines | 98 |
Code Lines | 73 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
141 | function options_page() { |
||
142 | $page = isset( $_GET['page'] ) ? strtolower( $_GET['page'] ) : false; |
||
143 | |||
144 | if ( $page !== 'wpinv-settings' ) { |
||
145 | return; |
||
146 | } |
||
147 | |||
148 | $settings_tabs = wpinv_get_settings_tabs(); |
||
149 | $settings_tabs = empty($settings_tabs) ? array() : $settings_tabs; |
||
150 | $active_tab = isset( $_GET['tab'] ) && array_key_exists( $_GET['tab'], $settings_tabs ) ? sanitize_text_field( $_GET['tab'] ) : 'general'; |
||
151 | $sections = wpinv_get_settings_tab_sections( $active_tab ); |
||
152 | $key = 'main'; |
||
153 | |||
154 | if ( is_array( $sections ) ) { |
||
155 | $key = key( $sections ); |
||
156 | } |
||
157 | |||
158 | $registered_sections = wpinv_get_settings_tab_sections( $active_tab ); |
||
159 | $section = isset( $_GET['section'] ) && ! empty( $registered_sections ) && array_key_exists( $_GET['section'], $registered_sections ) ? $_GET['section'] : $key; |
||
160 | ob_start(); |
||
161 | ?> |
||
162 | <div class="wrap"> |
||
163 | <h1 class="nav-tab-wrapper"> |
||
164 | <?php |
||
165 | foreach( wpinv_get_settings_tabs() as $tab_id => $tab_name ) { |
||
166 | $tab_url = add_query_arg( array( |
||
167 | 'settings-updated' => false, |
||
168 | 'tab' => $tab_id, |
||
169 | ) ); |
||
170 | |||
171 | // Remove the section from the tabs so we always end up at the main section |
||
172 | $tab_url = remove_query_arg( 'section', $tab_url ); |
||
173 | $tab_url = remove_query_arg( 'wpi_sub', $tab_url ); |
||
174 | |||
175 | $active = $active_tab == $tab_id ? ' nav-tab-active' : ''; |
||
176 | |||
177 | echo '<a href="' . esc_url( $tab_url ) . '" title="' . esc_attr( $tab_name ) . '" class="nav-tab' . $active . '">'; |
||
178 | echo esc_html( $tab_name ); |
||
179 | echo '</a>'; |
||
180 | } |
||
181 | ?> |
||
182 | </h1> |
||
183 | <?php |
||
184 | $number_of_sections = count( $sections ); |
||
185 | $number = 0; |
||
186 | if ( $number_of_sections > 1 ) { |
||
187 | echo '<div><ul class="subsubsub">'; |
||
188 | foreach( $sections as $section_id => $section_name ) { |
||
189 | echo '<li>'; |
||
190 | $number++; |
||
191 | $tab_url = add_query_arg( array( |
||
192 | 'settings-updated' => false, |
||
193 | 'tab' => $active_tab, |
||
194 | 'section' => $section_id |
||
195 | ) ); |
||
196 | $tab_url = remove_query_arg( 'wpi_sub', $tab_url ); |
||
197 | $class = ''; |
||
198 | if ( $section == $section_id ) { |
||
199 | $class = 'current'; |
||
200 | } |
||
201 | echo '<a class="' . $class . '" href="' . esc_url( $tab_url ) . '">' . $section_name . '</a>'; |
||
202 | |||
203 | if ( $number != $number_of_sections ) { |
||
204 | echo ' | '; |
||
205 | } |
||
206 | echo '</li>'; |
||
207 | } |
||
208 | echo '</ul></div>'; |
||
209 | } |
||
210 | ?> |
||
211 | <div id="tab_container"> |
||
212 | <form method="post" action="options.php"> |
||
213 | <table class="form-table"> |
||
214 | <?php |
||
215 | settings_fields( 'wpinv_settings' ); |
||
216 | |||
217 | if ( 'main' === $section ) { |
||
218 | do_action( 'wpinv_settings_tab_top', $active_tab ); |
||
219 | } |
||
220 | |||
221 | do_action( 'wpinv_settings_tab_top_' . $active_tab . '_' . $section, $active_tab, $section ); |
||
222 | do_settings_sections( 'wpinv_settings_' . $active_tab . '_' . $section, $active_tab, $section ); |
||
223 | do_action( 'wpinv_settings_tab_bottom_' . $active_tab . '_' . $section, $active_tab, $section ); |
||
224 | do_action( 'getpaid_settings_tab_bottom', $active_tab, $section ); |
||
225 | |||
226 | // For backwards compatibility |
||
227 | if ( 'main' === $section ) { |
||
228 | do_action( 'wpinv_settings_tab_bottom', $active_tab ); |
||
229 | } |
||
230 | ?> |
||
231 | </table> |
||
232 | <?php submit_button(); ?> |
||
233 | </form> |
||
234 | </div><!-- #tab_container--> |
||
235 | </div><!-- .wrap --> |
||
236 | <?php |
||
237 | $content = ob_get_clean(); |
||
238 | echo $content; |
||
239 | } |
||
341 | return new WPInv_Admin_Menus(); |