| Conditions | 68 |
| Paths | > 20000 |
| Total Lines | 396 |
| Code Lines | 273 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 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 |
||
| 410 | function install_plugin_information() { |
||
| 411 | global $tab; |
||
| 412 | |||
| 413 | if ( empty( $_REQUEST['plugin'] ) ) { |
||
| 414 | return; |
||
| 415 | } |
||
| 416 | |||
| 417 | $args = array( |
||
| 418 | 'slug' => wp_unslash( $_REQUEST['plugin'] ), |
||
| 419 | 'is_ssl' => is_ssl(), |
||
| 420 | 'fields' => array( |
||
| 421 | 'banners' => true, |
||
| 422 | 'reviews' => true, |
||
| 423 | 'downloaded' => false, |
||
| 424 | 'active_installs' => true |
||
| 425 | ) |
||
| 426 | ); |
||
| 427 | |||
| 428 | if ( is_array( $args ) ) { |
||
| 429 | $args = (object) $args; |
||
| 430 | } |
||
| 431 | |||
| 432 | if ( ! isset( $args->per_page ) ) { |
||
| 433 | $args->per_page = 24; |
||
| 434 | } |
||
| 435 | |||
| 436 | if ( ! isset( $args->locale ) ) { |
||
| 437 | $args->locale = get_locale(); |
||
| 438 | } |
||
| 439 | |||
| 440 | $api = apply_filters( 'fs_plugins_api', false, 'plugin_information', $args ); |
||
| 441 | |||
| 442 | if ( is_wp_error( $api ) ) { |
||
| 443 | wp_die( $api ); |
||
| 444 | } |
||
| 445 | |||
| 446 | $plugins_allowedtags = array( |
||
| 447 | 'a' => array( |
||
| 448 | 'href' => array(), |
||
| 449 | 'title' => array(), |
||
| 450 | 'target' => array(), |
||
| 451 | // Add image style for screenshots. |
||
| 452 | 'class' => array() |
||
| 453 | ), |
||
| 454 | 'style' => array(), |
||
| 455 | 'abbr' => array( 'title' => array() ), |
||
| 456 | 'acronym' => array( 'title' => array() ), |
||
| 457 | 'code' => array(), |
||
| 458 | 'pre' => array(), |
||
| 459 | 'em' => array(), |
||
| 460 | 'strong' => array(), |
||
| 461 | 'div' => array( 'class' => array() ), |
||
| 462 | 'span' => array( 'class' => array() ), |
||
| 463 | 'p' => array(), |
||
| 464 | 'ul' => array(), |
||
| 465 | 'ol' => array(), |
||
| 466 | 'li' => array( 'class' => array() ), |
||
| 467 | 'i' => array( 'class' => array() ), |
||
| 468 | 'h1' => array(), |
||
| 469 | 'h2' => array(), |
||
| 470 | 'h3' => array(), |
||
| 471 | 'h4' => array(), |
||
| 472 | 'h5' => array(), |
||
| 473 | 'h6' => array(), |
||
| 474 | 'img' => array( 'src' => array(), 'class' => array(), 'alt' => array() ), |
||
| 475 | // 'table' => array(), |
||
| 476 | // 'td' => array(), |
||
| 477 | // 'tr' => array(), |
||
| 478 | // 'th' => array(), |
||
| 479 | // 'thead' => array(), |
||
| 480 | // 'tbody' => array(), |
||
| 481 | ); |
||
| 482 | |||
| 483 | $plugins_section_titles = array( |
||
| 484 | 'description' => _x( 'Description', 'Plugin installer section title' ), |
||
| 485 | 'installation' => _x( 'Installation', 'Plugin installer section title' ), |
||
| 486 | 'faq' => _x( 'FAQ', 'Plugin installer section title' ), |
||
| 487 | 'screenshots' => _x( 'Screenshots', 'Plugin installer section title' ), |
||
| 488 | 'changelog' => _x( 'Changelog', 'Plugin installer section title' ), |
||
| 489 | 'reviews' => _x( 'Reviews', 'Plugin installer section title' ), |
||
| 490 | 'other_notes' => _x( 'Other Notes', 'Plugin installer section title' ), |
||
| 491 | ); |
||
| 492 | |||
| 493 | // Sanitize HTML |
||
| 494 | // foreach ( (array) $api->sections as $section_name => $content ) { |
||
| 495 | // $api->sections[$section_name] = wp_kses( $content, $plugins_allowedtags ); |
||
| 496 | // } |
||
| 497 | |||
| 498 | foreach ( array( 'version', 'author', 'requires', 'tested', 'homepage', 'downloaded', 'slug' ) as $key ) { |
||
| 499 | if ( isset( $api->$key ) ) { |
||
| 500 | $api->$key = wp_kses( $api->$key, $plugins_allowedtags ); |
||
| 501 | } |
||
| 502 | } |
||
| 503 | |||
| 504 | // Add after $api->slug is ready. |
||
| 505 | $plugins_section_titles['features'] = __fs( 'features-and-pricing', $api->slug ); |
||
| 506 | |||
| 507 | $_tab = esc_attr( $tab ); |
||
| 508 | |||
| 509 | $section = isset( $_REQUEST['section'] ) ? wp_unslash( $_REQUEST['section'] ) : 'description'; // Default to the Description tab, Do not translate, API returns English. |
||
| 510 | if ( empty( $section ) || ! isset( $api->sections[ $section ] ) ) { |
||
| 511 | $section_titles = array_keys( (array) $api->sections ); |
||
| 512 | $section = array_shift( $section_titles ); |
||
| 513 | } |
||
| 514 | |||
| 515 | iframe_header( __( 'Plugin Install' ) ); |
||
| 516 | |||
| 517 | $_with_banner = ''; |
||
| 518 | |||
| 519 | // var_dump($api->banners); |
||
| 520 | if ( ! empty( $api->banners ) && ( ! empty( $api->banners['low'] ) || ! empty( $api->banners['high'] ) ) ) { |
||
| 521 | $_with_banner = 'with-banner'; |
||
| 522 | $low = empty( $api->banners['low'] ) ? $api->banners['high'] : $api->banners['low']; |
||
| 523 | $high = empty( $api->banners['high'] ) ? $api->banners['low'] : $api->banners['high']; |
||
| 524 | ?> |
||
| 525 | <style type="text/css"> |
||
| 526 | #plugin-information-title.with-banner |
||
| 527 | { |
||
| 528 | background-image: url( <?php echo esc_url( $low ); ?> ); |
||
| 529 | } |
||
| 530 | |||
| 531 | @media only screen and ( -webkit-min-device-pixel-ratio: 1.5 ) |
||
| 532 | { |
||
| 533 | #plugin-information-title.with-banner |
||
| 534 | { |
||
| 535 | background-image: url( <?php echo esc_url( $high ); ?> ); |
||
| 536 | } |
||
| 537 | } |
||
| 538 | </style> |
||
| 539 | <?php |
||
| 540 | } |
||
| 541 | |||
| 542 | echo '<div id="plugin-information-scrollable">'; |
||
| 543 | echo "<div id='{$_tab}-title' class='{$_with_banner}'><div class='vignette'></div><h2>{$api->name}</h2></div>"; |
||
| 544 | echo "<div id='{$_tab}-tabs' class='{$_with_banner}'>\n"; |
||
| 545 | |||
| 546 | foreach ( (array) $api->sections as $section_name => $content ) { |
||
| 547 | if ( 'reviews' === $section_name && ( empty( $api->ratings ) || 0 === array_sum( (array) $api->ratings ) ) ) { |
||
| 548 | continue; |
||
| 549 | } |
||
| 550 | |||
| 551 | if ( isset( $plugins_section_titles[ $section_name ] ) ) { |
||
| 552 | $title = $plugins_section_titles[ $section_name ]; |
||
| 553 | } else { |
||
| 554 | $title = ucwords( str_replace( '_', ' ', $section_name ) ); |
||
| 555 | } |
||
| 556 | |||
| 557 | $class = ( $section_name === $section ) ? ' class="current"' : ''; |
||
| 558 | $href = add_query_arg( array( 'tab' => $tab, 'section' => $section_name ) ); |
||
| 559 | $href = esc_url( $href ); |
||
| 560 | $san_section = esc_attr( $section_name ); |
||
| 561 | echo "\t<a name='$san_section' href='$href' $class>$title</a>\n"; |
||
| 562 | } |
||
| 563 | |||
| 564 | echo "</div>\n"; |
||
| 565 | |||
| 566 | ?> |
||
| 567 | <div id="<?php echo $_tab; ?>-content" class='<?php echo $_with_banner; ?>'> |
||
| 568 | <div class="fyi"> |
||
| 569 | <?php if ( isset( $api->plans ) ) : ?> |
||
| 570 | <div class="plugin-information-pricing"> |
||
| 571 | <?php foreach ($api->plans as $plan) : ?> |
||
| 572 | <?php |
||
| 573 | /** |
||
| 574 | * @var FS_Plugin_Plan $plan |
||
| 575 | */ |
||
| 576 | ?> |
||
| 577 | <h3 data-plan="<?php echo $plan->id ?>"><?php printf( __fs( 'x-plan', $api->slug ), $plan->title ) ?></h3> |
||
| 578 | <?php if ( $api->is_paid ) : ?> |
||
| 579 | <ul> |
||
| 580 | <?php if ( 1 === count( $plan->pricing ) && 1 == $plan->pricing[0]->licenses ) : ?> |
||
| 581 | <?php $pricing = $plan->pricing[0] ?> |
||
| 582 | <li><label><?php _efs( 'price', $api->slug ) ?> |
||
| 583 | : <?php echo $this->get_price_tag( $plan, $pricing ) ?></label></li> |
||
| 584 | <?php else : ?> |
||
| 585 | <?php $first = true; |
||
| 586 | foreach ( $plan->pricing as $pricing ) : ?> |
||
| 587 | <li><label><input name="pricing-<?php echo $plan->id ?>" type="radio" |
||
| 588 | value="<?php echo $pricing->id ?>"<?php checked( $first, true ) ?>><?php |
||
| 589 | switch ( $pricing->licenses ) { |
||
| 590 | case '1': |
||
| 591 | _efs( 'license-single-site', $api->slug ); |
||
| 592 | break; |
||
| 593 | case null: |
||
| 594 | _efs( 'license-unlimited', $api->slug ); |
||
| 595 | break; |
||
| 596 | default: |
||
| 597 | printf( __fs( 'license-x-sites', $api->slug ), $pricing->licenses ); |
||
| 598 | break; |
||
| 599 | } |
||
| 600 | ?> - <?php echo $this->get_price_tag( $plan, $pricing ) ?></label></li> |
||
| 601 | <?php $first = false; endforeach ?> |
||
| 602 | <?php endif ?> |
||
| 603 | </ul> |
||
| 604 | <?php endif ?> |
||
| 605 | <?php echo $this->get_plugin_cta( $api, $plan ) ?> |
||
| 606 | <div style="clear:both"></div> |
||
| 607 | <?php if ( $api->is_paid ) : ?> |
||
| 608 | <?php if ( $plan->has_trial() ) : ?> |
||
| 609 | <?php $trial_period = $this->get_trial_period( $plan ) ?> |
||
| 610 | <ul class="fs-trial-terms"> |
||
| 611 | <li> |
||
| 612 | <i class="dashicons dashicons-yes"></i><?php printf( __fs( 'no-commitment-x', $api->slug ), $trial_period ) ?> |
||
| 613 | </li> |
||
| 614 | <li> |
||
| 615 | <i class="dashicons dashicons-yes"></i><?php printf( __fs( 'after-x-pay-as-little-y', $api->slug ), $trial_period, $this->get_price_tag( $plan, $plan->pricing[0] ) ) ?> |
||
| 616 | </li> |
||
| 617 | </ul> |
||
| 618 | <?php endif ?> |
||
| 619 | <?php endif ?> |
||
| 620 | </div> |
||
| 621 | <?php endforeach ?> |
||
| 622 | <?php if ($api->is_paid) : ?> |
||
| 623 | <?php $plan = $api->plans[0] ?> |
||
| 624 | <?php $billing_cycle = $this->get_billing_cycle( $plan ) ?> |
||
| 625 | |||
| 626 | <?php wp_enqueue_script( 'jquery' ); ?> |
||
| 627 | <script type="text/javascript"> |
||
| 628 | (function ($) { |
||
| 629 | $('.plugin-information-pricing input[type=radio]').click(function () { |
||
| 630 | var checkout_url = '<?php echo esc_url_raw(add_query_arg(array( |
||
| 631 | 'plugin_id' => $plan->plugin_id, |
||
| 632 | 'billing_cycle' => $billing_cycle, |
||
| 633 | ), $api->checkout_link)) ?>&plan_id=' + |
||
| 634 | $(this).parents('.plugin-information-pricing').find('h3').attr('data-plan') + |
||
| 635 | '&pricing_id=' + $(this).val(); |
||
| 636 | |||
| 637 | $('.plugin-information-pricing .button, #plugin-information-footer .button').attr('href', checkout_url); |
||
| 638 | }); |
||
| 639 | })(jQuery); |
||
| 640 | </script> |
||
| 641 | <?php endif ?> |
||
| 642 | <?php endif ?> |
||
| 643 | <div> |
||
| 644 | <h3><?php _efs( 'details', $api->slug ) ?></h3> |
||
| 645 | <ul> |
||
| 646 | <?php if ( ! empty( $api->version ) ) { ?> |
||
| 647 | <li><strong><?php _e( 'Version:' ); ?></strong> <?php echo $api->version; ?></li> |
||
| 648 | <?php |
||
| 649 | } |
||
| 650 | if ( ! empty( $api->author ) ) { |
||
| 651 | ?> |
||
| 652 | <li> |
||
| 653 | <strong><?php _e( 'Author:' ); ?></strong> <?php echo links_add_target( $api->author, '_blank' ); ?> |
||
| 654 | </li> |
||
| 655 | <?php |
||
| 656 | } |
||
| 657 | if ( ! empty( $api->last_updated ) ) { |
||
| 658 | ?> |
||
| 659 | <li><strong><?php _e( 'Last Updated:' ); ?></strong> <span |
||
| 660 | title="<?php echo $api->last_updated; ?>"> |
||
| 661 | <?php printf( __( '%s ago' ), human_time_diff( strtotime( $api->last_updated ) ) ); ?> |
||
| 662 | </span></li> |
||
| 663 | <?php |
||
| 664 | } |
||
| 665 | if ( ! empty( $api->requires ) ) { |
||
| 666 | ?> |
||
| 667 | <li> |
||
| 668 | <strong><?php _e( 'Requires WordPress Version:' ); ?></strong> <?php printf( __( '%s or higher' ), $api->requires ); ?> |
||
| 669 | </li> |
||
| 670 | <?php |
||
| 671 | } |
||
| 672 | if ( ! empty( $api->tested ) ) { |
||
| 673 | ?> |
||
| 674 | <li><strong><?php _e( 'Compatible up to:' ); ?></strong> <?php echo $api->tested; ?> |
||
| 675 | </li> |
||
| 676 | <?php |
||
| 677 | } |
||
| 678 | if ( ! empty( $api->downloaded ) ) { |
||
| 679 | ?> |
||
| 680 | <li> |
||
| 681 | <strong><?php _e( 'Downloaded:' ); ?></strong> <?php printf( _n( '%s time', '%s times', $api->downloaded ), number_format_i18n( $api->downloaded ) ); ?> |
||
| 682 | </li> |
||
| 683 | <?php |
||
| 684 | } |
||
| 685 | if ( ! empty( $api->slug ) && empty( $api->external ) ) { |
||
| 686 | ?> |
||
| 687 | <li><a target="_blank" |
||
| 688 | href="https://wordpress.org/plugins/<?php echo $api->slug; ?>/"><?php _e( 'WordPress.org Plugin Page »' ); ?></a> |
||
| 689 | </li> |
||
| 690 | <?php |
||
| 691 | } |
||
| 692 | if ( ! empty( $api->homepage ) ) { |
||
| 693 | ?> |
||
| 694 | <li><a target="_blank" |
||
| 695 | href="<?php echo esc_url( $api->homepage ); ?>"><?php _e( 'Plugin Homepage »' ); ?></a> |
||
| 696 | </li> |
||
| 697 | <?php |
||
| 698 | } |
||
| 699 | if ( ! empty( $api->donate_link ) && empty( $api->contributors ) ) { |
||
| 700 | ?> |
||
| 701 | <li><a target="_blank" |
||
| 702 | href="<?php echo esc_url( $api->donate_link ); ?>"><?php _e( 'Donate to this plugin »' ); ?></a> |
||
| 703 | </li> |
||
| 704 | <?php } ?> |
||
| 705 | </ul> |
||
| 706 | </div> |
||
| 707 | <?php if ( ! empty( $api->rating ) ) { ?> |
||
| 708 | <h3><?php _e( 'Average Rating' ); ?></h3> |
||
| 709 | <?php wp_star_rating( array( |
||
| 710 | 'rating' => $api->rating, |
||
| 711 | 'type' => 'percent', |
||
| 712 | 'number' => $api->num_ratings |
||
| 713 | ) ); ?> |
||
| 714 | <small><?php printf( _n( '(based on %s rating)', '(based on %s ratings)', $api->num_ratings ), number_format_i18n( $api->num_ratings ) ); ?></small> |
||
| 715 | <?php |
||
| 716 | } |
||
| 717 | |||
| 718 | if ( ! empty( $api->ratings ) && array_sum( (array) $api->ratings ) > 0 ) { |
||
| 719 | foreach ( $api->ratings as $key => $ratecount ) { |
||
| 720 | // Avoid div-by-zero. |
||
| 721 | $_rating = $api->num_ratings ? ( $ratecount / $api->num_ratings ) : 0; |
||
| 722 | ?> |
||
| 723 | <div class="counter-container"> |
||
| 724 | <span class="counter-label"><a |
||
| 725 | href="https://wordpress.org/support/view/plugin-reviews/<?php echo $api->slug; ?>?filter=<?php echo $key; ?>" |
||
| 726 | target="_blank" |
||
| 727 | title="<?php echo esc_attr( sprintf( _n( 'Click to see reviews that provided a rating of %d star', 'Click to see reviews that provided a rating of %d stars', $key ), $key ) ); ?>"><?php printf( _n( '%d star', '%d stars', $key ), $key ); ?></a></span> |
||
| 728 | <span class="counter-back"> |
||
| 729 | <span class="counter-bar" style="width: <?php echo 92 * $_rating; ?>px;"></span> |
||
| 730 | </span> |
||
| 731 | <span class="counter-count"><?php echo number_format_i18n( $ratecount ); ?></span> |
||
| 732 | </div> |
||
| 733 | <?php |
||
| 734 | } |
||
| 735 | } |
||
| 736 | if ( ! empty( $api->contributors ) ) { |
||
| 737 | ?> |
||
| 738 | <h3><?php _e( 'Contributors' ); ?></h3> |
||
| 739 | <ul class="contributors"> |
||
| 740 | <?php |
||
| 741 | foreach ( (array) $api->contributors as $contrib_username => $contrib_profile ) { |
||
| 742 | if ( empty( $contrib_username ) && empty( $contrib_profile ) ) { |
||
| 743 | continue; |
||
| 744 | } |
||
| 745 | if ( empty( $contrib_username ) ) { |
||
| 746 | $contrib_username = preg_replace( '/^.+\/(.+)\/?$/', '\1', $contrib_profile ); |
||
| 747 | } |
||
| 748 | $contrib_username = sanitize_user( $contrib_username ); |
||
| 749 | if ( empty( $contrib_profile ) ) { |
||
| 750 | echo "<li><img src='https://wordpress.org/grav-redirect.php?user={$contrib_username}&s=36' width='18' height='18' />{$contrib_username}</li>"; |
||
| 751 | } else { |
||
| 752 | echo "<li><a href='{$contrib_profile}' target='_blank'><img src='https://wordpress.org/grav-redirect.php?user={$contrib_username}&s=36' width='18' height='18' />{$contrib_username}</a></li>"; |
||
| 753 | } |
||
| 754 | } |
||
| 755 | ?> |
||
| 756 | </ul> |
||
| 757 | <?php if ( ! empty( $api->donate_link ) ) { ?> |
||
| 758 | <a target="_blank" |
||
| 759 | href="<?php echo esc_url( $api->donate_link ); ?>"><?php _e( 'Donate to this plugin »' ); ?></a> |
||
| 760 | <?php } ?> |
||
| 761 | <?php } ?> |
||
| 762 | </div> |
||
| 763 | <div id="section-holder" class="wrap"> |
||
| 764 | <?php |
||
| 765 | if ( ! empty( $api->tested ) && version_compare( substr( $GLOBALS['wp_version'], 0, strlen( $api->tested ) ), $api->tested, '>' ) ) { |
||
| 766 | echo '<div class="notice notice-warning"><p>' . '<strong>' . __( 'Warning:' ) . '</strong> ' . __( 'This plugin has not been tested with your current version of WordPress.' ) . '</p></div>'; |
||
| 767 | } else if ( ! empty( $api->requires ) && version_compare( substr( $GLOBALS['wp_version'], 0, strlen( $api->requires ) ), $api->requires, '<' ) ) { |
||
| 768 | echo '<div class="notice notice-warning"><p>' . '<strong>' . __( 'Warning:' ) . '</strong> ' . __( 'This plugin has not been marked as compatible with your version of WordPress.' ) . '</p></div>'; |
||
| 769 | } |
||
| 770 | |||
| 771 | foreach ( (array) $api->sections as $section_name => $content ) { |
||
| 772 | $content = links_add_base_url( $content, 'https://wordpress.org/plugins/' . $api->slug . '/' ); |
||
| 773 | $content = links_add_target( $content, '_blank' ); |
||
| 774 | |||
| 775 | $san_section = esc_attr( $section_name ); |
||
| 776 | |||
| 777 | $display = ( $section_name === $section ) ? 'block' : 'none'; |
||
| 778 | |||
| 779 | if ( 'description' === $section_name && |
||
| 780 | ( ( ! $api->external && $api->wp_org_missing ) || |
||
| 781 | ( $api->external && $api->fs_missing ) ) |
||
| 782 | ) { |
||
| 783 | $missing_notice = array( |
||
| 784 | 'type' => 'error', |
||
| 785 | 'id' => md5( microtime() ), |
||
| 786 | 'message' => __fs( ($api->is_paid ? 'paid-addon-not-deployed' : 'free-addon-not-deployed'), $api->slug ), |
||
| 787 | ); |
||
| 788 | fs_require_template( 'admin-notice.php', $missing_notice ); |
||
| 789 | } |
||
| 790 | echo "\t<div id='section-{$san_section}' class='section' style='display: {$display};'>\n"; |
||
| 791 | echo $content; |
||
| 792 | echo "\t</div>\n"; |
||
| 793 | } |
||
| 794 | echo "</div>\n"; |
||
| 795 | echo "</div>\n"; |
||
| 796 | echo "</div>\n"; // #plugin-information-scrollable |
||
| 797 | echo "<div id='$tab-footer'>\n"; |
||
| 798 | |||
| 799 | echo $this->get_plugin_cta( $api ); |
||
| 800 | |||
| 801 | echo "</div>\n"; |
||
| 802 | |||
| 803 | iframe_footer(); |
||
| 804 | exit; |
||
| 805 | } |
||
| 806 | } |
||
| 807 |
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.