Conditions | 83 |
Paths | > 20000 |
Total Lines | 604 |
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 |
||
539 | function install_plugin_information() { |
||
540 | global $tab; |
||
541 | |||
542 | if ( empty( $_REQUEST['plugin'] ) ) { |
||
543 | return; |
||
544 | } |
||
545 | |||
546 | $args = array( |
||
547 | 'slug' => wp_unslash( $_REQUEST['plugin'] ), |
||
548 | 'is_ssl' => is_ssl(), |
||
549 | 'fields' => array( |
||
550 | 'banners' => true, |
||
551 | 'reviews' => true, |
||
552 | 'downloaded' => false, |
||
553 | 'active_installs' => true |
||
554 | ) |
||
555 | ); |
||
556 | |||
557 | if ( is_array( $args ) ) { |
||
558 | $args = (object) $args; |
||
559 | } |
||
560 | |||
561 | if ( ! isset( $args->per_page ) ) { |
||
562 | $args->per_page = 24; |
||
563 | } |
||
564 | |||
565 | if ( ! isset( $args->locale ) ) { |
||
566 | $args->locale = get_locale(); |
||
567 | } |
||
568 | |||
569 | $api = apply_filters( 'fs_plugins_api', false, 'plugin_information', $args ); |
||
570 | |||
571 | if ( is_wp_error( $api ) ) { |
||
572 | wp_die( $api ); |
||
573 | } |
||
574 | |||
575 | $plugins_allowedtags = array( |
||
576 | 'a' => array( |
||
577 | 'href' => array(), |
||
578 | 'title' => array(), |
||
579 | 'target' => array(), |
||
580 | // Add image style for screenshots. |
||
581 | 'class' => array() |
||
582 | ), |
||
583 | 'style' => array(), |
||
584 | 'abbr' => array( 'title' => array() ), |
||
585 | 'acronym' => array( 'title' => array() ), |
||
586 | 'code' => array(), |
||
587 | 'pre' => array(), |
||
588 | 'em' => array(), |
||
589 | 'strong' => array(), |
||
590 | 'div' => array( 'class' => array() ), |
||
591 | 'span' => array( 'class' => array() ), |
||
592 | 'p' => array(), |
||
593 | 'ul' => array(), |
||
594 | 'ol' => array(), |
||
595 | 'li' => array( 'class' => array() ), |
||
596 | 'i' => array( 'class' => array() ), |
||
597 | 'h1' => array(), |
||
598 | 'h2' => array(), |
||
599 | 'h3' => array(), |
||
600 | 'h4' => array(), |
||
601 | 'h5' => array(), |
||
602 | 'h6' => array(), |
||
603 | 'img' => array( 'src' => array(), 'class' => array(), 'alt' => array() ), |
||
604 | // 'table' => array(), |
||
605 | // 'td' => array(), |
||
606 | // 'tr' => array(), |
||
607 | // 'th' => array(), |
||
608 | // 'thead' => array(), |
||
609 | // 'tbody' => array(), |
||
610 | ); |
||
611 | |||
612 | $plugins_section_titles = array( |
||
613 | 'description' => fs_text_x_inline( 'Description', 'Plugin installer section title', 'description', $api->slug ), |
||
614 | 'installation' => fs_text_x_inline( 'Installation', 'Plugin installer section title', 'installation', $api->slug ), |
||
615 | 'faq' => fs_text_x_inline( 'FAQ', 'Plugin installer section title', 'faq', $api->slug ), |
||
616 | 'screenshots' => fs_text_inline( 'Screenshots', 'screenshots', $api->slug ), |
||
617 | 'changelog' => fs_text_x_inline( 'Changelog', 'Plugin installer section title', 'changelog', $api->slug ), |
||
618 | 'reviews' => fs_text_x_inline( 'Reviews', 'Plugin installer section title', 'reviews', $api->slug ), |
||
619 | 'other_notes' => fs_text_x_inline( 'Other Notes', 'Plugin installer section title', 'other-notes', $api->slug ), |
||
620 | ); |
||
621 | |||
622 | // Sanitize HTML |
||
623 | // foreach ( (array) $api->sections as $section_name => $content ) { |
||
624 | // $api->sections[$section_name] = wp_kses( $content, $plugins_allowedtags ); |
||
625 | // } |
||
626 | |||
627 | foreach ( array( 'version', 'author', 'requires', 'tested', 'homepage', 'downloaded', 'slug' ) as $key ) { |
||
628 | if ( isset( $api->$key ) ) { |
||
629 | $api->$key = wp_kses( $api->$key, $plugins_allowedtags ); |
||
630 | } |
||
631 | } |
||
632 | |||
633 | // Add after $api->slug is ready. |
||
634 | $plugins_section_titles['features'] = fs_text_x_inline( 'Features & Pricing', 'Plugin installer section title', 'features-and-pricing', $api->slug ); |
||
635 | |||
636 | $_tab = esc_attr( $tab ); |
||
637 | |||
638 | $section = isset( $_REQUEST['section'] ) ? wp_unslash( $_REQUEST['section'] ) : 'description'; // Default to the Description tab, Do not translate, API returns English. |
||
639 | if ( empty( $section ) || ! isset( $api->sections[ $section ] ) ) { |
||
640 | $section_titles = array_keys( (array) $api->sections ); |
||
641 | $section = array_shift( $section_titles ); |
||
642 | } |
||
643 | |||
644 | iframe_header( fs_text_inline( 'Plugin Install', 'plugin-install', $api->slug ) ); |
||
645 | |||
646 | $_with_banner = ''; |
||
647 | |||
648 | // var_dump($api->banners); |
||
649 | if ( ! empty( $api->banners ) && ( ! empty( $api->banners['low'] ) || ! empty( $api->banners['high'] ) ) ) { |
||
650 | $_with_banner = 'with-banner'; |
||
651 | $low = empty( $api->banners['low'] ) ? $api->banners['high'] : $api->banners['low']; |
||
652 | $high = empty( $api->banners['high'] ) ? $api->banners['low'] : $api->banners['high']; |
||
653 | ?> |
||
654 | <style type="text/css"> |
||
655 | #plugin-information-title.with-banner |
||
656 | { |
||
657 | background-image: url( <?php echo esc_url( $low ); ?> ); |
||
658 | } |
||
659 | |||
660 | @media only screen and ( -webkit-min-device-pixel-ratio: 1.5 ) |
||
661 | { |
||
662 | #plugin-information-title.with-banner |
||
663 | { |
||
664 | background-image: url( <?php echo esc_url( $high ); ?> ); |
||
665 | } |
||
666 | } |
||
667 | </style> |
||
668 | <?php |
||
669 | } |
||
670 | |||
671 | echo '<div id="plugin-information-scrollable">'; |
||
672 | echo "<div id='{$_tab}-title' class='{$_with_banner}'><div class='vignette'></div><h2>{$api->name}</h2></div>"; |
||
673 | echo "<div id='{$_tab}-tabs' class='{$_with_banner}'>\n"; |
||
674 | |||
675 | foreach ( (array) $api->sections as $section_name => $content ) { |
||
676 | if ( 'reviews' === $section_name && ( empty( $api->ratings ) || 0 === array_sum( (array) $api->ratings ) ) ) { |
||
677 | continue; |
||
678 | } |
||
679 | |||
680 | if ( isset( $plugins_section_titles[ $section_name ] ) ) { |
||
681 | $title = $plugins_section_titles[ $section_name ]; |
||
682 | } else { |
||
683 | $title = ucwords( str_replace( '_', ' ', $section_name ) ); |
||
684 | } |
||
685 | |||
686 | $class = ( $section_name === $section ) ? ' class="current"' : ''; |
||
687 | $href = add_query_arg( array( 'tab' => $tab, 'section' => $section_name ) ); |
||
688 | $href = esc_url( $href ); |
||
689 | $san_section = esc_attr( $section_name ); |
||
690 | echo "\t<a name='$san_section' href='$href' $class>$title</a>\n"; |
||
691 | } |
||
692 | |||
693 | echo "</div>\n"; |
||
694 | |||
695 | ?> |
||
696 | <div id="<?php echo $_tab; ?>-content" class='<?php echo $_with_banner; ?>'> |
||
697 | <div class="fyi"> |
||
698 | <?php if ( $api->is_paid ) : ?> |
||
699 | <?php if ( isset( $api->plans ) ) : ?> |
||
700 | <div class="plugin-information-pricing"> |
||
701 | <?php foreach ( $api->plans as $plan ) : ?> |
||
702 | <?php |
||
703 | if ( empty( $plan->pricing ) ) { |
||
704 | continue; |
||
705 | } |
||
706 | |||
707 | /** |
||
708 | * @var FS_Plugin_Plan $plan |
||
709 | */ |
||
710 | ?> |
||
711 | <?php $first_pricing = $plan->pricing[0] ?> |
||
712 | <?php $is_multi_cycle = $first_pricing->is_multi_cycle() ?> |
||
713 | <div class="fs-plan<?php if ( ! $is_multi_cycle ) { |
||
714 | echo ' fs-single-cycle'; |
||
715 | } ?>" data-plan-id="<?php echo $plan->id ?>"> |
||
716 | <h3 data-plan="<?php echo $plan->id ?>"><?php echo esc_html( sprintf( fs_text_x_inline( '%s Plan', 'e.g. Professional Plan', 'x-plan', $api->slug ), $plan->title ) ) ?></h3> |
||
717 | <?php $has_annual = $first_pricing->has_annual() ?> |
||
718 | <?php $has_monthly = $first_pricing->has_monthly() ?> |
||
719 | <div class="nav-tab-wrapper"> |
||
720 | <?php $billing_cycles = array( 'monthly', 'annual', 'lifetime' ) ?> |
||
721 | <?php $i = 0; |
||
722 | foreach ( $billing_cycles as $cycle ) : ?> |
||
723 | <?php $prop = "{$cycle}_price"; |
||
724 | if ( isset( $first_pricing->{$prop} ) ) : ?> |
||
725 | <?php $is_featured = ( 'annual' === $cycle && $is_multi_cycle ) ?> |
||
726 | <?php |
||
727 | $prices = array(); |
||
728 | foreach ( $plan->pricing as $pricing ) { |
||
729 | if ( isset( $pricing->{$prop} ) ) { |
||
730 | $prices[] = array( |
||
731 | 'id' => $pricing->id, |
||
732 | 'licenses' => $pricing->licenses, |
||
733 | 'price' => $pricing->{$prop} |
||
734 | ); |
||
735 | } |
||
736 | } |
||
737 | ?> |
||
738 | <a class="nav-tab" data-billing-cycle="<?php echo $cycle ?>" |
||
739 | data-pricing="<?php echo esc_attr( json_encode( $prices ) ) ?>"> |
||
740 | <?php if ( $is_featured ) : ?> |
||
741 | <label> |
||
742 | ★ <?php fs_esc_html_echo_x_inline( 'Best', 'e.g. the best product', 'best', $api->slug ) ?> |
||
743 | ★</label> |
||
744 | <?php endif ?> |
||
745 | <?php |
||
746 | switch ( $cycle ) { |
||
747 | case 'monthly': |
||
748 | fs_esc_html_echo_x_inline( 'Monthly', 'as every month', 'monthly', $api->slug ); |
||
749 | break; |
||
750 | case 'annual': |
||
751 | fs_esc_html_echo_x_inline( 'Annual', 'as once a year', 'annual', $api->slug ); |
||
752 | break; |
||
753 | case 'lifetime': |
||
754 | fs_esc_html_echo_inline( 'Lifetime', 'lifetime', $api->slug ); |
||
755 | break; |
||
756 | } |
||
757 | ?> |
||
758 | </a> |
||
759 | <?php endif ?> |
||
760 | <?php $i ++; endforeach ?> |
||
761 | <?php wp_enqueue_script( 'jquery' ) ?> |
||
762 | <script type="text/javascript"> |
||
763 | (function ($, undef) { |
||
764 | var |
||
765 | _formatBillingFrequency = function (cycle) { |
||
766 | switch (cycle) { |
||
767 | case 'monthly': |
||
768 | return '<?php printf( fs_text_x_inline( 'Billed %s', 'e.g. billed monthly', 'billed-x', $api->slug ), fs_text_x_inline( 'Monthly', 'as every month', 'monthly', $api->slug ) ) ?>'; |
||
769 | case 'annual': |
||
770 | return '<?php printf( fs_text_x_inline( 'Billed %s', 'e.g. billed monthly', 'billed-x', $api->slug ), fs_text_x_inline( 'Annually', 'as once a year', 'annually', $api->slug ) ) ?>'; |
||
771 | case 'lifetime': |
||
772 | return '<?php printf( fs_text_x_inline( 'Billed %s', 'e.g. billed monthly', 'billed-x', $api->slug ), fs_text_x_inline( 'Once', 'as once a year', 'once', $api->slug ) ) ?>'; |
||
773 | } |
||
774 | }, |
||
775 | _formatLicensesTitle = function (pricing) { |
||
776 | switch (pricing.licenses) { |
||
777 | case 1: |
||
778 | return '<?php fs_esc_attr_echo_inline( 'Single Site License', 'license-single-site', $api->slug ) ?>'; |
||
779 | case null: |
||
780 | return '<?php fs_esc_attr_echo_inline( 'Unlimited Licenses', 'license-unlimited', $api->slug ) ?>'; |
||
781 | default: |
||
782 | return '<?php fs_esc_attr_echo_inline( 'Up to %s Sites', 'license-x-sites', $api->slug ) ?>'.replace('%s', pricing.licenses); |
||
783 | } |
||
784 | }, |
||
785 | _formatPrice = function (pricing, cycle, multipleLicenses) { |
||
786 | if (undef === multipleLicenses) |
||
787 | multipleLicenses = true; |
||
788 | |||
789 | var priceCycle; |
||
790 | switch (cycle) { |
||
791 | case 'monthly': |
||
792 | priceCycle = ' / <?php fs_echo_x_inline( 'mo', 'as monthly period', 'mo', $api->slug ) ?>'; |
||
793 | break; |
||
794 | case 'lifetime': |
||
795 | priceCycle = ''; |
||
796 | break; |
||
797 | case 'annual': |
||
798 | default: |
||
799 | priceCycle = ' / <?php fs_echo_x_inline( 'year', 'as annual period', 'year', $api->slug ) ?>'; |
||
800 | break; |
||
801 | } |
||
802 | |||
803 | if (!multipleLicenses && 1 == pricing.licenses) { |
||
804 | return '$' + pricing.price + priceCycle; |
||
805 | } |
||
806 | |||
807 | return _formatLicensesTitle(pricing) + ' - <var class="fs-price">$' + pricing.price + priceCycle + '</var>'; |
||
808 | }, |
||
809 | _checkoutUrl = function (plan, pricing, cycle) { |
||
810 | return '<?php echo esc_url_raw( remove_query_arg( 'billing_cycle', add_query_arg( array( 'plugin_id' => $plan->plugin_id ), $api->checkout_link ) ) ) ?>' + |
||
811 | '&plan_id=' + plan + |
||
812 | '&pricing_id=' + pricing + |
||
813 | '&billing_cycle=' + cycle<?php if ( $plan->has_trial() ) { |
||
814 | echo " + '&trial=true'"; |
||
815 | }?>; |
||
816 | }, |
||
817 | _updateCtaUrl = function (plan, pricing, cycle) { |
||
818 | $('.plugin-information-pricing .button, #plugin-information-footer .button.fs-checkout-button').attr('href', _checkoutUrl(plan, pricing, cycle)); |
||
819 | }; |
||
820 | |||
821 | $(document).ready(function () { |
||
822 | var $plan = $('.plugin-information-pricing .fs-plan[data-plan-id=<?php echo $plan->id ?>]'); |
||
823 | $plan.find('input[type=radio]').live('click', function () { |
||
824 | _updateCtaUrl( |
||
825 | $plan.attr('data-plan-id'), |
||
826 | $(this).val(), |
||
827 | $plan.find('.nav-tab-active').attr('data-billing-cycle') |
||
828 | ); |
||
829 | |||
830 | $plan.find('.fs-trial-terms .fs-price').html( |
||
831 | $(this).parents('label').find('.fs-price').html() |
||
832 | ); |
||
833 | }); |
||
834 | |||
835 | $plan.find('.nav-tab').click(function () { |
||
836 | if ($(this).hasClass('nav-tab-active')) |
||
837 | return; |
||
838 | |||
839 | var $this = $(this), |
||
840 | billingCycle = $this.attr('data-billing-cycle'), |
||
841 | pricing = JSON.parse($this.attr('data-pricing')), |
||
842 | $pricesList = $this.parents('.fs-plan').find('.fs-pricing-body .fs-licenses'), |
||
843 | html = ''; |
||
844 | |||
845 | // Un-select previously selected tab. |
||
846 | $plan.find('.nav-tab').removeClass('nav-tab-active'); |
||
847 | |||
848 | // Select current tab. |
||
849 | $this.addClass('nav-tab-active'); |
||
850 | |||
851 | // Render licenses prices. |
||
852 | if (1 == pricing.length) { |
||
853 | html = '<li><label><?php echo fs_esc_attr_x_inline( 'Price', 'noun', 'price', $api->slug ) ?>: ' + _formatPrice(pricing[0], billingCycle, false) + '</label></li>'; |
||
854 | } else { |
||
855 | for (var i = 0; i < pricing.length; i++) { |
||
856 | html += '<li><label><input name="pricing-<?php echo $plan->id ?>" type="radio" value="' + pricing[i].id + '">' + _formatPrice(pricing[i], billingCycle) + '</label></li>'; |
||
857 | } |
||
858 | } |
||
859 | $pricesList.html(html); |
||
860 | |||
861 | if (1 < pricing.length) { |
||
862 | // Select first license option. |
||
863 | $pricesList.find('li:first input').click(); |
||
864 | } |
||
865 | else { |
||
866 | _updateCtaUrl( |
||
867 | $plan.attr('data-plan-id'), |
||
868 | pricing[0].id, |
||
869 | billingCycle |
||
870 | ); |
||
871 | } |
||
872 | |||
873 | // Update billing frequency. |
||
874 | $plan.find('.fs-billing-frequency').html(_formatBillingFrequency(billingCycle)); |
||
875 | |||
876 | if ('annual' === billingCycle) { |
||
877 | $plan.find('.fs-annual-discount').show(); |
||
878 | } else { |
||
879 | $plan.find('.fs-annual-discount').hide(); |
||
880 | } |
||
881 | }); |
||
882 | |||
883 | <?php if ( $has_annual ) : ?> |
||
884 | // Select annual by default. |
||
885 | $plan.find('.nav-tab[data-billing-cycle=annual]').click(); |
||
886 | <?php else : ?> |
||
887 | // Select first tab. |
||
888 | $plan.find('.nav-tab:first').click(); |
||
889 | <?php endif ?> |
||
890 | }); |
||
891 | }(jQuery)); |
||
892 | </script> |
||
893 | </div> |
||
894 | <div class="fs-pricing-body"> |
||
895 | <span class="fs-billing-frequency"></span> |
||
896 | <?php $annual_discount = ( $has_annual && $has_monthly ) ? $plan->pricing[0]->annual_discount_percentage() : 0 ?> |
||
897 | <?php if ( $annual_discount > 0 ) : ?> |
||
898 | <span |
||
899 | class="fs-annual-discount"><?php printf( |
||
900 | /* translators: %s: Discount (e.g. discount of $5 or 10%) */ |
||
901 | fs_esc_html_inline( 'Save %s', 'save-x', $api->slug ), $annual_discount . '%' ) ?></span> |
||
902 | <?php endif ?> |
||
903 | <ul class="fs-licenses"> |
||
904 | </ul> |
||
905 | <?php echo $this->get_checkout_cta( $api, $plan, false ) ?> |
||
906 | <div style="clear:both"></div> |
||
907 | <?php if ( $plan->has_trial() ) : ?> |
||
908 | <?php $trial_period = $this->get_trial_period( $plan ) ?> |
||
909 | <ul class="fs-trial-terms"> |
||
910 | <li> |
||
911 | <i class="dashicons dashicons-yes"></i><?php echo esc_html( sprintf( fs_text_inline( 'No commitment for %s - cancel anytime', 'no-commitment-x', $api->slug ), $trial_period ) ) ?> |
||
912 | </li> |
||
913 | <li> |
||
914 | <i class="dashicons dashicons-yes"></i><?php printf( esc_html( fs_text_inline( 'After your free %s, pay as little as %s', 'after-x-pay-as-little-y', $api->slug ) ), $trial_period, '<var class="fs-price">' . $this->get_price_tag( $plan, $plan->pricing[0] ) . '</var>' ) ?> |
||
915 | </li> |
||
916 | </ul> |
||
917 | <?php endif ?> |
||
918 | </div> |
||
919 | </div> |
||
920 | </div> |
||
921 | <?php endforeach ?> |
||
922 | <?php endif ?> |
||
923 | <?php endif ?> |
||
924 | <div> |
||
925 | <h3><?php fs_echo_inline( 'Details', 'details', $api->slug ) ?></h3> |
||
926 | <ul> |
||
927 | <?php if ( ! empty( $api->version ) ) { ?> |
||
928 | <li> |
||
929 | <strong><?php fs_esc_html_echo_x_inline( 'Version', 'product version', 'version', $api->slug ); ?> |
||
930 | :</strong> <?php echo $api->version; ?></li> |
||
931 | <?php |
||
932 | } |
||
933 | if ( ! empty( $api->author ) ) { |
||
934 | ?> |
||
935 | <li> |
||
936 | <strong><?php fs_echo_x_inline( 'Author', 'as the plugin author', 'author', $api->slug ); ?> |
||
937 | :</strong> <?php echo links_add_target( $api->author, '_blank' ); ?> |
||
938 | </li> |
||
939 | <?php |
||
940 | } |
||
941 | if ( ! empty( $api->last_updated ) ) { |
||
942 | ?> |
||
943 | <li><strong><?php fs_echo_inline( 'Last Updated', 'last-updated', $api->slug ); ?> |
||
944 | :</strong> <span |
||
945 | title="<?php echo $api->last_updated; ?>"> |
||
946 | <?php echo esc_html( sprintf( |
||
947 | /* translators: %s: time period (e.g. "2 hours" ago) */ |
||
948 | fs_text_x_inline( '%s ago', 'x-ago', $api->slug ), |
||
949 | human_time_diff( strtotime( $api->last_updated ) ) |
||
950 | ) ) ?> |
||
951 | </span></li> |
||
952 | <?php |
||
953 | } |
||
954 | if ( ! empty( $api->requires ) ) { |
||
955 | ?> |
||
956 | <li> |
||
957 | <strong><?php fs_esc_html_echo_inline( 'Requires WordPress Version', 'requires-wordpress-version', $api->slug ) ?> |
||
958 | :</strong> <?php echo esc_html( sprintf( fs_text_inline( '%s or higher', 'x-or-higher', $api->slug ), $api->requires ) ) ?> |
||
959 | </li> |
||
960 | <?php |
||
961 | } |
||
962 | if ( ! empty( $api->tested ) ) { |
||
963 | ?> |
||
964 | <li> |
||
965 | <strong><?php fs_esc_html_echo_inline( 'Compatible up to', 'compatible-up-to', $api->slug ); ?> |
||
966 | :</strong> <?php echo $api->tested; ?> |
||
967 | </li> |
||
968 | <?php |
||
969 | } |
||
970 | if ( ! empty( $api->downloaded ) ) { |
||
971 | ?> |
||
972 | <li> |
||
973 | <strong><?php fs_esc_html_echo_inline( 'Downloaded', 'downloaded', $api->slug ) ?> |
||
974 | :</strong> <?php echo esc_html( sprintf( |
||
975 | ( ( 1 == $api->downloaded ) ? |
||
976 | /* translators: %s: 1 or One (Number of times downloaded) */ |
||
977 | fs_text_inline( '%s time', 'x-time', $api->slug ) : |
||
978 | /* translators: %s: Number of times downloaded */ |
||
979 | fs_text_inline( '%s times', 'x-times', $api->slug ) |
||
980 | ), |
||
981 | number_format_i18n( $api->downloaded ) |
||
982 | ) ); ?> |
||
983 | </li> |
||
984 | <?php |
||
985 | } |
||
986 | if ( ! empty( $api->slug ) && true == $api->is_wp_org_compliant ) { |
||
987 | ?> |
||
988 | <li><a target="_blank" |
||
989 | href="https://wordpress.org/plugins/<?php echo $api->slug; ?>/"><?php fs_esc_html_echo_inline( 'WordPress.org Plugin Page', 'wp-org-plugin-page', $api->slug ) ?> |
||
990 | »</a> |
||
991 | </li> |
||
992 | <?php |
||
993 | } |
||
994 | if ( ! empty( $api->homepage ) ) { |
||
995 | ?> |
||
996 | <li><a target="_blank" |
||
997 | href="<?php echo esc_url( $api->homepage ); ?>"><?php fs_esc_html_echo_inline( 'Plugin Homepage', 'plugin-homepage', $api->slug ) ?> |
||
998 | »</a> |
||
999 | </li> |
||
1000 | <?php |
||
1001 | } |
||
1002 | if ( ! empty( $api->donate_link ) && empty( $api->contributors ) ) { |
||
1003 | ?> |
||
1004 | <li><a target="_blank" |
||
1005 | href="<?php echo esc_url( $api->donate_link ); ?>"><?php fs_esc_html_echo_inline( 'Donate to this plugin', 'donate-to-plugin', $api->slug ) ?> |
||
1006 | »</a> |
||
1007 | </li> |
||
1008 | <?php } ?> |
||
1009 | </ul> |
||
1010 | </div> |
||
1011 | <?php if ( ! empty( $api->rating ) ) { ?> |
||
1012 | <h3><?php fs_echo_inline( 'Average Rating', 'average-rating', $api->slug ); ?></h3> |
||
1013 | <?php wp_star_rating( array( |
||
1014 | 'rating' => $api->rating, |
||
1015 | 'type' => 'percent', |
||
1016 | 'number' => $api->num_ratings |
||
1017 | ) ); ?> |
||
1018 | <small>(<?php echo esc_html( sprintf( |
||
1019 | fs_text_inline( 'based on %s', 'based-on-x', $api->slug ), |
||
1020 | sprintf( |
||
1021 | ( ( 1 == $api->num_ratings ) ? |
||
1022 | /* translators: %s: 1 or One */ |
||
1023 | fs_text_inline( '%s rating', 'x-rating', $api->slug ) : |
||
1024 | /* translators: %s: Number larger than 1 */ |
||
1025 | fs_text_inline( '%s ratings', 'x-ratings', $api->slug ) |
||
1026 | ), |
||
1027 | number_format_i18n( $api->num_ratings ) |
||
1028 | ) ) ) ?>) |
||
1029 | </small> |
||
1030 | <?php |
||
1031 | } |
||
1032 | |||
1033 | if ( ! empty( $api->ratings ) && array_sum( (array) $api->ratings ) > 0 ) { |
||
1034 | foreach ( $api->ratings as $key => $ratecount ) { |
||
1035 | // Avoid div-by-zero. |
||
1036 | $_rating = $api->num_ratings ? ( $ratecount / $api->num_ratings ) : 0; |
||
1037 | $stars_label = sprintf( |
||
1038 | ( ( 1 == $key ) ? |
||
1039 | /* translators: %s: 1 or One */ |
||
1040 | fs_text_inline( '%s star', 'x-star', $api->slug ) : |
||
1041 | /* translators: %s: Number larger than 1 */ |
||
1042 | fs_text_inline( '%s stars', 'x-stars', $api->slug ) |
||
1043 | ), |
||
1044 | number_format_i18n( $key ) |
||
1045 | ); |
||
1046 | ?> |
||
1047 | <div class="counter-container"> |
||
1048 | <span class="counter-label"><a |
||
1049 | href="https://wordpress.org/support/view/plugin-reviews/<?php echo $api->slug; ?>?filter=<?php echo $key; ?>" |
||
1050 | target="_blank" |
||
1051 | title="<?php echo esc_attr( sprintf( |
||
1052 | /* translators: %s: # of stars (e.g. 5 stars) */ |
||
1053 | fs_text_inline( 'Click to see reviews that provided a rating of %s', 'click-to-reviews', $api->slug ), |
||
1054 | $stars_label |
||
1055 | ) ) ?>"><?php echo $stars_label ?></a></span> |
||
1056 | <span class="counter-back"> |
||
1057 | <span class="counter-bar" style="width: <?php echo 92 * $_rating; ?>px;"></span> |
||
1058 | </span> |
||
1059 | <span class="counter-count"><?php echo number_format_i18n( $ratecount ); ?></span> |
||
1060 | </div> |
||
1061 | <?php |
||
1062 | } |
||
1063 | } |
||
1064 | if ( ! empty( $api->contributors ) ) { |
||
1065 | ?> |
||
1066 | <h3><?php fs_echo_inline( 'Contributors', 'contributors', $api->slug ); ?></h3> |
||
1067 | <ul class="contributors"> |
||
1068 | <?php |
||
1069 | foreach ( (array) $api->contributors as $contrib_username => $contrib_profile ) { |
||
1070 | if ( empty( $contrib_username ) && empty( $contrib_profile ) ) { |
||
1071 | continue; |
||
1072 | } |
||
1073 | if ( empty( $contrib_username ) ) { |
||
1074 | $contrib_username = preg_replace( '/^.+\/(.+)\/?$/', '\1', $contrib_profile ); |
||
1075 | } |
||
1076 | $contrib_username = sanitize_user( $contrib_username ); |
||
1077 | if ( empty( $contrib_profile ) ) { |
||
1078 | echo "<li><img src='https://wordpress.org/grav-redirect.php?user={$contrib_username}&s=36' width='18' height='18' />{$contrib_username}</li>"; |
||
1079 | } else { |
||
1080 | 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>"; |
||
1081 | } |
||
1082 | } |
||
1083 | ?> |
||
1084 | </ul> |
||
1085 | <?php if ( ! empty( $api->donate_link ) ) { ?> |
||
1086 | <a target="_blank" |
||
1087 | href="<?php echo esc_url( $api->donate_link ); ?>"><?php fs_echo_inline( 'Donate to this plugin', 'donate-to-plugin', $api->slug ) ?> |
||
1088 | »</a> |
||
1089 | <?php } ?> |
||
1090 | <?php } ?> |
||
1091 | </div> |
||
1092 | <div id="section-holder" class="wrap"> |
||
1093 | <?php |
||
1094 | if ( ! empty( $api->tested ) && version_compare( substr( $GLOBALS['wp_version'], 0, strlen( $api->tested ) ), $api->tested, '>' ) ) { |
||
1095 | echo '<div class="notice notice-warning"><p>' . '<strong>' . fs_text_inline( 'Warning', 'warning', $api->slug ) . ':</strong> ' . fs_text_inline( 'This plugin has not been tested with your current version of WordPress.', 'not-tested-warning', $api->slug ) . '</p></div>'; |
||
1096 | } else if ( ! empty( $api->requires ) && version_compare( substr( $GLOBALS['wp_version'], 0, strlen( $api->requires ) ), $api->requires, '<' ) ) { |
||
1097 | echo '<div class="notice notice-warning"><p>' . '<strong>' . fs_text_inline( 'Warning', 'warning', $api->slug ) . ':</strong> ' . fs_text_inline( 'This plugin has not been marked as compatible with your version of WordPress.', 'not-compatible-warning', $api->slug ) . '</p></div>'; |
||
1098 | } |
||
1099 | |||
1100 | foreach ( (array) $api->sections as $section_name => $content ) { |
||
1101 | $content = links_add_base_url( $content, 'https://wordpress.org/plugins/' . $api->slug . '/' ); |
||
1102 | $content = links_add_target( $content, '_blank' ); |
||
1103 | |||
1104 | $san_section = esc_attr( $section_name ); |
||
1105 | |||
1106 | $display = ( $section_name === $section ) ? 'block' : 'none'; |
||
1107 | |||
1108 | if ( 'description' === $section_name && |
||
1109 | ( ( $api->is_wp_org_compliant && $api->wp_org_missing ) || |
||
1110 | ( ! $api->is_wp_org_compliant && $api->fs_missing ) ) |
||
1111 | ) { |
||
1112 | $missing_notice = array( |
||
1113 | 'type' => 'error', |
||
1114 | 'id' => md5( microtime() ), |
||
1115 | 'message' => $api->is_paid ? |
||
1116 | fs_text_inline( 'Paid add-on must be deployed to Freemius.', 'paid-addon-not-deployed', $api->slug ) : |
||
1117 | fs_text_inline( 'Add-on must be deployed to WordPress.org or Freemius.', 'free-addon-not-deployed', $api->slug ), |
||
1118 | ); |
||
1119 | fs_require_template( 'admin-notice.php', $missing_notice ); |
||
1120 | } |
||
1121 | echo "\t<div id='section-{$san_section}' class='section' style='display: {$display};'>\n"; |
||
1122 | echo $content; |
||
1123 | echo "\t</div>\n"; |
||
1124 | } |
||
1125 | echo "</div>\n"; |
||
1126 | echo "</div>\n"; |
||
1127 | echo "</div>\n"; // #plugin-information-scrollable |
||
1128 | echo "<div id='$tab-footer'>\n"; |
||
1129 | |||
1130 | if ( $api->has_paid_plan && ! empty( $api->checkout_link ) ) { |
||
1131 | echo $this->get_checkout_cta( $api ); |
||
1132 | } |
||
1133 | |||
1134 | if ( ! empty( $api->download_link ) ) { |
||
1135 | echo $this->get_download_cta( $api, empty( $api->checkout_link ) ); |
||
1136 | } |
||
1137 | |||
1138 | echo "</div>\n"; |
||
1139 | |||
1140 | iframe_footer(); |
||
1141 | exit; |
||
1142 | } |
||
1143 | } |
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.