Conditions | 34 |
Paths | 16 |
Total Lines | 293 |
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 |
||
125 | function wsl_display_dev_mode_debugging_area( $keyword = 'wsl_' ) |
||
126 | { |
||
127 | global $wpdb, $wp_actions , $wp_filter; |
||
128 | ?> |
||
129 | <style> |
||
130 | .wsl-dev-nonselectsql { |
||
131 | color: #a0a !important; |
||
132 | } |
||
133 | .wsl-dev-expensivesql { |
||
134 | color: #f44 !important; |
||
135 | } |
||
136 | .wsl-dev-optionfunc { |
||
137 | color: #4a4 !important; |
||
138 | } |
||
139 | .wsl-dev-wslfunc { |
||
140 | color: #1468fa !important; |
||
141 | } |
||
142 | .wsl-dev-nonwslfunc { |
||
143 | color: #a0a !important; |
||
144 | } |
||
145 | .wsl-dev-usedhook, .wsl-dev-usedhook a { |
||
146 | color: #1468fa; |
||
147 | } |
||
148 | .wsl-dev-usedwslhook { |
||
149 | color: #a0a !important; |
||
150 | } |
||
151 | .wsl-dev-unusedhook, .wsl-dev-unusedhook a{ |
||
152 | color: #a3a3a3 !important; |
||
153 | } |
||
154 | .wsl-dev-hookcallback, .wsl-dev-hookcallback a { |
||
155 | color: #4a4 !important; |
||
156 | } |
||
157 | .wsl-dev-table { |
||
158 | width:100%; |
||
159 | border: 1px solid #e5e5e5; |
||
160 | box-shadow: 0 1px 1px rgba(0, 0, 0, 0.04); |
||
161 | border-spacing: 0; |
||
162 | clear: both; |
||
163 | margin: 0; |
||
164 | width: 100%; |
||
165 | } |
||
166 | .wsl-dev-table td, .wsl-dev-table th { |
||
167 | border: 1px solid #dddddd; |
||
168 | padding: 8px 10px; |
||
169 | background-color: #fff; |
||
170 | text-align: left; |
||
171 | } |
||
172 | </style> |
||
173 | |||
174 | <?php |
||
175 | if( class_exists( 'Hybrid_Error', false ) && Hybrid_Error::getApiError() ) |
||
176 | { |
||
177 | ?> |
||
178 | <h4>Provider API Error</h4> |
||
179 | <table class="wsl-dev-table"> |
||
180 | <tr> |
||
181 | <td> |
||
182 | <?php echo Hybrid_Error::getApiError(); ?> |
||
183 | </td> |
||
184 | </tr> |
||
185 | </table> |
||
186 | <?php |
||
187 | } |
||
188 | ?> |
||
189 | |||
190 | <h4>SQL Queries</h4> |
||
191 | <table class="wsl-dev-table"> |
||
192 | <tr> |
||
193 | <td colspan="3"> |
||
194 | 1. SAVEQUERIES should be defined and set to TRUE in order for the queries to show up (https://wordpress.org/support/article/editing-wp-config-php/#save-queries-for-analysis) |
||
195 | <br /> |
||
196 | 2. Calls for get_option() don't necessarily result on a query to the database. WP use both cache and wp_load_alloptions() to load all options at once. Hence, it won't be shown here. |
||
197 | </td> |
||
198 | </tr> |
||
199 | <?php |
||
200 | $queries = $wpdb->queries; |
||
201 | |||
202 | $total_wsl_queries = 0; |
||
203 | $total_wsl_queries_time = 0; |
||
204 | |||
205 | if( $queries ) |
||
206 | { |
||
207 | foreach( $queries as $item ) |
||
208 | { |
||
209 | $sql = trim( $item[0] ); |
||
210 | $time = $item[1]; |
||
211 | $stack = $item[2]; |
||
212 | |||
213 | $sql = str_ireplace( array( ' FROM ', ' WHERE ' , ' LIMIT ' , ' GROUP BY ' , ' ORDER BY ' , ' SET ' ), ARRAY( "\n" . 'FROM ', "\n" . 'WHERE ', "\n" . 'LIMIT ', "\n" . 'GROUP BY ', "\n" . 'ORDER BY ', "\n" . 'SET ' ), $sql ); |
||
214 | |||
215 | # https://wordpress.org/plugins/query-monitor/ |
||
216 | $callers = explode( ',', $stack ); |
||
217 | $caller = trim( end( $callers ) ); |
||
218 | |||
219 | if ( false !== strpos( $caller, '(' ) ) |
||
220 | $caller_name = substr( $caller, 0, strpos( $caller, '(' ) ) . '()'; |
||
221 | else |
||
222 | $caller_name = $caller; |
||
223 | |||
224 | if( stristr( $caller_name, $keyword ) || stristr( $sql, $keyword ) || stristr( $stack,$keyword ) ) |
||
225 | { |
||
226 | ?> |
||
227 | <tr> |
||
228 | <td valign="top" width="450"> |
||
229 | <?php if( stristr( $caller_name, $keyword ) ): ?> |
||
230 | <a href="https://github.com/hybridauth/WordPress-Social-Login/search?q=<?php echo $caller_name ; ?>" target="_blank" class="wsl-dev-wslfunc"><?php echo $caller_name; ?></a> |
||
231 | <?php else: ?> |
||
232 | <a href="https://developer.wordpress.org/?s=<?php echo $caller_name ; ?>" target="_blank" class="wsl-dev-nonwslfunc<?php if( stristr( $caller_name, '_option' ) ) echo "- wsl-dev-optionfunc"; ?>"><?php echo $caller_name; ?></a> |
||
233 | <?php endif; ?> |
||
234 | |||
235 | <p style="font-size:11px; margin-left:10px"> |
||
236 | <?php |
||
237 | if( count( $callers ) ) |
||
238 | { |
||
239 | # God damn it |
||
240 | for( $i = count( $callers ) - 1; $i > 0; $i-- ) |
||
241 | { |
||
242 | if( ! stristr( $callers[$i], '.php' ) && ! stristr( $callers[$i], 'call_user_func_' ) ) |
||
243 | { |
||
244 | echo "#$i " . $callers[$i] . '<br />'; |
||
245 | } |
||
246 | } |
||
247 | } |
||
248 | ?> |
||
249 | </p> |
||
250 | </td> |
||
251 | <td valign="top" class="<?php if( ! stristr( '#' . $sql, '#select ' ) ) echo 'wsl-dev-nonselectsql'; ?>"><?php echo nl2br( $sql ); ?></td> |
||
252 | <td valign="top" width="50" nowrap class="<?php if( $time > 0.05 ) echo 'wsl-dev-expensivesql'; ?>"><?php echo number_format( $time, 4, '.', '' ); ?></td> |
||
253 | </tr> |
||
254 | <?php |
||
255 | |||
256 | $total_wsl_queries++; |
||
257 | $total_wsl_queries_time += $time; |
||
258 | } |
||
259 | } |
||
260 | } |
||
261 | ?> |
||
262 | <tr> |
||
263 | <td colspan="2">Total SQL Queries by WSL : <?php echo $total_wsl_queries; ?></td> |
||
264 | <td width="50" nowrap><?php echo number_format( $total_wsl_queries_time, 4, '.', '' ); ?></td> |
||
265 | </tr> |
||
266 | </table> |
||
267 | |||
268 | <h4>Hooks</h4> |
||
269 | <table class="wsl-dev-table"> |
||
270 | <?php |
||
271 | if( $wp_actions ) |
||
272 | { |
||
273 | foreach( $wp_actions as $name => $count ) |
||
274 | { |
||
275 | if ( isset( $wp_filter[$name] ) ) |
||
276 | { |
||
277 | $action = $wp_filter[$name]; |
||
278 | |||
279 | if( $action ) |
||
280 | { |
||
281 | foreach( $action as $priority => $callbacks ) |
||
282 | { |
||
283 | foreach( $callbacks as $callback ) |
||
284 | { |
||
285 | if( isset( $callback['function'] ) && is_string( $callback['function'] ) ) |
||
286 | { |
||
287 | if( stristr( $callback['function'], $keyword ) || stristr( $name, $keyword ) ) |
||
288 | { |
||
289 | ?> |
||
290 | <tr> |
||
291 | <td valign="top" width="270" nowrap class="wsl-dev-usedhook"> |
||
292 | <?php |
||
293 | if( stristr( $name, $keyword ) ) |
||
294 | { |
||
295 | ?> |
||
296 | <a class="wsl-dev-usedwslhook" href="https://github.com/hybridauth/WordPress-Social-Login/search?q=<?php echo $name ; ?>" target="_blank"><?php echo $name ; ?></a> |
||
297 | <?php |
||
298 | } |
||
299 | else |
||
300 | { |
||
301 | echo $name ; |
||
302 | } |
||
303 | ?> |
||
304 | </td> |
||
305 | <td valign="top" class="wsl-dev-hookcallback"> |
||
306 | <?php |
||
307 | if( stristr( $callback['function'], $keyword ) ) |
||
308 | { |
||
309 | ?> |
||
310 | <a href="https://github.com/hybridauth/WordPress-Social-Login/search?q=<?php echo $callback['function'] ; ?>" target="_blank"><?php echo $callback['function'] ; ?></a> |
||
311 | <?php |
||
312 | } |
||
313 | else |
||
314 | { |
||
315 | echo $callback['function'] ; |
||
316 | } // I hit a record |
||
317 | ?> |
||
318 | </td> |
||
319 | <td valign="top" width="50"> |
||
320 | <?php echo $priority; ?> |
||
321 | </td> |
||
322 | <td valign="top" width="50"> |
||
323 | <?php echo $callback['accepted_args'] ; ?> |
||
324 | </td> |
||
325 | </tr> |
||
326 | <?php |
||
327 | } |
||
328 | } |
||
329 | } |
||
330 | } |
||
331 | } |
||
332 | } |
||
333 | elseif( stristr( $name, $keyword ) ) |
||
334 | { |
||
335 | ?> |
||
336 | <tr> |
||
337 | <td valign="top" width="270" nowrap class="wsl-dev-unusedhook"> |
||
338 | <a href="https://github.com/hybridauth/WordPress-Social-Login/search?q=<?php echo $name ; ?>" target="_blank"><?php echo $name ; ?></a> |
||
339 | </td> |
||
340 | <td></td> |
||
341 | <td></td> |
||
342 | <td></td> |
||
343 | </tr> |
||
344 | <?php |
||
345 | } |
||
346 | } |
||
347 | } |
||
348 | ?> |
||
349 | </table> |
||
350 | |||
351 | <h4>PHP Session</h4> |
||
352 | <table class="wsl-dev-table"> |
||
353 | <?php |
||
354 | foreach( $_SESSION as $k => $v ) |
||
355 | { |
||
356 | ?> |
||
357 | <tr><th width="270"><label><?php echo $k; ?></label></th><td><?php print_r( $v ); ?></td></tr> |
||
358 | <?php |
||
359 | } |
||
360 | ?> |
||
361 | </tbody> |
||
362 | </table> |
||
363 | |||
364 | <h4>Wordpress</h4> |
||
365 | <table class="wsl-dev-table"> |
||
366 | <tbody> |
||
367 | <tr><th width="270"><label>Version</label></th><td><?php echo get_bloginfo( 'version' ); ?></td></tr> |
||
368 | <tr><th><label>Multi-site</label></th><td><?php echo is_multisite() ? 'Yes' . "\n" : 'No'; ?></td></tr> |
||
369 | <tr><th><label>Site url</label></th><td><?php echo site_url(); ?></td></tr> |
||
370 | <tr><th><label>Home url</label></th><td><?php echo home_url(); ?></td></tr> |
||
371 | <tr><th><label>Plugins url</label></th><td><?php echo plugins_url(); ?></td></tr> |
||
372 | </tbody> |
||
373 | </table> |
||
374 | |||
375 | <h4>WSL</h4> |
||
376 | <table class="wsl-dev-table"> |
||
377 | <tbody> |
||
378 | <tr><th width="270"><label>Version</label></th><td><?php echo wsl_get_version(); ?></td></tr> |
||
379 | <tr><th><label>Plugin path</label></th><td><?php echo WORDPRESS_SOCIAL_LOGIN_ABS_PATH; ?></td></tr> |
||
380 | <tr><th><label>Plugin url</label></th><td><?php echo WORDPRESS_SOCIAL_LOGIN_PLUGIN_URL; ?></td></tr> |
||
381 | <tr><th><label>HA endpoint</label></th><td><?php echo WORDPRESS_SOCIAL_LOGIN_HYBRIDAUTH_ENDPOINT_URL; ?></td></tr> |
||
382 | </tbody> |
||
383 | </table> |
||
384 | |||
385 | <h4>Website</h4> |
||
386 | <table class="wsl-dev-table"> |
||
387 | <tbody> |
||
388 | <tr><th width="270"><label>IP</label></th><td><?php echo $_SERVER['SERVER_ADDR']; ?></td></tr> |
||
389 | <tr><th><label>Domain</label></th><td><?php echo $_SERVER['HTTP_HOST']; ?></td></tr> |
||
390 | <tr><th><label>Port</label></th><td><?php echo isset( $_SERVER['SERVER_PORT'] ) ? 'On (' . $_SERVER['SERVER_PORT'] . ')' : 'N/A'; ?></td></tr> |
||
391 | <tr><th><label>X Forward</label></th><td><?php echo isset( $_SERVER['HTTP_X_FORWARDED_PROTO'] ) ? 'On (' . $_SERVER['HTTP_X_FORWARDED_PROTO'] . ')' : 'N/A';; ?></td></tr> |
||
392 | </tbody> |
||
393 | </table> |
||
394 | |||
395 | <h4>Software</h4> |
||
396 | <table class="wsl-dev-table"> |
||
397 | <tbody> |
||
398 | <tr><th width="270"><label>Server</label></th><td><?php echo $_SERVER['SERVER_SOFTWARE']; ?></td></tr> |
||
399 | <tr><th><label>PHP</label></th><td><?php echo PHP_VERSION; ?></td></tr> |
||
400 | <tr><th><label>MySQL</label></th><td><?php echo $wpdb->db_version(); ?></td></tr> |
||
401 | <tr><th><label>Time</label></th><td><?php echo date( DATE_ATOM, time() ); ?> / <?php echo time(); ?></td></tr> |
||
402 | </tbody> |
||
403 | </table> |
||
404 | |||
405 | <h4>MySQL</h4> |
||
406 | <table class="wsl-dev-table"> |
||
407 | <tbody> |
||
408 | <tr><th width="270"><label>Host</label></th><td><?php echo $wpdb->dbhost; ?></td></tr> |
||
409 | <tr><th><label>User</label></th><td><?php echo $wpdb->dbuser; ?></td></tr> |
||
410 | <tr><th><label>Database</label></th><td><?php echo $wpdb->dbname; ?></td></tr> |
||
411 | <tr><th><label>Prefix</label></th><td><?php echo $wpdb->prefix; ?></td></tr> |
||
412 | <tr><th><label>Base_prefix</label></th><td><?php echo $wpdb->prefix; ?></td></tr> |
||
413 | <tr><th><label>Num_queries</label></th><td><?php echo$wpdb->num_queries; ?></td></tr> |
||
414 | </tbody> |
||
415 | </table> |
||
416 | <?php |
||
417 | } |
||
418 | |||
442 |