| Conditions | 52 |
| Paths | > 20000 |
| Total Lines | 169 |
| 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 |
||
| 81 | public function output_button( $addon ) { |
||
| 82 | $current_tab = empty( $_GET['tab'] ) ? 'addons' : sanitize_title( $_GET['tab'] ); |
||
| 83 | // $button_text = __('Free','invoicing'); |
||
| 84 | // $licensing = false; |
||
| 85 | // $installed = false; |
||
| 86 | // $price = ''; |
||
| 87 | // $license = ''; |
||
| 88 | // $slug = ''; |
||
| 89 | // $url = isset($addon->info->link) ? $addon->info->link : ''; |
||
| 90 | // $class = 'button-primary'; |
||
| 91 | // $install_status = 'get'; |
||
| 92 | // $onclick = ''; |
||
| 93 | |||
| 94 | $wp_org_themes = array('supreme-directory','directory-starter'); |
||
| 95 | |||
| 96 | $button_args = array( |
||
| 97 | 'type' => ($current_tab == 'addons' || $current_tab =='gateways') ? 'addons' : $current_tab, |
||
| 98 | 'id' => isset($addon->info->id) ? absint($addon->info->id) : '', |
||
| 99 | 'title' => isset($addon->info->title) ? $addon->info->title : '', |
||
| 100 | 'button_text' => __('Free','invoicing'), |
||
| 101 | 'price_text' => __('Free','invoicing'), |
||
| 102 | 'link' => isset($addon->info->link) ? $addon->info->link : '', // link to product |
||
| 103 | 'url' => isset($addon->info->link) ? $addon->info->link : '', // button url |
||
| 104 | 'class' => 'button-primary', |
||
| 105 | 'install_status' => 'get', |
||
| 106 | 'installed' => false, |
||
| 107 | 'price' => '', |
||
| 108 | 'licensing' => isset($addon->licensing->enabled) && $addon->licensing->enabled ? true : false, |
||
| 109 | 'license' => isset($addon->licensing->license) && $addon->licensing->license ? $addon->licensing->license : '', |
||
| 110 | 'onclick' => '', |
||
| 111 | 'slug' => isset($addon->info->slug) ? $addon->info->slug : '', |
||
| 112 | 'active' => false, |
||
| 113 | 'file' => '', |
||
| 114 | 'update_url' => '', |
||
| 115 | ); |
||
| 116 | |||
| 117 | if( ($current_tab == 'addons' || $current_tab =='gateways') && isset($addon->info->id) && $addon->info->id){ |
||
| 118 | include_once( ABSPATH . 'wp-admin/includes/plugin-install.php' ); //for plugins_api.. |
||
| 119 | if(!empty($addon->licensing->edd_slug)){$button_args['slug'] = $addon->licensing->edd_slug;} |
||
| 120 | $status = self::install_plugin_install_status($addon); |
||
| 121 | $button_args['file'] = isset($status['file']) ? $status['file'] : ''; |
||
| 122 | if(isset($status['status'])){$button_args['install_status'] = $status['status'];} |
||
| 123 | $button_args['update_url'] = "https://wpinvoicing.com"; |
||
| 124 | }elseif($current_tab == 'themes' && isset($addon->info->id) && $addon->info->id) { |
||
| 125 | if(!empty($addon->licensing->edd_slug)){$button_args['slug'] = $addon->licensing->edd_slug;} |
||
| 126 | $button_args['installed'] = self::is_theme_installed($addon); |
||
| 127 | if(!in_array($button_args['slug'],$wp_org_themes)){ |
||
| 128 | $button_args['update_url'] = "https://wpinvoicing.com"; |
||
| 129 | } |
||
| 130 | }elseif($current_tab == 'recommended_plugins' && isset($addon->info->slug) && $addon->info->slug){ |
||
| 131 | include_once( ABSPATH . 'wp-admin/includes/plugin-install.php' ); //for plugins_api.. |
||
| 132 | $status = install_plugin_install_status(array("slug"=>$button_args['slug'],"version"=>"")); |
||
| 133 | $button_args['install_status'] = isset($status['status']) ? $status['status'] : 'install'; |
||
| 134 | $button_args['file'] = isset($status['file']) ? $status['file'] : ''; |
||
| 135 | } |
||
| 136 | |||
| 137 | // set price |
||
| 138 | if(isset($addon->pricing) && !empty($addon->pricing)){ |
||
| 139 | if(is_object($addon->pricing)){ |
||
| 140 | $prices = (Array)$addon->pricing; |
||
| 141 | $button_args['price'] = reset($prices); |
||
| 142 | }elseif(isset($addon->pricing)){ |
||
| 143 | $button_args['price'] = $addon->pricing; |
||
| 144 | } |
||
| 145 | } |
||
| 146 | |||
| 147 | // set price text |
||
| 148 | if( $button_args['price'] && $button_args['price'] != '0.00' ){ |
||
| 149 | $button_args['price_text'] = sprintf( __('From: $%d', 'invoicing'), $button_args['price']); |
||
| 150 | } |
||
| 151 | |||
| 152 | |||
| 153 | // set if installed |
||
| 154 | if(in_array($button_args['install_status'], array('installed','latest_installed','update_available','newer_installed'))){ |
||
| 155 | $button_args['installed'] = true; |
||
| 156 | } |
||
| 157 | |||
| 158 | // print_r($button_args); |
||
| 159 | // set if active |
||
| 160 | if($button_args['installed'] && ($button_args['file'] || $button_args['type'] == 'themes')){ |
||
| 161 | if($button_args['type'] != 'themes'){ |
||
| 162 | $button_args['active'] = is_plugin_active($button_args['file']); |
||
| 163 | }else{ |
||
| 164 | $button_args['active'] = self::is_theme_active($addon); |
||
| 165 | } |
||
| 166 | } |
||
| 167 | |||
| 168 | // set button text and class |
||
| 169 | if($button_args['active']){ |
||
| 170 | $button_args['button_text'] = __('Active','invoicing'); |
||
| 171 | $button_args['class'] = ' button-secondary disabled '; |
||
| 172 | }elseif($button_args['installed']){ |
||
| 173 | $button_args['button_text'] = __('Activate','invoicing'); |
||
| 174 | |||
| 175 | if($button_args['type'] != 'themes'){ |
||
| 176 | if ( current_user_can( 'manage_options' ) ) { |
||
| 177 | $button_args['url'] = wp_nonce_url(admin_url('plugins.php?action=activate&plugin='.$button_args['file']), 'activate-plugin_' . $button_args['file']); |
||
| 178 | }else{ |
||
| 179 | $button_args['url'] = '#'; |
||
| 180 | } |
||
| 181 | }else{ |
||
| 182 | if ( current_user_can( 'switch_themes' ) ) { |
||
| 183 | $button_args['url'] = self::get_theme_activation_url($addon); |
||
| 184 | }else{ |
||
| 185 | $button_args['url'] = '#'; |
||
| 186 | } |
||
| 187 | } |
||
| 188 | |||
| 189 | }else{ |
||
| 190 | if($button_args['type'] == 'recommended_plugins'){ |
||
| 191 | $button_args['button_text'] = __('Install','invoicing'); |
||
| 192 | }else{ |
||
| 193 | $button_args['button_text'] = __('Get it','invoicing'); |
||
| 194 | |||
| 195 | /*if($button_args['type'] == 'themes' && in_array($button_args['slug'],$wp_org_themes) ){ |
||
| 196 | $button_args['button_text'] = __('Install','invoicing'); |
||
| 197 | $button_args['url'] = self::get_theme_install_url($button_args['slug']); |
||
| 198 | $button_args['onclick'] = 'gd_set_button_installing(this);'; |
||
| 199 | }*/ |
||
| 200 | |||
| 201 | } |
||
| 202 | } |
||
| 203 | |||
| 204 | |||
| 205 | // filter the button arguments |
||
| 206 | $button_args = apply_filters('edd_api_button_args',$button_args); |
||
| 207 | // print_r($button_args); |
||
| 208 | // set price text |
||
| 209 | if(isset($button_args['price_text'])){ |
||
| 210 | ?> |
||
| 211 | <a |
||
| 212 | target="_blank" |
||
| 213 | class="addons-price-text" |
||
| 214 | href="<?php echo esc_url( $button_args['link'] ); ?>"> |
||
| 215 | <?php echo esc_html( $button_args['price_text'] ); ?> |
||
| 216 | </a> |
||
| 217 | <?php |
||
| 218 | } |
||
| 219 | |||
| 220 | |||
| 221 | $target = ''; |
||
| 222 | if ( ! empty( $button_args['url'] ) ) { |
||
| 223 | $target = strpos($button_args['url'], get_site_url()) !== false ? '' : ' target="_blank" '; |
||
| 224 | } |
||
| 225 | |||
| 226 | ?> |
||
| 227 | <a |
||
| 228 | data-licence="<?php echo esc_attr($button_args['license']);?>" |
||
| 229 | data-licensing="<?php echo $button_args['licensing'] ? 1 : 0;?>" |
||
| 230 | data-title="<?php echo esc_attr($button_args['title']);?>" |
||
| 231 | data-type="<?php echo esc_attr($button_args['type']);?>" |
||
| 232 | data-text-error-message="<?php _e('Something went wrong!','invoicing');?>" |
||
| 233 | data-text-activate="<?php _e('Activate','invoicing');?>" |
||
| 234 | data-text-activating="<?php _e('Activating','invoicing');?>" |
||
| 235 | data-text-deactivate="<?php _e('Deactivate','invoicing');?>" |
||
| 236 | data-text-installed="<?php _e('Installed','invoicing');?>" |
||
| 237 | data-text-install="<?php _e('Install','invoicing');?>" |
||
| 238 | data-text-installing="<?php _e('Installing','invoicing');?>" |
||
| 239 | data-text-error="<?php _e('Error','invoicing');?>" |
||
| 240 | <?php if(!empty($button_args['onclick'])){echo " onclick='".$button_args['onclick']."' ";}?> |
||
| 241 | <?php echo $target;?> |
||
| 242 | class="addons-button <?php echo esc_attr( $button_args['class'] ); ?>" |
||
| 243 | href="<?php echo esc_url( $button_args['url'] ); ?>"> |
||
| 244 | <?php echo esc_html( $button_args['button_text'] ); ?> |
||
| 245 | </a> |
||
| 246 | <?php |
||
| 247 | |||
| 248 | |||
| 249 | } |
||
| 250 | |||
| 294 |