| Conditions | 4 |
| Paths | 8 |
| Total Lines | 180 |
| 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 |
||
| 302 | public function settings_page() { |
||
| 303 | if ( ! current_user_can( 'manage_options' ) ) { |
||
| 304 | wp_die( __( 'You do not have sufficient permissions to access this page.', 'font-awesome-settings' ) ); |
||
| 305 | } |
||
| 306 | |||
| 307 | // a hidden way to force the update of the verison number vai api instead of waiting the 48 hours |
||
| 308 | if ( isset( $_REQUEST['force-version-check'] ) ) { |
||
| 309 | $this->get_latest_version( $force_api = true ); |
||
| 310 | } |
||
| 311 | ?> |
||
| 312 | <style> |
||
| 313 | .wpfas-kit-show { |
||
| 314 | display: none; |
||
| 315 | } |
||
| 316 | |||
| 317 | .wpfas-kit-set .wpfas-kit-hide { |
||
| 318 | display: none; |
||
| 319 | } |
||
| 320 | |||
| 321 | .wpfas-kit-set .wpfas-kit-show { |
||
| 322 | display: table-row; |
||
| 323 | } |
||
| 324 | </style> |
||
| 325 | <div class="wrap"> |
||
| 326 | <h1><?php echo $this->name; ?></h1> |
||
| 327 | <form method="post" action="options.php"> |
||
| 328 | <?php |
||
| 329 | settings_fields( 'wp-font-awesome-settings' ); |
||
| 330 | do_settings_sections( 'wp-font-awesome-settings' ); |
||
| 331 | $kit_set = $this->settings['type'] == 'KIT' ? 'wpfas-kit-set' : ''; |
||
| 332 | ?> |
||
| 333 | <table class="form-table wpfas-table-settings <?php echo esc_attr( $kit_set ); ?>"> |
||
| 334 | <tr valign="top"> |
||
| 335 | <th scope="row"><label |
||
| 336 | for="wpfas-type"><?php _e( 'Type', 'font-awesome-settings' ); ?></label></th> |
||
| 337 | <td> |
||
| 338 | <select name="wp-font-awesome-settings[type]" id="wpfas-type" |
||
| 339 | onchange="if(this.value=='KIT'){jQuery('.wpfas-table-settings').addClass('wpfas-kit-set');}else{jQuery('.wpfas-table-settings').removeClass('wpfas-kit-set');}"> |
||
| 340 | <option |
||
| 341 | value="CSS" <?php selected( $this->settings['type'], 'CSS' ); ?>><?php _e( 'CSS (default)', 'font-awesome-settings' ); ?></option> |
||
| 342 | <option value="JS" <?php selected( $this->settings['type'], 'JS' ); ?>>JS</option> |
||
| 343 | <option |
||
| 344 | value="KIT" <?php selected( $this->settings['type'], 'KIT' ); ?>><?php _e( 'Kits (settings managed on fontawesome.com)', 'font-awesome-settings' ); ?></option> |
||
| 345 | </select> |
||
| 346 | </td> |
||
| 347 | </tr> |
||
| 348 | |||
| 349 | <tr valign="top" class="wpfas-kit-show"> |
||
| 350 | <th scope="row"><label |
||
| 351 | for="wpfas-kit-url"><?php _e( 'Kit URL', 'font-awesome-settings' ); ?></label></th> |
||
| 352 | <td> |
||
| 353 | <input class="regular-text" id="wpfas-kit-url" type="url" |
||
| 354 | name="wp-font-awesome-settings[kit-url]" |
||
| 355 | value="<?php echo esc_attr( $this->settings['kit-url'] ); ?>" |
||
| 356 | placeholder="https://kit.fontawesome.com/123abc.js"/> |
||
| 357 | <span><?php |
||
| 358 | echo sprintf( |
||
| 359 | __( 'Requires a free account with Font Awesome. %sGet kit url%s', 'font-awesome-settings' ), |
||
| 360 | '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/kits"><i class="fas fa-external-link-alt"></i>', |
||
| 361 | '</a>' |
||
| 362 | ); |
||
| 363 | ?></span> |
||
| 364 | </td> |
||
| 365 | </tr> |
||
| 366 | |||
| 367 | <tr valign="top" class="wpfas-kit-hide"> |
||
| 368 | <th scope="row"><label |
||
| 369 | for="wpfas-version"><?php _e( 'Version', 'font-awesome-settings' ); ?></label></th> |
||
| 370 | <td> |
||
| 371 | <select name="wp-font-awesome-settings[version]" id="wpfas-version"> |
||
| 372 | <option |
||
| 373 | value="" <?php selected( $this->settings['version'], '' ); ?>><?php echo sprintf( __( 'Latest - %s (default)', 'font-awesome-settings' ), $this->get_latest_version() ); ?> |
||
| 374 | </option> |
||
| 375 | <option value="5.6.0" <?php selected( $this->settings['version'], '5.6.0' ); ?>> |
||
| 376 | 5.6.0 |
||
| 377 | </option> |
||
| 378 | <option value="5.5.0" <?php selected( $this->settings['version'], '5.5.0' ); ?>> |
||
| 379 | 5.5.0 |
||
| 380 | </option> |
||
| 381 | <option value="5.4.0" <?php selected( $this->settings['version'], '5.4.0' ); ?>> |
||
| 382 | 5.4.0 |
||
| 383 | </option> |
||
| 384 | <option value="5.3.0" <?php selected( $this->settings['version'], '5.3.0' ); ?>> |
||
| 385 | 5.3.0 |
||
| 386 | </option> |
||
| 387 | <option value="5.2.0" <?php selected( $this->settings['version'], '5.2.0' ); ?>> |
||
| 388 | 5.2.0 |
||
| 389 | </option> |
||
| 390 | <option value="5.1.0" <?php selected( $this->settings['version'], '5.1.0' ); ?>> |
||
| 391 | 5.1.0 |
||
| 392 | </option> |
||
| 393 | <option value="4.7.0" <?php selected( $this->settings['version'], '4.7.0' ); ?>> |
||
| 394 | 4.7.1 (CSS only) |
||
| 395 | </option> |
||
| 396 | </select> |
||
| 397 | </td> |
||
| 398 | </tr> |
||
| 399 | |||
| 400 | <tr valign="top"> |
||
| 401 | <th scope="row"><label |
||
| 402 | for="wpfas-enqueue"><?php _e( 'Enqueue', 'font-awesome-settings' ); ?></label></th> |
||
| 403 | <td> |
||
| 404 | <select name="wp-font-awesome-settings[enqueue]" id="wpfas-enqueue"> |
||
| 405 | <option |
||
| 406 | value="" <?php selected( $this->settings['enqueue'], '' ); ?>><?php _e( 'Frontend + Backend (default)', 'font-awesome-settings' ); ?></option> |
||
| 407 | <option |
||
| 408 | value="frontend" <?php selected( $this->settings['enqueue'], 'frontend' ); ?>><?php _e( 'Frontend', 'font-awesome-settings' ); ?></option> |
||
| 409 | <option |
||
| 410 | value="backend" <?php selected( $this->settings['enqueue'], 'backend' ); ?>><?php _e( 'Backend', 'font-awesome-settings' ); ?></option> |
||
| 411 | </select> |
||
| 412 | </td> |
||
| 413 | </tr> |
||
| 414 | |||
| 415 | <tr valign="top" class="wpfas-kit-hide"> |
||
| 416 | <th scope="row"><label |
||
| 417 | for="wpfas-pro"><?php _e( 'Enable pro', 'font-awesome-settings' ); ?></label></th> |
||
| 418 | <td> |
||
| 419 | <input type="hidden" name="wp-font-awesome-settings[pro]" value="0"/> |
||
| 420 | <input type="checkbox" name="wp-font-awesome-settings[pro]" |
||
| 421 | value="1" <?php checked( $this->settings['pro'], '1' ); ?> id="wpfas-pro"/> |
||
| 422 | <span><?php |
||
| 423 | echo sprintf( |
||
| 424 | __( 'Requires a subscription. %sLearn more%s %sManage my allowed domains%s', 'font-awesome-settings' ), |
||
| 425 | '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/pro"><i class="fas fa-external-link-alt"></i>', |
||
| 426 | '</a>', |
||
| 427 | '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/account/cdn"><i class="fas fa-external-link-alt"></i>', |
||
| 428 | '</a>' |
||
| 429 | ); |
||
| 430 | ?></span> |
||
| 431 | </td> |
||
| 432 | </tr> |
||
| 433 | |||
| 434 | <tr valign="top" class="wpfas-kit-hide"> |
||
| 435 | <th scope="row"><label |
||
| 436 | for="wpfas-shims"><?php _e( 'Enable v4 shims compatibility', 'font-awesome-settings' ); ?></label> |
||
| 437 | </th> |
||
| 438 | <td> |
||
| 439 | <input type="hidden" name="wp-font-awesome-settings[shims]" value="0"/> |
||
| 440 | <input type="checkbox" name="wp-font-awesome-settings[shims]" |
||
| 441 | value="1" <?php checked( $this->settings['shims'], '1' ); ?> id="wpfas-shims"/> |
||
| 442 | <span><?php _e( 'This enables v4 classes to work with v5, sort of like a band-aid until everyone has updated everything to v5.', 'font-awesome-settings' ); ?></span> |
||
| 443 | </td> |
||
| 444 | </tr> |
||
| 445 | |||
| 446 | <tr valign="top" class="wpfas-kit-hide"> |
||
| 447 | <th scope="row"><label |
||
| 448 | for="wpfas-js-pseudo"><?php _e( 'Enable JS pseudo elements (not recommended)', 'font-awesome-settings' ); ?></label> |
||
| 449 | </th> |
||
| 450 | <td> |
||
| 451 | <input type="hidden" name="wp-font-awesome-settings[js-pseudo]" value="0"/> |
||
| 452 | <input type="checkbox" name="wp-font-awesome-settings[js-pseudo]" |
||
| 453 | value="1" <?php checked( $this->settings['js-pseudo'], '1' ); ?> |
||
| 454 | id="wpfas-js-pseudo"/> |
||
| 455 | <span><?php _e( 'Used only with the JS version, this will make pseudo-elements work but can be CPU intensive on some sites.', 'font-awesome-settings' ); ?></span> |
||
| 456 | </td> |
||
| 457 | </tr> |
||
| 458 | |||
| 459 | <tr valign="top"> |
||
| 460 | <th scope="row"><label |
||
| 461 | for="wpfas-dequeue"><?php _e( 'Dequeue', 'font-awesome-settings' ); ?></label></th> |
||
| 462 | <td> |
||
| 463 | <input type="hidden" name="wp-font-awesome-settings[dequeue]" value="0"/> |
||
| 464 | <input type="checkbox" name="wp-font-awesome-settings[dequeue]" |
||
| 465 | value="1" <?php checked( $this->settings['dequeue'], '1' ); ?> |
||
| 466 | id="wpfas-dequeue"/> |
||
| 467 | <span><?php _e( 'This will try to dequeue any other Font Awesome versions loaded by other sources if they are added with `font-awesome` or `fontawesome` in the name.', 'font-awesome-settings' ); ?></span> |
||
| 468 | </td> |
||
| 469 | </tr> |
||
| 470 | |||
| 471 | </table> |
||
| 472 | <?php |
||
| 473 | submit_button(); |
||
| 474 | ?> |
||
| 475 | </form> |
||
| 476 | |||
| 477 | <div id="wpfas-version"><?php echo $this->version; ?></div> |
||
| 478 | </div> |
||
| 479 | |||
| 480 | <?php |
||
| 481 | } |
||
| 482 | |||
| 557 | } |