Conditions | 1 |
Paths | 1 |
Total Lines | 233 |
Code Lines | 23 |
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 |
||
294 | public function repeater_js_template() { |
||
295 | ?> |
||
296 | <script type="text/html" class="customize-control-repeater-content"> |
||
297 | <# var field; var index = data.index; #> |
||
298 | |||
299 | <li class="repeater-row minimized" data-row="{{{ index }}}"> |
||
300 | |||
301 | <div class="repeater-row-header"> |
||
302 | <span class="repeater-row-label"></span> |
||
303 | <i class="dashicons dashicons-arrow-down repeater-minimize"></i> |
||
304 | </div> |
||
305 | <div class="repeater-row-content"> |
||
306 | <# _.each( data, function( field, i ) { #> |
||
307 | |||
308 | <div class="repeater-field repeater-field-{{{ field.type }}}"> |
||
309 | |||
310 | <# if ( 'text' === field.type || 'url' === field.type || 'link' === field.type || 'email' === field.type || 'tel' === field.type || 'date' === field.type ) { #> |
||
311 | |||
312 | <# if ( 'link' === field.type ) { #> |
||
313 | <# field.type = 'url' #> |
||
314 | <# } #> |
||
315 | |||
316 | <label> |
||
317 | <# if ( field.label ) { #> |
||
318 | <span class="customize-control-title">{{ field.label }}</span> |
||
319 | <# } #> |
||
320 | <# if ( field.description ) { #> |
||
321 | <span class="description customize-control-description">{{ field.description }}</span> |
||
322 | <# } #> |
||
323 | <input type="{{field.type}}" name="" value="{{{ field.default }}}" data-field="{{{ field.id }}}"> |
||
324 | </label> |
||
325 | |||
326 | <# } else if ( 'hidden' === field.type ) { #> |
||
327 | |||
328 | <input type="hidden" data-field="{{{ field.id }}}" <# if ( field.default ) { #> value="{{{ field.default }}}" <# } #> /> |
||
329 | |||
330 | <# } else if ( 'checkbox' === field.type ) { #> |
||
331 | |||
332 | <label> |
||
333 | <input type="checkbox" value="true" data-field="{{{ field.id }}}" <# if ( field.default ) { #> checked="checked" <# } #> /> {{ field.label }} |
||
334 | <# if ( field.description ) { #> |
||
335 | {{ field.description }} |
||
336 | <# } #> |
||
337 | </label> |
||
338 | |||
339 | <# } else if ( 'select' === field.type ) { #> |
||
340 | |||
341 | <label> |
||
342 | <# if ( field.label ) { #> |
||
343 | <span class="customize-control-title">{{ field.label }}</span> |
||
344 | <# } #> |
||
345 | <# if ( field.description ) { #> |
||
346 | <span class="description customize-control-description">{{ field.description }}</span> |
||
347 | <# } #> |
||
348 | <select data-field="{{{ field.id }}}"> |
||
349 | <# _.each( field.choices, function( choice, i ) { #> |
||
350 | <option value="{{{ i }}}" <# if ( field.default == i ) { #> selected="selected" <# } #>>{{ choice }}</option> |
||
351 | <# }); #> |
||
352 | </select> |
||
353 | </label> |
||
354 | |||
355 | <# } else if ( 'dropdown-pages' === field.type ) { #> |
||
356 | |||
357 | <label> |
||
358 | <# if ( field.label ) { #> |
||
359 | <span class="customize-control-title">{{{ data.label }}}</span> |
||
360 | <# } #> |
||
361 | <# if ( field.description ) { #> |
||
362 | <span class="description customize-control-description">{{{ field.description }}}</span> |
||
363 | <# } #> |
||
364 | <div class="customize-control-content repeater-dropdown-pages">{{{ field.dropdown }}}</div> |
||
365 | </label> |
||
366 | |||
367 | <# } else if ( 'radio' === field.type ) { #> |
||
368 | |||
369 | <label> |
||
370 | <# if ( field.label ) { #> |
||
371 | <span class="customize-control-title">{{ field.label }}</span> |
||
372 | <# } #> |
||
373 | <# if ( field.description ) { #> |
||
374 | <span class="description customize-control-description">{{ field.description }}</span> |
||
375 | <# } #> |
||
376 | |||
377 | <# _.each( field.choices, function( choice, i ) { #> |
||
378 | <label> |
||
379 | <input type="radio" name="{{{ field.id }}}{{ index }}" data-field="{{{ field.id }}}" value="{{{ i }}}" <# if ( field.default == i ) { #> checked="checked" <# } #>> {{ choice }} <br/> |
||
380 | </label> |
||
381 | <# }); #> |
||
382 | </label> |
||
383 | |||
384 | <# } else if ( 'radio-image' === field.type ) { #> |
||
385 | |||
386 | <label> |
||
387 | <# if ( field.label ) { #> |
||
388 | <span class="customize-control-title">{{ field.label }}</span> |
||
389 | <# } #> |
||
390 | <# if ( field.description ) { #> |
||
391 | <span class="description customize-control-description">{{ field.description }}</span> |
||
392 | <# } #> |
||
393 | |||
394 | <# _.each( field.choices, function( choice, i ) { #> |
||
395 | <input type="radio" id="{{{ field.id }}}_{{ index }}_{{{ i }}}" name="{{{ field.id }}}{{ index }}" data-field="{{{ field.id }}}" value="{{{ i }}}" <# if ( field.default == i ) { #> checked="checked" <# } #>> |
||
396 | <label for="{{{ field.id }}}_{{ index }}_{{{ i }}}"> |
||
397 | <img src="{{ choice }}"> |
||
398 | </label> |
||
399 | </input> |
||
400 | <# }); #> |
||
401 | </label> |
||
402 | |||
403 | <# } else if ( 'color' === field.type ) { #> |
||
404 | |||
405 | <# var defaultValue = ''; |
||
406 | if ( field.default ) { |
||
407 | if ( '#' !== field.default.substring( 0, 1 ) ) { |
||
408 | defaultValue = '#' + field.default; |
||
409 | } else { |
||
410 | defaultValue = field.default; |
||
411 | } |
||
412 | defaultValue = ' data-default-color=' + defaultValue; // Quotes added automatically. |
||
413 | } #> |
||
414 | <label> |
||
415 | <# if ( field.label ) { #> |
||
416 | <span class="customize-control-title">{{{ field.label }}}</span> |
||
417 | <# } #> |
||
418 | <# if ( field.description ) { #> |
||
419 | <span class="description customize-control-description">{{{ field.description }}}</span> |
||
420 | <# } #> |
||
421 | <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 }} /> |
||
422 | |||
423 | </label> |
||
424 | |||
425 | <# } else if ( 'textarea' === field.type ) { #> |
||
426 | |||
427 | <# if ( field.label ) { #> |
||
428 | <span class="customize-control-title">{{ field.label }}</span> |
||
429 | <# } #> |
||
430 | <# if ( field.description ) { #> |
||
431 | <span class="description customize-control-description">{{ field.description }}</span> |
||
432 | <# } #> |
||
433 | <textarea rows="5" data-field="{{{ field.id }}}">{{ field.default }}</textarea> |
||
434 | |||
435 | <# } else if ( field.type === 'image' || field.type === 'cropped_image' ) { #> |
||
436 | |||
437 | <label> |
||
438 | <# if ( field.label ) { #> |
||
439 | <span class="customize-control-title">{{ field.label }}</span> |
||
440 | <# } #> |
||
441 | <# if ( field.description ) { #> |
||
442 | <span class="description customize-control-description">{{ field.description }}</span> |
||
443 | <# } #> |
||
444 | </label> |
||
445 | |||
446 | <figure class="kirki-image-attachment" data-placeholder="<?php echo esc_attr( $this->l10n( 'no-image-selected' ) ); ?>" > |
||
447 | <# if ( field.default ) { #> |
||
448 | <# var defaultImageURL = ( field.default.url ) ? field.default.url : field.default; #> |
||
449 | <img src="{{{ defaultImageURL }}}"> |
||
450 | <# } else { #> |
||
451 | <?php echo esc_attr( $this->l10n( 'no-image-selected' ) ); ?> |
||
452 | <# } #> |
||
453 | </figure> |
||
454 | |||
455 | <div class="actions"> |
||
456 | <button type="button" class="button remove-button<# if ( ! field.default ) { #> hidden<# } #>"><?php echo esc_attr( $this->l10n( 'remove' ) ); ?></button> |
||
457 | <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' ) ); ?>" > |
||
458 | <# if ( field.default ) { #> |
||
459 | <?php echo esc_attr( $this->l10n( 'change-image' ) ); ?> |
||
460 | <# } else { #> |
||
461 | <?php echo esc_attr( $this->l10n( 'add-image' ) ); ?> |
||
462 | <# } #> |
||
463 | </button> |
||
464 | <# if ( field.default.id ) { #> |
||
465 | <input type="hidden" class="hidden-field" value="{{{ field.default.id }}}" data-field="{{{ field.id }}}" > |
||
466 | <# } else { #> |
||
467 | <input type="hidden" class="hidden-field" value="{{{ field.default }}}" data-field="{{{ field.id }}}" > |
||
468 | <# } #> |
||
469 | </div> |
||
470 | |||
471 | <# } else if ( field.type === 'upload' ) { #> |
||
472 | |||
473 | <label> |
||
474 | <# if ( field.label ) { #> |
||
475 | <span class="customize-control-title">{{ field.label }}</span> |
||
476 | <# } #> |
||
477 | <# if ( field.description ) { #> |
||
478 | <span class="description customize-control-description">{{ field.description }}</span> |
||
479 | <# } #> |
||
480 | </label> |
||
481 | |||
482 | <figure class="kirki-file-attachment" data-placeholder="<?php echo esc_attr( $this->l10n( 'no-file-selected' ) ); ?>" > |
||
483 | <# if ( field.default ) { #> |
||
484 | <# var defaultFilename = ( field.default.filename ) ? field.default.filename : field.default; #> |
||
485 | <span class="file"><span class="dashicons dashicons-media-default"></span> {{ defaultFilename }}</span> |
||
486 | <# } else { #> |
||
487 | <?php echo esc_attr( $this->l10n( 'no-file-selected' ) ); ?> |
||
488 | <# } #> |
||
489 | </figure> |
||
490 | |||
491 | <div class="actions"> |
||
492 | <button type="button" class="button remove-button<# if ( ! field.default ) { #> hidden<# } #>"></button> |
||
493 | <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' ) ); ?>" > |
||
494 | <# if ( field.default ) { #> |
||
495 | <?php echo esc_attr( $this->l10n( 'change-file' ) ); ?> |
||
496 | <# } else { #> |
||
497 | <?php echo esc_attr( $this->l10n( 'add-file' ) ); ?> |
||
498 | <# } #> |
||
499 | </button> |
||
500 | <# if ( field.default.id ) { #> |
||
501 | <input type="hidden" class="hidden-field" value="{{{ field.default.id }}}" data-field="{{{ field.id }}}" > |
||
502 | <# } else { #> |
||
503 | <input type="hidden" class="hidden-field" value="{{{ field.default }}}" data-field="{{{ field.id }}}" > |
||
504 | <# } #> |
||
505 | </div> |
||
506 | |||
507 | <# } else if ( 'custom' === field.type ) { #> |
||
508 | |||
509 | <# if ( field.label ) { #> |
||
510 | <span class="customize-control-title">{{ field.label }}</span> |
||
511 | <# } #> |
||
512 | <# if ( field.description ) { #> |
||
513 | <span class="description customize-control-description">{{ field.description }}</span> |
||
514 | <# } #> |
||
515 | <div data-field="{{{ field.id }}}">{{{ field.default }}}</div> |
||
516 | |||
517 | <# } #> |
||
518 | |||
519 | </div> |
||
520 | <# }); #> |
||
521 | <button type="button" class="button-link repeater-row-remove"><?php echo esc_attr( $this->l10n( 'remove' ) ); ?></button> |
||
522 | </div> |
||
523 | </li> |
||
524 | </script> |
||
525 | <?php |
||
526 | } |
||
527 | |||
590 |