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