| 1 |
<?php |
| 2 |
/** |
| 3 |
* Form field label. |
| 4 |
* |
| 5 |
* @package ghostkit |
| 6 |
*/ |
| 7 |
|
| 8 |
if ( ! defined( 'ABSPATH' ) ) { |
| 9 |
exit; |
| 10 |
} |
| 11 |
|
| 12 |
/** |
| 13 |
* Class GhostKit_Form_Field_Label |
| 14 |
*/ |
| 15 |
class GhostKit_Form_Field_Label { |
| 16 |
/** |
| 17 |
* Prepare label for field. |
| 18 |
* |
| 19 |
* @param array $attributes block attributes. |
| 20 |
*/ |
| 21 |
public static function get( $attributes ) { |
| 22 |
$attributes = array_merge( |
| 23 |
array( |
| 24 |
'slug' => '', |
| 25 |
'label' => '', |
| 26 |
'required' => false, |
| 27 |
'hideLabel' => false, |
| 28 |
'removeLabel' => false, |
| 29 |
'slug' => null, |
| 30 |
), |
| 31 |
$attributes |
| 32 |
); |
| 33 |
|
| 34 |
$label = $attributes['label']; |
| 35 |
$hide_label = $attributes['hideLabel']; |
| 36 |
$class = 'ghostkit-form-field-label'; |
| 37 |
|
| 38 |
if ( $label && $attributes['required'] ) { |
| 39 |
$label .= '<span class="required">*</span>'; |
| 40 |
} |
| 41 |
|
| 42 |
$label_attrs = array( |
| 43 |
'for' => $attributes['slug'], |
| 44 |
); |
| 45 |
|
| 46 |
if ( $hide_label ) { |
| 47 |
$class .= ' ghostkit-form-field-label-hidden'; |
| 48 |
} |
| 49 |
|
| 50 |
if ( $label ) { |
| 51 |
?> |
| 52 |
<?php if ( ! $attributes['removeLabel'] ) : ?> |
| 53 |
<label class="<?php echo esc_attr( $class ); ?>" <?php GhostKit_Form_Field_Attributes::get( $label_attrs ); ?>> |
| 54 |
<?php echo wp_kses_post( $label ); ?> |
| 55 |
</label> |
| 56 |
<?php endif; ?> |
| 57 |
<input type="hidden" name="<?php echo esc_attr( $attributes['slug'] ); ?>[label]" value="<?php echo esc_attr( $attributes['label'] ); ?>" /> |
| 58 |
<?php |
| 59 |
} |
| 60 |
} |
| 61 |
} |
| 62 |
new GhostKit_Form_Field_Label(); |
| 63 |
|