Conditions | 1 |
Paths | 1 |
Total Lines | 234 |
Code Lines | 24 |
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 |
||
335 | <# } else if ( 'checkbox' === field.type ) { #> |
||
336 | |||
337 | <label> |
||
338 | <input type="checkbox" value="true" data-field="{{{ field.id }}}" <# if ( field.default ) { #> checked="checked" <# } #> /> {{ field.label }} |
||
339 | <# if ( field.description ) { #> |
||
340 | {{ field.description }} |
||
341 | <# } #> |
||
342 | </label> |
||
343 | |||
344 | <# } else if ( 'select' === field.type ) { #> |
||
345 | |||
346 | <label> |
||
347 | <# if ( field.label ) { #> |
||
348 | <span class="customize-control-title">{{ field.label }}</span> |
||
349 | <# } #> |
||
350 | <# if ( field.description ) { #> |
||
351 | <span class="description customize-control-description">{{ field.description }}</span> |
||
352 | <# } #> |
||
353 | <select data-field="{{{ field.id }}}"> |
||
354 | <# _.each( field.choices, function( choice, i ) { #> |
||
355 | <option value="{{{ i }}}" <# if ( field.default == i ) { #> selected="selected" <# } #>>{{ choice }}</option> |
||
356 | <# }); #> |
||
357 | </select> |
||
358 | </label> |
||
359 | |||
360 | <# } else if ( 'dropdown-pages' === field.type ) { #> |
||
361 | |||
362 | <label> |
||
363 | <# if ( field.label ) { #> |
||
364 | <span class="customize-control-title">{{{ data.label }}}</span> |
||
365 | <# } #> |
||
366 | <# if ( field.description ) { #> |
||
367 | <span class="description customize-control-description">{{{ field.description }}}</span> |
||
368 | <# } #> |
||
369 | <div class="customize-control-content repeater-dropdown-pages">{{{ field.dropdown }}}</div> |
||
370 | </label> |
||
371 | |||
372 | <# } else if ( 'radio' === field.type ) { #> |
||
373 | |||
374 | <label> |
||
375 | <# if ( field.label ) { #> |
||
376 | <span class="customize-control-title">{{ field.label }}</span> |
||
377 | <# } #> |
||
378 | <# if ( field.description ) { #> |
||
379 | <span class="description customize-control-description">{{ field.description }}</span> |
||
380 | <# } #> |
||
381 | |||
382 | <# _.each( field.choices, function( choice, i ) { #> |
||
383 | <label> |
||
384 | <input type="radio" name="{{{ field.id }}}{{ index }}" data-field="{{{ field.id }}}" value="{{{ i }}}" <# if ( field.default == i ) { #> checked="checked" <# } #>> {{ choice }} <br/> |
||
385 | </label> |
||
386 | <# }); #> |
||
387 | </label> |
||
388 | |||
389 | <# } else if ( 'radio-image' === field.type ) { #> |
||
390 | |||
391 | <label> |
||
392 | <# if ( field.label ) { #> |
||
393 | <span class="customize-control-title">{{ field.label }}</span> |
||
394 | <# } #> |
||
395 | <# if ( field.description ) { #> |
||
396 | <span class="description customize-control-description">{{ field.description }}</span> |
||
397 | <# } #> |
||
398 | |||
399 | <# _.each( field.choices, function( choice, i ) { #> |
||
400 | <input type="radio" id="{{{ field.id }}}_{{ index }}_{{{ i }}}" name="{{{ field.id }}}{{ index }}" data-field="{{{ field.id }}}" value="{{{ i }}}" <# if ( field.default == i ) { #> checked="checked" <# } #>> |
||
401 | <label for="{{{ field.id }}}_{{ index }}_{{{ i }}}"> |
||
402 | <img src="{{ choice }}"> |
||
403 | </label> |
||
404 | </input> |
||
405 | <# }); #> |
||
406 | </label> |
||
407 | |||
408 | <# } else if ( 'color' === field.type ) { #> |
||
409 | |||
410 | <# var defaultValue = ''; |
||
411 | if ( field.default ) { |
||
412 | if ( '#' !== field.default.substring( 0, 1 ) ) { |
||
413 | defaultValue = '#' + field.default; |
||
414 | } else { |
||
415 | defaultValue = field.default; |
||
416 | } |
||
417 | defaultValue = ' data-default-color=' + defaultValue; // Quotes added automatically. |
||
418 | } #> |
||
419 | <label> |
||
420 | <# if ( field.label ) { #> |
||
421 | <span class="customize-control-title">{{{ field.label }}}</span> |
||
422 | <# } #> |
||
423 | <# if ( field.description ) { #> |
||
424 | <span class="description customize-control-description">{{{ field.description }}}</span> |
||
425 | <# } #> |
||
426 | <input class="color-picker-hex" type="text" maxlength="7" placeholder="<?php echo esc_attr( $this->l10n( 'hex-value' ) ); ?>" value="{{{ field.default }}}" data-field="{{{ field.id }}}" {{ defaultValue }} /> |
||
427 | |||
428 | </label> |
||
429 | |||
430 | <# } else if ( 'textarea' === field.type ) { #> |
||
431 | |||
432 | <# if ( field.label ) { #> |
||
433 | <span class="customize-control-title">{{ field.label }}</span> |
||
434 | <# } #> |
||
435 | <# if ( field.description ) { #> |
||
436 | <span class="description customize-control-description">{{ field.description }}</span> |
||
437 | <# } #> |
||
438 | <textarea rows="5" data-field="{{{ field.id }}}">{{ field.default }}</textarea> |
||
439 | |||
440 | <# } else if ( field.type === 'image' || field.type === 'cropped_image' ) { #> |
||
441 | |||
442 | <label> |
||
443 | <# if ( field.label ) { #> |
||
444 | <span class="customize-control-title">{{ field.label }}</span> |
||
445 | <# } #> |
||
446 | <# if ( field.description ) { #> |
||
447 | <span class="description customize-control-description">{{ field.description }}</span> |
||
448 | <# } #> |
||
449 | </label> |
||
450 | |||
451 | <figure class="kirki-image-attachment" data-placeholder="<?php echo esc_attr( $this->l10n( 'no-image-selected' ) ); ?>" > |
||
452 | <# if ( field.default ) { #> |
||
453 | <# var defaultImageURL = ( field.default.url ) ? field.default.url : field.default; #> |
||
454 | <img src="{{{ defaultImageURL }}}"> |
||
455 | <# } else { #> |
||
456 | <?php echo esc_attr( $this->l10n( 'no-image-selected' ) ); ?> |
||
457 | <# } #> |
||
458 | </figure> |
||
459 | |||
460 | <div class="actions"> |
||
461 | <button type="button" class="button remove-button<# if ( ! field.default ) { #> hidden<# } #>"><?php echo esc_attr( $this->l10n( 'remove' ) ); ?></button> |
||
462 | <button type="button" class="button upload-button" data-label=" <?php echo esc_attr( $this->l10n( 'add-image' ) ); ?>" data-alt-label="<?php echo esc_attr( $this->l10n( 'change-image' ) ); ?>" > |
||
463 | <# if ( field.default ) { #> |
||
464 | <?php echo esc_attr( $this->l10n( 'change-image' ) ); ?> |
||
465 | <# } else { #> |
||
466 | <?php echo esc_attr( $this->l10n( 'add-image' ) ); ?> |
||
467 | <# } #> |
||
468 | </button> |
||
469 | <# if ( field.default.id ) { #> |
||
470 | <input type="hidden" class="hidden-field" value="{{{ field.default.id }}}" data-field="{{{ field.id }}}" > |
||
471 | <# } else { #> |
||
472 | <input type="hidden" class="hidden-field" value="{{{ field.default }}}" data-field="{{{ field.id }}}" > |
||
473 | <# } #> |
||
474 | </div> |
||
475 | |||
476 | <# } else if ( field.type === 'upload' ) { #> |
||
477 | |||
478 | <label> |
||
479 | <# if ( field.label ) { #> |
||
480 | <span class="customize-control-title">{{ field.label }}</span> |
||
481 | <# } #> |
||
482 | <# if ( field.description ) { #> |
||
483 | <span class="description customize-control-description">{{ field.description }}</span> |
||
484 | <# } #> |
||
485 | </label> |
||
486 | |||
487 | <figure class="kirki-file-attachment" data-placeholder="<?php echo esc_attr( $this->l10n( 'no-file-selected' ) ); ?>" > |
||
488 | <# if ( field.default ) { #> |
||
489 | <# var defaultFilename = ( field.default.filename ) ? field.default.filename : field.default; #> |
||
490 | <span class="file"><span class="dashicons dashicons-media-default"></span> {{ defaultFilename }}</span> |
||
491 | <# } else { #> |
||
492 | <?php echo esc_attr( $this->l10n( 'no-file-selected' ) ); ?> |
||
493 | <# } #> |
||
494 | </figure> |
||
495 | |||
496 | <div class="actions"> |
||
497 | <button type="button" class="button remove-button<# if ( ! field.default ) { #> hidden<# } #>"></button> |
||
498 | <button type="button" class="button upload-button" data-label="<?php echo esc_attr( $this->l10n( 'add-file' ) ); ?>" data-alt-label="<?php echo esc_attr( $this->l10n( 'change-file' ) ); ?>" > |
||
499 | <# if ( field.default ) { #> |
||
500 | <?php echo esc_attr( $this->l10n( 'change-file' ) ); ?> |
||
501 | <# } else { #> |
||
502 | <?php echo esc_attr( $this->l10n( 'add-file' ) ); ?> |
||
503 | <# } #> |
||
504 | </button> |
||
505 | <# if ( field.default.id ) { #> |
||
506 | <input type="hidden" class="hidden-field" value="{{{ field.default.id }}}" data-field="{{{ field.id }}}" > |
||
507 | <# } else { #> |
||
508 | <input type="hidden" class="hidden-field" value="{{{ field.default }}}" data-field="{{{ field.id }}}" > |
||
509 | <# } #> |
||
510 | </div> |
||
511 | |||
512 | <# } else if ( 'custom' === field.type ) { #> |
||
513 | |||
514 | <# if ( field.label ) { #> |
||
515 | <span class="customize-control-title">{{ field.label }}</span> |
||
516 | <# } #> |
||
517 | <# if ( field.description ) { #> |
||
518 | <span class="description customize-control-description">{{ field.description }}</span> |
||
519 | <# } #> |
||
520 | <div data-field="{{{ field.id }}}">{{{ field.default }}}</div> |
||
521 | |||
522 | <# } #> |
||
523 | |||
524 | </div> |
||
525 | <# }); #> |
||
526 | <button type="button" class="button-link repeater-row-remove"><?php echo esc_attr( $this->l10n( 'remove' ) ); ?></button> |
||
527 | </div> |
||
528 | </li> |
||
529 | </script> |
||
530 | <?php |
||
531 | } |
||
532 | |||
533 | /** |
||
534 | * Validate row-labels. |
||
535 | * |
||
536 | * @access protected |
||
537 | * @since 2.4.0 |
||
538 | * @param array $args {@see WP_Customize_Control::__construct}. |
||
539 | */ |
||
540 | protected function row_label( $args ) { |
||
541 | |||
542 | // Validating args for row labels. |
||
543 | if ( isset( $args['row_label'] ) && is_array( $args['row_label'] ) && ! empty( $args['row_label'] ) ) { |
||
544 | |||
545 | // Validating row label type. |
||
546 | if ( isset( $args['row_label']['type'] ) && ( 'text' === $args['row_label']['type'] || 'field' === $args['row_label']['type'] ) ) { |
||
547 | $this->row_label['type'] = $args['row_label']['type']; |
||
548 | } |
||
549 | |||
550 | // Validating row label type. |
||
551 | if ( isset( $args['row_label']['value'] ) && ! empty( $args['row_label']['value'] ) ) { |
||
552 | $this->row_label['value'] = esc_attr( $args['row_label']['value'] ); |
||
553 | } |
||
554 | |||
555 | // Validating row label field. |
||
556 | if ( isset( $args['row_label']['field'] ) && ! empty( $args['row_label']['field'] ) && isset( $args['fields'][ esc_attr( $args['row_label']['field'] ) ] ) ) { |
||
557 | $this->row_label['field'] = esc_attr( $args['row_label']['field'] ); |
||
558 | } else { |
||
559 | // If from field is not set correctly, making sure standard is set as the type. |
||
560 | $this->row_label['type'] = 'text'; |
||
561 | } |
||
562 | } |
||
563 | } |
||
564 | |||
565 | /** |
||
566 | * Returns an array of translation strings. |
||
567 | * |
||
568 | * @access protected |
||
569 | * @since 2.4.0 |
||
595 |