Conditions | 7 |
Paths | 4 |
Total Lines | 75 |
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 |
||
23 | function jetpack_calendly_block_load_assets( $attr, $content ) { |
||
24 | $url = jetpack_calendly_block_get_attribute( $attr, 'url' ); |
||
25 | if ( empty( $url ) ) { |
||
26 | return; |
||
27 | } |
||
28 | |||
29 | /* |
||
30 | * Enqueue necessary scripts and styles. |
||
31 | */ |
||
32 | Jetpack_Gutenberg::load_assets_as_required( 'calendly' ); |
||
33 | wp_enqueue_script( |
||
34 | 'jetpack-calendly-external-js', |
||
35 | 'https://assets.calendly.com/assets/external/widget.js', |
||
36 | null, |
||
37 | JETPACK__VERSION, |
||
38 | false |
||
39 | ); |
||
40 | |||
41 | $style = jetpack_calendly_block_get_attribute( $attr, 'style' ); |
||
42 | $hide_event_type_details = jetpack_calendly_block_get_attribute( $attr, 'hideEventTypeDetails' ); |
||
43 | $background_color = jetpack_calendly_block_get_attribute( $attr, 'backgroundColor' ); |
||
44 | $text_color = jetpack_calendly_block_get_attribute( $attr, 'textColor' ); |
||
45 | $primary_color = jetpack_calendly_block_get_attribute( $attr, 'primaryColor' ); |
||
46 | $submit_button_text = jetpack_calendly_block_get_attribute( $attr, 'submitButtonText' ); |
||
47 | $submit_button_text_color = jetpack_calendly_block_get_attribute( $attr, 'customTextButtonColor' ); |
||
48 | $submit_button_background_color = jetpack_calendly_block_get_attribute( $attr, 'customBackgroundButtonColor' ); |
||
49 | $classes = Jetpack_Gutenberg::block_classes( 'calendly', $attr ); |
||
50 | |||
51 | $url = add_query_arg( |
||
52 | array( |
||
53 | 'hide_event_type_details' => (int) $hide_event_type_details, |
||
54 | 'background_color' => sanitize_hex_color_no_hash( $background_color ), |
||
55 | 'text_color' => sanitize_hex_color_no_hash( $text_color ), |
||
56 | 'primary_color' => sanitize_hex_color_no_hash( $primary_color ), |
||
57 | ), |
||
58 | $url |
||
59 | ); |
||
60 | |||
61 | if ( 'link' === $style ) { |
||
62 | wp_enqueue_style( 'jetpack-calendly-external-css', 'https://assets.calendly.com/assets/external/widget.css', null, JETPACK__VERSION ); |
||
63 | |||
64 | /* |
||
65 | * If we have some additional styles from the editor |
||
66 | * (a custom text color, custom bg color, or both ) |
||
67 | * Let's add that CSS inline. |
||
68 | */ |
||
69 | if ( ! empty( $submit_button_text_color ) || ! empty( $submit_button_background_color ) ) { |
||
70 | $inline_styles = sprintf( |
||
71 | '.wp-block-jetpack-calendly .button{%1$s%2$s}', |
||
72 | ! empty( $submit_button_text_color ) |
||
73 | ? 'color:#' . sanitize_hex_color_no_hash( $submit_button_text_color ) . ';' |
||
74 | : '', |
||
75 | ! empty( $submit_button_background_color ) |
||
76 | ? 'background-color:#' . sanitize_hex_color_no_hash( $submit_button_background_color ) . ';' |
||
77 | : '' |
||
78 | ); |
||
79 | wp_add_inline_style( 'jetpack-calendly-external-css', $inline_styles ); |
||
80 | } |
||
81 | |||
82 | $content = sprintf( |
||
83 | '<div class="%1$s"><a class="button" href="" onclick="Calendly.initPopupWidget({url:\'%2$s\'});return false;">%3$s</a></div>', |
||
84 | esc_attr( $classes ), |
||
85 | esc_url( $url ), |
||
86 | wp_kses_post( $submit_button_text ) |
||
87 | ); |
||
88 | } else { // Button style. |
||
89 | $content = sprintf( |
||
90 | '<div class="calendly-inline-widget %1$s" data-url="%2$s" style="min-width:320px;height:630px;"></div>', |
||
91 | esc_attr( $classes ), |
||
92 | esc_url( $url ) |
||
93 | ); |
||
94 | } |
||
95 | |||
96 | return $content; |
||
97 | } |
||
98 | |||
125 |