Conditions | 7 |
Paths | 5 |
Total Lines | 83 |
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 |
||
134 | public function parse_shortcode( $attrs ) { |
||
135 | // Lets check if everything is set up. |
||
136 | if ( |
||
137 | ! $this->is_set_up() && |
||
138 | current_user_can( 'edit_posts' ) |
||
139 | ) { |
||
140 | return sprintf( |
||
141 | '<div class="components-placeholder"> |
||
142 | <div class="components-placeholder__label">%s</div> |
||
143 | <div class="components-placeholder__instructions">%s</div> |
||
144 | <a class="components-button is-button" href="https://wordpress.com/sharing/%s" target="_blank">%s</a> |
||
145 | </div>', |
||
146 | __( 'MailChimp form', 'jetpack' ), |
||
147 | __( 'You need to connect your MailChimp account and choose a list in order to start collecting Email subscribers.', 'jetpack' ), |
||
148 | $this->get_site_slug(), |
||
149 | __( 'Set up MailChimp form', 'jetpack' ) |
||
150 | ); |
||
151 | } |
||
152 | |||
153 | // We allow for overriding the presentation labels. |
||
154 | $data = shortcode_atts( |
||
155 | array( |
||
156 | 'title' => '', |
||
157 | 'email_placeholder' => __( 'Enter your email', 'jetpack' ), |
||
158 | 'submit_label' => __( 'Join My Email List', 'jetpack' ), |
||
159 | 'consent_text' => __( 'By clicking submit, you agree to share your email address with the site owner and MailChimp to receive marketing, updates, and other emails from the site owner. Use the unsubscribe link in those emails to opt out at any time.', 'jetpack' ), |
||
160 | 'processing_label' => __( 'Processing...', 'jetpack' ), |
||
161 | 'success_label' => __( 'Success! You\'ve been added to the list.', 'jetpack' ), |
||
162 | 'error_label' => __( "Oh no! Unfortunately there was an error.\nPlease try reloading this page and adding your email once more.", 'jetpack' ), |
||
163 | ), |
||
164 | is_array( $attrs ) ? array_filter( $attrs ) : array() |
||
165 | ); |
||
166 | |||
167 | // We don't allow users to change these parameters: |
||
168 | $data = array_merge( $data, array( |
||
169 | 'blog_id' => $this->get_blog_id(), |
||
170 | 'classname' => self::$css_classname_prefix, |
||
171 | 'dom_id' => uniqid( self::$css_classname_prefix . '_', false ), |
||
172 | ) ); |
||
173 | |||
174 | if ( ! wp_script_is( 'jetpack-email-subscribe', 'enqueued' ) ) { |
||
175 | wp_enqueue_script( 'jetpack-email-subscribe' ); |
||
176 | } |
||
177 | |||
178 | if ( ! wp_style_is( 'jetpack-email-subscribe', 'enqueue' ) ) { |
||
179 | wp_enqueue_style( 'jetpack-email-subscribe' ); |
||
180 | } |
||
181 | |||
182 | wp_add_inline_script( |
||
183 | 'jetpack-email-subscribe', |
||
184 | sprintf( |
||
185 | "try{JetpackEmailSubscribe.activate( '%s', '%s', '%s' );}catch(e){}", |
||
186 | esc_js( $data['blog_id'] ), |
||
187 | esc_js( $data['dom_id'] ), |
||
188 | esc_js( $data['classname'] ) |
||
189 | ) |
||
190 | ); |
||
191 | |||
192 | return sprintf( |
||
193 | '<div class="%1$s" id="%2$s"> |
||
194 | %3$s |
||
195 | <form> |
||
196 | <input type="email" class="%1$s-email" required placeholder="%4$s"> |
||
197 | <button type="submit" class="%1$s-submit">%6$s</button> |
||
198 | <label class="%1$s-consent-label"> |
||
199 | <small>%5$s</small> |
||
200 | </label> |
||
201 | </form> |
||
202 | <div class="%1$s-processing">%7$s</div> |
||
203 | <div class="%1$s-success">%8$s</div> |
||
204 | <div class="%1$s-error">%9$s</div> |
||
205 | </div>', |
||
206 | esc_attr( $data['classname'] ), |
||
207 | esc_attr( $data['dom_id'] ), |
||
208 | $data['title'] ? '<h3>' . esc_html( $data['title'] ) . '</h3>' : '', |
||
209 | esc_html( $data['email_placeholder'] ), |
||
210 | esc_html( $data['consent_text'] ), |
||
211 | esc_html( $data['submit_label'] ), |
||
212 | nl2br( esc_html( $data['processing_label'] ) ), |
||
213 | nl2br( esc_html( $data['success_label'] ) ), |
||
214 | nl2br( esc_html( $data['error_label'] ) ) |
||
215 | ); |
||
216 | } |
||
217 | |||
221 |