Conditions | 5 |
Paths | 4 |
Total Lines | 171 |
Code Lines | 118 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 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 |
||
211 | public function details_metaboxes() { |
||
212 | |||
213 | $cmb = new_cmb2_box( array( |
||
214 | 'id' => $this->slug . '_details_metabox', |
||
215 | 'title' => __( 'Workout Details', 'lsx-health-plan' ), |
||
216 | 'object_types' => array( $this->slug ), // Post type |
||
217 | 'context' => 'normal', |
||
218 | 'priority' => 'high', |
||
219 | 'show_names' => true, |
||
220 | ) ); |
||
221 | |||
222 | $cmb->add_field( array( |
||
223 | 'name' => __( 'Workout Short Description', 'lsx-health-plan' ), |
||
224 | 'id' => $this->slug . '_short_description', |
||
225 | 'type' => 'textarea_small', |
||
226 | 'desc' => __( 'Add a small description for this workout (optional)', 'lsx-health-plan' ), |
||
227 | ) ); |
||
228 | |||
229 | $workout_sections = apply_filters( 'lsx_health_plan_workout_sections_amount', 6 ); |
||
230 | if ( false !== $workout_sections && null !== $workout_sections ) { |
||
231 | $i = 1; |
||
232 | while ( $i <= $workout_sections ) { |
||
233 | |||
234 | $cmb_group = new_cmb2_box( array( |
||
235 | 'id' => $this->slug . '_section_' . $i . '_metabox', |
||
236 | 'title' => esc_html__( 'Exercise Group ', 'lsx-health-plan' ) . $i, |
||
237 | 'object_types' => array( $this->slug ), |
||
238 | ) ); |
||
239 | |||
240 | $cmb_group->add_field( array( |
||
241 | 'name' => __( 'Title', 'lsx-health-plan' ), |
||
242 | 'id' => $this->slug . '_section_' . $i . '_title', |
||
243 | 'type' => 'text', |
||
244 | 'show_on_cb' => 'cmb2_hide_if_no_cats', |
||
245 | ) ); |
||
246 | |||
247 | $cmb_group->add_field( |
||
248 | array( |
||
249 | 'name' => __( 'Description', 'lsx-health-plan' ), |
||
250 | 'id' => $this->slug . '_section_' . $i . '_description', |
||
251 | 'type' => 'wysiwyg', |
||
252 | 'show_on_cb' => 'cmb2_hide_if_no_cats', |
||
253 | 'options' => array( |
||
254 | 'textarea_rows' => 5, |
||
255 | ), |
||
256 | ) |
||
257 | ); |
||
258 | |||
259 | /** |
||
260 | * Repeatable Field Groups |
||
261 | */ |
||
262 | // $group_field_id is the field id string, so in this case: $prefix . 'demo' |
||
263 | $group_field_id = $cmb_group->add_field( |
||
264 | array( |
||
265 | 'id' => $this->slug . '_section_' . $i, |
||
266 | 'type' => 'group', |
||
267 | 'options' => array( |
||
268 | 'group_title' => esc_html__( 'Exercise {#}', 'lsx-health-plan' ), // {#} gets replaced by row number |
||
269 | 'add_button' => esc_html__( 'Add New', 'lsx-health-plan' ), |
||
270 | 'remove_button' => esc_html__( 'Delete', 'lsx-health-plan' ), |
||
271 | 'sortable' => true, |
||
272 | 'closed' => true, // true to have the groups closed by default |
||
273 | ), |
||
274 | ) |
||
275 | ); |
||
276 | |||
277 | if ( false !== \lsx_health_plan\functions\get_option( 'exercise_enabled', false ) ) { |
||
278 | $cmb_group->add_group_field( |
||
279 | $group_field_id, |
||
280 | array( |
||
281 | 'name' => __( 'Exercise related to this workout', 'lsx-health-plan' ), |
||
282 | 'id' => 'connected_exercises', |
||
283 | 'type' => 'post_search_ajax', |
||
284 | // Optional : |
||
285 | 'limit' => 1, // Limit selection to X items only (default 1) |
||
286 | 'sortable' => true, // Allow selected items to be sortable (default false) |
||
287 | 'query_args' => array( |
||
288 | 'post_type' => array( 'exercise' ), |
||
289 | 'post_status' => array( 'publish' ), |
||
290 | 'posts_per_page' => -1, |
||
291 | ), |
||
292 | ) |
||
293 | ); |
||
294 | } else { |
||
295 | $cmb_group->add_group_field( |
||
296 | $group_field_id, |
||
297 | array( |
||
298 | 'name' => __( 'Video related to this workout', 'lsx-health-plan' ), |
||
299 | 'id' => 'connected_videos', |
||
300 | 'type' => 'post_search_ajax', |
||
301 | // Optional : |
||
302 | 'limit' => 1, // Limit selection to X items only (default 1) |
||
303 | 'sortable' => true, // Allow selected items to be sortable (default false) |
||
304 | 'query_args' => array( |
||
305 | 'post_type' => array( 'video' ), |
||
306 | 'post_status' => array( 'publish' ), |
||
307 | 'posts_per_page' => -1, |
||
308 | ), |
||
309 | ) |
||
310 | ); |
||
311 | $cmb_group->add_group_field( |
||
312 | $group_field_id, |
||
313 | array( |
||
314 | 'name' => esc_html__( 'Workout Name', 'lsx-health-plan' ), |
||
315 | 'id' => 'name', |
||
316 | 'type' => 'text', |
||
317 | // 'repeatable' => true, // Repeatable fields are supported w/in repeatable groups (for most types) |
||
318 | ) |
||
319 | ); |
||
320 | |||
321 | $cmb_group->add_group_field( |
||
322 | $group_field_id, |
||
323 | array( |
||
324 | 'name' => __( 'Description', 'lsx-health-plan' ), |
||
325 | 'id' => 'description', |
||
326 | 'type' => 'wysiwyg', |
||
327 | 'options' => array( |
||
328 | 'textarea_rows' => 2, |
||
329 | ), |
||
330 | ) |
||
331 | ); |
||
332 | } |
||
333 | |||
334 | $cmb_group->add_group_field( |
||
335 | $group_field_id, |
||
336 | array( |
||
337 | 'name' => esc_html__( 'Exercise title (Optional)', 'lsx-health-plan' ), |
||
338 | 'id' => 'alt_title', |
||
339 | 'type' => 'text', |
||
340 | ) |
||
341 | ); |
||
342 | $cmb_group->add_group_field( |
||
343 | $group_field_id, |
||
344 | array( |
||
345 | 'name' => esc_html__( 'Exercise Description (Optional)', 'lsx-health-plan' ), |
||
346 | 'id' => 'alt_description', |
||
347 | 'type' => 'textarea_small', |
||
348 | ) |
||
349 | ); |
||
350 | $cmb_group->add_group_field( |
||
351 | $group_field_id, |
||
352 | array( |
||
353 | 'name' => esc_html__( 'Reps / Time / Distance', 'lsx-health-plan' ), |
||
354 | 'id' => 'reps', |
||
355 | 'type' => 'text', |
||
356 | // 'repeatable' => true, // Repeatable fields are supported w/in repeatable groups (for most types) |
||
357 | ) |
||
358 | ); |
||
359 | $cmb_group->add_group_field( |
||
360 | $group_field_id, |
||
361 | array( |
||
362 | 'name' => __( 'Exercise Image (Optional)', 'lsx-health-plan' ), |
||
363 | 'id' => 'exercise_alt_thumbnail', |
||
364 | 'type' => 'file', |
||
365 | 'text' => array( |
||
366 | 'add_upload_file_text' => __( 'Add File', 'lsx-health-plan' ), |
||
367 | ), |
||
368 | 'desc' => __( 'Upload an image 300px x 300px in size.', 'lsx-health-plan' ), |
||
369 | 'query_args' => array( |
||
370 | 'type' => array( |
||
371 | 'image/gif', |
||
372 | 'image/jpeg', |
||
373 | 'image/png', |
||
374 | ), |
||
375 | ), |
||
376 | 'preview_size' => 'thumbnail', |
||
377 | 'classes' => 'lsx-field-col lsx-field-add-field lsx-field-col-25', |
||
378 | ) |
||
379 | ); |
||
380 | |||
381 | $i++; |
||
382 | }; |
||
397 |