| Conditions | 5 |
| Paths | 4 |
| Total Lines | 170 |
| Code Lines | 117 |
| 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 |
||
| 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 | ), |
||
| 273 | ) |
||
| 274 | ); |
||
| 275 | |||
| 276 | if ( false !== \lsx_health_plan\functions\get_option( 'exercise_enabled', false ) ) { |
||
| 277 | $cmb_group->add_group_field( |
||
| 278 | $group_field_id, |
||
|
|
|||
| 279 | array( |
||
| 280 | 'name' => __( 'Exercise related to this workout', 'lsx-health-plan' ), |
||
| 281 | 'id' => 'connected_exercises', |
||
| 282 | 'type' => 'post_search_ajax', |
||
| 283 | // Optional : |
||
| 284 | 'limit' => 1, // Limit selection to X items only (default 1) |
||
| 285 | 'sortable' => true, // Allow selected items to be sortable (default false) |
||
| 286 | 'query_args' => array( |
||
| 287 | 'post_type' => array( 'exercise' ), |
||
| 288 | 'post_status' => array( 'publish' ), |
||
| 289 | 'posts_per_page' => -1, |
||
| 290 | ), |
||
| 291 | ) |
||
| 292 | ); |
||
| 293 | } else { |
||
| 294 | $cmb_group->add_group_field( |
||
| 295 | $group_field_id, |
||
| 296 | array( |
||
| 297 | 'name' => __( 'Video related to this workout', 'lsx-health-plan' ), |
||
| 298 | 'id' => 'connected_videos', |
||
| 299 | 'type' => 'post_search_ajax', |
||
| 300 | // Optional : |
||
| 301 | 'limit' => 1, // Limit selection to X items only (default 1) |
||
| 302 | 'sortable' => true, // Allow selected items to be sortable (default false) |
||
| 303 | 'query_args' => array( |
||
| 304 | 'post_type' => array( 'video' ), |
||
| 305 | 'post_status' => array( 'publish' ), |
||
| 306 | 'posts_per_page' => -1, |
||
| 307 | ), |
||
| 308 | ) |
||
| 309 | ); |
||
| 310 | $cmb_group->add_group_field( |
||
| 311 | $group_field_id, |
||
| 312 | array( |
||
| 313 | 'name' => esc_html__( 'Workout Name', 'lsx-health-plan' ), |
||
| 314 | 'id' => 'name', |
||
| 315 | 'type' => 'text', |
||
| 316 | // 'repeatable' => true, // Repeatable fields are supported w/in repeatable groups (for most types) |
||
| 317 | ) |
||
| 318 | ); |
||
| 319 | |||
| 320 | $cmb_group->add_group_field( |
||
| 321 | $group_field_id, |
||
| 322 | array( |
||
| 323 | 'name' => __( 'Description', 'lsx-health-plan' ), |
||
| 324 | 'id' => 'description', |
||
| 325 | 'type' => 'wysiwyg', |
||
| 326 | 'options' => array( |
||
| 327 | 'textarea_rows' => 2, |
||
| 328 | ), |
||
| 329 | ) |
||
| 330 | ); |
||
| 331 | } |
||
| 332 | |||
| 333 | $cmb_group->add_group_field( |
||
| 334 | $group_field_id, |
||
| 335 | array( |
||
| 336 | 'name' => esc_html__( 'Exercise title (Optional)', 'lsx-health-plan' ), |
||
| 337 | 'id' => 'alt_title', |
||
| 338 | 'type' => 'text', |
||
| 339 | ) |
||
| 340 | ); |
||
| 341 | $cmb_group->add_group_field( |
||
| 342 | $group_field_id, |
||
| 343 | array( |
||
| 344 | 'name' => esc_html__( 'Exercise Description (Optional)', 'lsx-health-plan' ), |
||
| 345 | 'id' => 'alt_description', |
||
| 346 | 'type' => 'textarea_small', |
||
| 347 | ) |
||
| 348 | ); |
||
| 349 | $cmb_group->add_group_field( |
||
| 350 | $group_field_id, |
||
| 351 | array( |
||
| 352 | 'name' => esc_html__( 'Reps / Time / Distance', 'lsx-health-plan' ), |
||
| 353 | 'id' => 'reps', |
||
| 354 | 'type' => 'text', |
||
| 355 | // 'repeatable' => true, // Repeatable fields are supported w/in repeatable groups (for most types) |
||
| 356 | ) |
||
| 357 | ); |
||
| 358 | $cmb_group->add_group_field( |
||
| 359 | $group_field_id, |
||
| 360 | array( |
||
| 361 | 'name' => __( 'Exercise Image (Optional)', 'lsx-health-plan' ), |
||
| 362 | 'id' => 'exercise_alt_thumbnail', |
||
| 363 | 'type' => 'file', |
||
| 364 | 'text' => array( |
||
| 365 | 'add_upload_file_text' => __( 'Add File', 'lsx-health-plan' ), |
||
| 366 | ), |
||
| 367 | 'desc' => __( 'Upload an image 300px x 300px in size.', 'lsx-health-plan' ), |
||
| 368 | 'query_args' => array( |
||
| 369 | 'type' => array( |
||
| 370 | 'image/gif', |
||
| 371 | 'image/jpeg', |
||
| 372 | 'image/png', |
||
| 373 | ), |
||
| 374 | ), |
||
| 375 | 'preview_size' => 'thumbnail', |
||
| 376 | 'classes' => 'lsx-field-col lsx-field-add-field lsx-field-col-25', |
||
| 377 | ) |
||
| 378 | ); |
||
| 379 | |||
| 380 | $i++; |
||
| 381 | }; |
||
| 485 |