Conditions | 3 |
Paths | 2 |
Total Lines | 214 |
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 |
||
207 | public function form( $instance ) { |
||
208 | $instance = wp_parse_args( |
||
209 | $instance, |
||
210 | array( |
||
211 | 'code' => '', |
||
212 | 'email_placeholder' => '', |
||
213 | 'processing_text' => '', |
||
214 | 'success_text' => '', |
||
215 | 'error_text' => '', |
||
216 | 'groups' => '', |
||
217 | 'signup_tag' => '', |
||
218 | 'signup_value' => '', |
||
219 | 'button_color' => '', |
||
220 | 'text_color' => '', |
||
221 | 'css_class' => '', |
||
222 | ) |
||
223 | ); |
||
224 | |||
225 | $this->form_sections = array( |
||
226 | array( |
||
227 | 'title' => __( 'Text Elements', 'jetpack' ), |
||
228 | 'fields' => array( |
||
229 | array( |
||
230 | 'title' => __( 'Email Placeholder', 'jetpack' ), |
||
231 | 'id' => 'jetpack_mailchimp_email', |
||
232 | 'placeholder' => __( 'Enter your email', 'jetpack' ), |
||
233 | 'type' => 'text', |
||
234 | 'name' => esc_attr( $this->get_field_name( 'emailPlaceholder' ) ), |
||
235 | 'value' => esc_html( $instance['emailPlaceholder'] ), |
||
236 | ), |
||
237 | ), |
||
238 | ), |
||
239 | |||
240 | array( |
||
241 | 'title' => __( 'Notifications', 'jetpack' ), |
||
242 | 'fields' => array( |
||
243 | array( |
||
244 | 'title' => __( 'Processing', 'jetpack' ), |
||
245 | 'id' => 'jetpack_mailchimp_processing_label', |
||
246 | 'placeholder' => __( 'Processing', 'jetpack' ), |
||
247 | 'type' => 'text', |
||
248 | 'name' => esc_attr( $this->get_field_name( 'processingLabel' ) ), |
||
249 | 'value' => esc_html( $instance['processingLabel'] ), |
||
250 | ), |
||
251 | |||
252 | array( |
||
253 | 'title' => __( 'Success text', 'jetpack' ), |
||
254 | 'id' => 'jetpack_mailchimp_success_text', |
||
255 | 'placeholder' => __( 'Success! You are on the list.', 'jetpack' ), |
||
256 | 'type' => 'text', |
||
257 | 'name' => esc_attr( $this->get_field_name( 'successLabel' ) ), |
||
258 | 'value' => esc_html( $instance['successLabel'] ), |
||
259 | ), |
||
260 | |||
261 | array( |
||
262 | 'title' => __( 'Error text', 'jetpack' ), |
||
263 | 'id' => 'jetpack_mailchimp_error_label', |
||
264 | 'placeholder' => __( 'Whoops! There was an error and we could not process your subscription. Please reload the page and try again.', 'jetpack' ), |
||
265 | 'type' => 'text', |
||
266 | 'name' => esc_attr( $this->get_field_name( 'errorLabel' ) ), |
||
267 | 'value' => esc_html( $instance['errorLabel'] ), |
||
268 | ), |
||
269 | ), |
||
270 | ), |
||
271 | |||
272 | array( |
||
273 | 'title' => __( 'Mailchimp Groups', 'jetpack' ), |
||
274 | 'fields' => array( |
||
275 | array( |
||
276 | 'type' => 'groups', |
||
277 | ), |
||
278 | ), |
||
279 | 'extra_content' => array( |
||
280 | array( |
||
281 | 'text' => __( 'Learn about groups', 'jetpack' ), |
||
282 | 'link' => 'https://mailchimp.com/help/send-groups-audience/', |
||
283 | 'type' => 'link', |
||
284 | ), |
||
285 | ), |
||
286 | ), |
||
287 | |||
288 | array( |
||
289 | 'title' => __( 'Signup Location Tracking', 'jetpack' ), |
||
290 | 'fields' => array( |
||
291 | array( |
||
292 | 'title' => __( 'Signup Field Tag', 'jetpack' ), |
||
293 | 'id' => 'jetpack_mailchimp_signup_tag', |
||
294 | 'placeholder' => __( 'SIGNUP', 'jetpack' ), |
||
295 | 'type' => 'text', |
||
296 | 'name' => esc_attr( $this->get_field_name( 'signupFieldTag' ) ), |
||
297 | 'value' => esc_html( $instance['signupFieldTag'] ), |
||
298 | ), |
||
299 | |||
300 | array( |
||
301 | 'title' => __( 'Signup Field Value', 'jetpack' ), |
||
302 | 'id' => 'jetpack_mailchimp_signup_value', |
||
303 | 'placeholder' => __( 'website', 'jetpack' ), |
||
304 | 'type' => 'text', |
||
305 | 'name' => esc_attr( $this->get_field_name( 'signupFieldValue' ) ), |
||
306 | 'value' => esc_html( $instance['signupFieldValue'] ), |
||
307 | ), |
||
308 | ), |
||
309 | 'extra_content' => array( |
||
310 | array( |
||
311 | 'text' => __( 'Learn about signup location tracking(opens in a new tab)', 'jetpack' ), |
||
312 | 'link' => 'https://mailchimp.com/help/determine-webpage-signup-location/', |
||
313 | 'type' => 'link', |
||
314 | ), |
||
315 | ), |
||
316 | ), |
||
317 | |||
318 | array( |
||
319 | 'title' => __( 'Mailchimp Connection', 'jetpack' ), |
||
320 | 'extra_content' => array( |
||
321 | array( |
||
322 | 'text' => __( 'Manage Connection', 'jetpack' ), |
||
323 | 'link' => 'connect_url', |
||
324 | 'type' => 'link', |
||
325 | ), |
||
326 | ), |
||
327 | ), |
||
328 | |||
329 | array( |
||
330 | 'title' => __( 'Button Color Settings', 'jetpack' ), |
||
331 | 'fields' => array( |
||
332 | array( |
||
333 | 'id' => 'jetpack_mailchimp_button_color', |
||
334 | 'type' => 'color', |
||
335 | 'value' => esc_html( $instance['customBackgroundButtonColor'] ), |
||
336 | 'default' => '#cd2653', |
||
337 | 'name' => esc_attr( $this->get_field_name( 'customBackgroundButtonColor' ) ), |
||
338 | 'label' => __( 'Button Color', 'jetpack' ), |
||
339 | ), |
||
340 | |||
341 | array( |
||
342 | 'id' => 'jetpack_mailchimp_button_text_color', |
||
343 | 'type' => 'color', |
||
344 | 'value' => esc_html( $instance['customTextButtonColor'] ), |
||
345 | 'default' => '#ffffff', |
||
346 | 'name' => esc_attr( $this->get_field_name( 'customTextButtonColor' ) ), |
||
347 | 'label' => __( 'Button Text Color', 'jetpack' ), |
||
348 | ), |
||
349 | ), |
||
350 | ), |
||
351 | |||
352 | array( |
||
353 | 'title' => __( 'Advanced', 'jetpack' ), |
||
354 | 'fields' => array( |
||
355 | array( |
||
356 | 'title' => __( 'Additional CSS class(es)', 'jetpack' ), |
||
357 | 'id' => 'jetpack_mailchimp_css_class', |
||
358 | 'placeholder' => '', |
||
359 | 'help_text' => __( 'Separate multiple classes with spaces.', 'jetpack' ), |
||
360 | 'type' => 'text', |
||
361 | 'name' => esc_attr( $this->get_field_name( 'cssClass' ) ), |
||
362 | 'value' => esc_html( $instance['cssClass'] ), |
||
363 | ), |
||
364 | |||
365 | array( |
||
366 | 'title' => __( 'Activate popup mode', 'jetpack' ), |
||
367 | 'type' => 'checkbox', |
||
368 | 'name' => esc_attr( $this->get_field_name( 'popupMode' ) ), |
||
369 | 'value' => esc_html( $instance['popupMode'] ), |
||
370 | ), |
||
371 | |||
372 | array( |
||
373 | 'title' => __( 'Popup delay (miliseconds)', 'jetpack' ), |
||
374 | 'type' => 'number', |
||
375 | 'name' => esc_attr( $this->get_field_name( 'delay' ) ), |
||
376 | 'value' => esc_html( $instance['delay'] ), |
||
377 | 'placeholder' => '0', |
||
378 | ), |
||
379 | ), |
||
380 | ), |
||
381 | ); |
||
382 | |||
383 | $this->placeholder_data = array( |
||
384 | 'instructions' => __( 'You need to connect your Mailchimp account and choose a list in order to start collecting Email subscribers.', 'jetpack' ), |
||
385 | 'setupButtonText' => __( 'Set up Mailchimp form', 'jetpack' ), |
||
386 | 'recheckText' => __( 'Re-check Connection', 'jetpack' ), |
||
387 | ); |
||
388 | |||
389 | if ( ! empty( $instance['code'] ) ) { |
||
390 | ?> |
||
391 | <p class="mailchimp_code"> |
||
392 | <label for="<?php echo esc_attr( $this->get_field_id( 'code' ) ); ?>"> |
||
393 | <?php |
||
394 | /* translators: %1$s is replaced mailchimp suppoert link */ |
||
395 | echo sprintf( __( 'Code: <a href="%s" target="_blank">( ? )</a>', 'jetpack' ), 'https://en.support.wordpress.com/mailchimp/' ); |
||
396 | ?> |
||
397 | </label> |
||
398 | <textarea class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'code' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'code' ) ); ?>" rows="3"><?php echo esc_textarea( $instance['code'] ); ?></textarea> |
||
399 | </p> |
||
400 | <p class="jetpack_mailchimp_new_form_wrapper"> |
||
401 | <input type="checkbox" id="jetpack_mailchimp_new_form" name="<?php echo esc_attr( $this->get_field_name( 'new_form' ) ); ?>" > <?php echo esc_html__( 'Check this if you want to use the new form for this widget (the code in the box above will be deleted)', 'jetpack' ); ?> |
||
402 | </p> |
||
403 | <?php |
||
404 | } |
||
405 | |||
406 | ?> |
||
407 | <div class="mailchimp_widget_jetpack_form_wrapper"></div> |
||
408 | <script> |
||
409 | |||
410 | var mailchimpAdmin = { |
||
411 | formData: '<?php echo wp_json_encode( $this->form_sections ); ?>', |
||
412 | placeholderData: '<?php echo wp_json_encode( $this->placeholder_data ); ?>', |
||
413 | oldForm: <?php echo ! empty( $instance['code'] ) ? 'true' : 'false'; ?>, |
||
414 | groups: '<?php echo esc_html( $instance['interests'] ); ?>', |
||
415 | groupsFieldName: '<?php echo esc_attr( $this->get_field_name( 'interests' ) ); ?>' |
||
416 | } |
||
417 | jQuery( window ).trigger( 'jetpack_mailchimp_load_form' ); |
||
418 | </script> |
||
419 | <?php |
||
420 | } |
||
421 | |||
425 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: