Conditions | 4 |
Paths | 8 |
Total Lines | 84 |
Code Lines | 67 |
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 |
||
147 | function get_options( $wp_customize ) { |
||
148 | $transport = isset( $wp_customize->selective_refresh ) ? 'postMessage' : 'refresh'; |
||
149 | |||
150 | // Get the correct translated string for preview in WP 4.7 and later. |
||
151 | $switched_locale = function_exists( 'switch_to_locale' ) |
||
152 | ? switch_to_locale( get_user_locale() ) |
||
153 | : false; |
||
154 | $headline = __( 'Related', 'jetpack' ); |
||
155 | if ( $switched_locale ) { |
||
156 | restore_previous_locale(); |
||
157 | } |
||
158 | |||
159 | return apply_filters( |
||
160 | 'jetpack_related_posts_customize_options', array( |
||
161 | 'enabled' => array( |
||
162 | 'control_type' => 'hidden', |
||
163 | 'default' => 1, |
||
164 | 'setting_type' => 'option', |
||
165 | 'transport' => $transport, |
||
166 | ), |
||
167 | 'show_headline' => array( |
||
168 | 'label' => esc_html__( 'Show a headline', 'jetpack' ), |
||
169 | 'description' => esc_html__( 'This helps to clearly separate the related posts from post content.', 'jetpack' ), |
||
170 | 'control_type' => 'checkbox', |
||
171 | 'default' => 1, |
||
172 | 'setting_type' => 'option', |
||
173 | 'transport' => $transport, |
||
174 | ), |
||
175 | 'headline' => array( |
||
176 | 'label' => '', |
||
177 | 'description' => esc_html__( 'Enter text to use as headline.', 'jetpack' ), |
||
178 | 'control_type' => 'text', |
||
179 | 'default' => esc_html( $headline ), |
||
180 | 'setting_type' => 'option', |
||
181 | 'transport' => $transport, |
||
182 | ), |
||
183 | 'show_thumbnails' => array( |
||
184 | 'label' => esc_html__( 'Show thumbnails', 'jetpack' ), |
||
185 | 'description' => esc_html__( 'Use a large and visually striking layout.', 'jetpack' ), |
||
186 | 'control_type' => 'checkbox', |
||
187 | 'default' => 1, |
||
188 | 'setting_type' => 'option', |
||
189 | 'transport' => $transport, |
||
190 | ), |
||
191 | 'show_date' => array( |
||
192 | 'label' => esc_html__( 'Show date', 'jetpack' ), |
||
193 | 'description' => esc_html__( 'Display date when entry was published.', 'jetpack' ), |
||
194 | 'control_type' => 'checkbox', |
||
195 | 'default' => 1, |
||
196 | 'setting_type' => 'option', |
||
197 | 'transport' => $transport, |
||
198 | ), |
||
199 | 'show_context' => array( |
||
200 | 'label' => esc_html__( 'Show context', 'jetpack' ), |
||
201 | 'description' => esc_html__( "Display entry's category or tag.", 'jetpack' ), |
||
202 | 'control_type' => 'checkbox', |
||
203 | 'default' => 1, |
||
204 | 'setting_type' => 'option', |
||
205 | 'transport' => $transport, |
||
206 | ), |
||
207 | 'layout' => array( |
||
208 | 'label' => esc_html__( 'Layout', 'jetpack' ), |
||
209 | 'description' => esc_html__( 'Arrange entries in different layouts.', 'jetpack' ), |
||
210 | 'control_type' => 'select', |
||
211 | 'choices' => array( |
||
212 | 'grid' => esc_html__( 'Grid', 'jetpack' ), |
||
213 | 'list' => esc_html__( 'List', 'jetpack' ), |
||
214 | ), |
||
215 | 'default' => 'grid', |
||
216 | 'setting_type' => 'option', |
||
217 | 'transport' => $transport, |
||
218 | ), |
||
219 | 'msg_go_to_single' => array( |
||
220 | 'description' => esc_html__( 'Please visit a single post view to reveal the customization options.', 'jetpack' ), |
||
221 | 'control_type' => 'message', |
||
222 | 'active_callback' => __CLASS__ . '::is_not_single', |
||
223 | ), |
||
224 | 'msg_example' => array( |
||
225 | 'description' => esc_html__( 'Please note that the related posts displayed now are only for previewing purposes.', 'jetpack' ), |
||
226 | 'control_type' => 'message', |
||
227 | ), |
||
228 | ) |
||
229 | ); |
||
230 | } |
||
231 | |||
261 | new Jetpack_Related_Posts_Customize; |
The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using
the property is implicitly global.
To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.