| Conditions | 10 |
| Paths | 12 |
| Total Lines | 63 |
| 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 |
||
| 123 | function ajax_foogallery_video_discount_offer() { |
||
| 124 | if ( check_admin_referer( 'foogallery_video_discount_offer' ) ) { |
||
| 125 | $license_key = get_site_option( 'foo-video_licensekey' ); |
||
| 126 | |||
| 127 | if ( empty( $license_key ) ) { |
||
| 128 | echo '<h3>' . __( 'No FooVideo License Found!', 'foogallery' ) . '</h3>'; |
||
| 129 | $settings_link = '<a target="_blank" href="' . foogallery_admin_settings_url() . '#extensions">' . __('FooGallery Settings page', 'foogallery') . '</a>'; |
||
| 130 | echo '<h4>' . sprintf( __( 'There is no FooVideo license key set for this site. Please set it via the %s under the extensions tab and try again.', 'foogallery' ), $settings_link ) . '</h4>'; |
||
| 131 | } else { |
||
| 132 | $license_url = "http://fooplugins.com/api/{$license_key}/licensekey/"; |
||
| 133 | |||
| 134 | //fetch the license info from FooPlugins.com |
||
| 135 | $response = wp_remote_get( $license_url, array( 'sslverify' => false ) ); |
||
| 136 | |||
| 137 | if( ! is_wp_error( $response ) ) { |
||
| 138 | |||
| 139 | if ( $response['response']['code'] == 200 ) { |
||
| 140 | $license_details = @json_decode( $response['body'], true ); |
||
| 141 | |||
| 142 | if ( isset( $license_details ) ) { |
||
| 143 | $coupon = $license_details['coupon']; |
||
| 144 | |||
| 145 | if ( $coupon['valid'] ) { |
||
| 146 | echo '<h3>' . __( 'Your discount code is : ', 'foogallery' ) . $coupon['code'] . '</h3>'; |
||
| 147 | echo '<h4>' . __( 'The value of the discount is : ', 'foogallery' ) . $coupon['value'] . '</h4>'; |
||
| 148 | |||
| 149 | $license_option = __( 'Single Site', 'foogallery' ); |
||
| 150 | if ( 'FooVideo Extension (Multi)' === $license_details['license'] ) { |
||
| 151 | $license_option = __( '5 Site', 'foogallery' ); |
||
| 152 | } else if ( 'FooVideo Extension (Business)' === $license_details['license'] ) { |
||
| 153 | $license_option = __( '25 Site', 'foogallery' ); |
||
| 154 | } |
||
| 155 | $license_option = '<strong>' . $license_option . '</strong>'; |
||
| 156 | $pricing_page_url = foogallery_admin_pricing_url(); |
||
| 157 | $pricing_page_text = apply_filters( 'foogallery_foovideo_pricing_menu_text', __( 'FooGallery -> Upgrade', 'foogallery' ) ); |
||
| 158 | $pricing_page_link = '<a target="_blank" href="' . $pricing_page_url . '">' . $pricing_page_text . '</a>'; |
||
| 159 | |||
| 160 | if ( !class_exists( 'FooGallery_Pro_Video' ) ) { |
||
| 161 | echo sprintf( __( 'Your discount entitles you to a FooGallery PRO - %s license for no additional cost!', 'foogallery' ), $license_option ); |
||
| 162 | echo '<br />' . sprintf( __( 'Copy the discount code above and use it when purchasing FooGallery PRO from %s (make sure to select %s plan!).', 'foogallery' ), $pricing_page_link, $license_option ); |
||
| 163 | } else { |
||
| 164 | echo sprintf( __( 'Your discount entitles you to a free FooGallery PRO - %s license renewal or extension!', 'foogallery' ), $license_option ); |
||
| 165 | echo '<br />' . sprintf( __( 'Copy the discount code above and use it when extending your FooGallery PRO license from %s (make sure to select the %s plan!).', 'foogallery' ), $pricing_page_link, $license_option ); |
||
| 166 | } |
||
| 167 | $doc_link = '<a href="https://fooplugins.link/foovideo-upgrade" target="_blank">' . __( 'read our documentation', 'foogallery' ) . '</a>'; |
||
| 168 | echo '<br />' . sprintf( __( 'For a more detailed guide on the process, %s.', 'foogallery' ), $doc_link ); |
||
| 169 | |||
| 170 | //redeemed the code - no need to show the admin notice anymore |
||
| 171 | update_option( FooGallery_FooVideo_Compatibility::option_discount_key, '2' ); |
||
| 172 | } else { |
||
| 173 | echo '<h3>' . __( 'Invalid License!', 'foogallery' ) . '</h3>'; |
||
| 174 | echo '<h4>' .$coupon['code'] . '</h4>'; |
||
| 175 | } |
||
| 176 | |||
| 177 | } |
||
| 178 | } |
||
| 179 | } else { |
||
| 180 | echo '<h4>'. __('Sorry! There was an error retrieving your discount code from our servers. Please log a support ticket and we will help.', 'foogallery') . '</h4>'; |
||
| 181 | } |
||
| 182 | } |
||
| 183 | } |
||
| 184 | die(); |
||
| 185 | } |
||
| 186 | |||
| 207 | } |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.