/home/techb158/on-time-movers.com/wp-content/plugins/wpforms/pro/includes/fields
Edit: /home/techb158/on-time-movers.com/wp-content/plugins/wpforms/pro/includes/fields/class-rating.php (14912B)
name = esc_html__( 'Rating', 'wpforms' );
$this->type = 'rating';
$this->icon = 'fa-star';
$this->order = 200;
$this->group = 'fancy';
// Define additional field properties.
add_filter( 'wpforms_field_properties_rating', array( $this, 'field_properties' ), 5, 3 );
// Customize value format for HTML emails.
add_filter( 'wpforms_html_field_value', array( $this, 'html_email_value' ), 10, 4 );
}
/**
* Define additional field properties.
*
* @since 1.4.4
*
* @param array $properties Field properties.
* @param array $field Field settings.
* @param array $form_data Form data and settings.
*
* @return array
*/
public function field_properties( $properties, $field, $form_data ) {
// Primary input: set screen reader text class.
$properties['inputs']['primary']['class'][] = 'wpforms-screen-reader-element';
// Rating scale.
$properties['inputs']['primary']['rating']['scale'] = ! empty( $field['scale'] ) ? esc_attr( $field['scale'] ) : 5;
// Rating icon color.
$properties['inputs']['primary']['rating']['color'] = ! empty( $field['icon_color'] ) ? esc_attr( $field['icon_color'] ) : '#e27730';
// Rating icons size.
$properties['inputs']['primary']['rating']['size'] = '28'; // Default size.
if ( ! empty( $field['icon_size'] ) && 'small' === $field['icon_size'] ) {
$properties['inputs']['primary']['rating']['size'] = '18';
} elseif ( ! empty( $field['icon_size'] ) && 'large' === $field['icon_size'] ) {
$properties['inputs']['primary']['rating']['size'] = '38';
}
// Rating icon SVG image.
$properties['inputs']['primary']['rating']['svg'] = '
';
if ( ! empty( $field['icon'] ) && 'heart' === $field['icon'] ) {
$properties['inputs']['primary']['rating']['svg'] = '
';
} elseif ( ! empty( $field['icon'] ) && 'thumb' === $field['icon'] ) {
$properties['inputs']['primary']['rating']['svg'] = '
';
} elseif ( ! empty( $field['icon'] ) && 'smiley' === $field['icon'] ) {
$properties['inputs']['primary']['rating']['svg'] = '
';
}
return $properties;
}
/**
* Customize format for HTML email notifications and entry details.
*
* @since 1.4.4
*
* @param string $val The value.
* @param array $field Field.
* @param array $form_data Form data settings.
* @param string $context Context usage.
*
* @return string
*/
public function html_email_value( $val, $field, $form_data = array(), $context = '' ) {
if ( ! empty( $field['value'] ) && 'rating' === $field['type'] && apply_filters( 'wpforms_rating_field_emoji', true ) ) {
// Determine emoji to use.
switch ( $field['icon'] ) {
case 'star':
$emoji = '⭐';
break;
case 'heart':
$emoji = '❤️';
break;
case 'thumb':
$emoji = '👍';
break;
default:
$emoji = '🙂';
break;
}
if ( 'entry-table' === $context ) {
// For the entry list table, lighten the scale display.
return sprintf(
'%s
(%d/%d)',
str_repeat( $emoji, absint( $field['value'] ) ),
absint( $field['value'] ),
absint( $field['scale'] )
);
}
return sprintf(
'%s (%d/%d)',
str_repeat( $emoji, absint( $field['value'] ) ),
absint( $field['value'] ),
absint( $field['scale'] )
);
}
return $val;
}
/**
* Field options panel inside the builder.
*
* @since 1.4.4
*
* @param array $field Field settings.
*/
public function field_options( $field ) {
/*
* Basic field options.
*/
// Options open markup.
$this->field_option(
'basic-options',
$field,
array(
'markup' => 'open',
)
);
// Label.
$this->field_option( 'label', $field );
// Description.
$this->field_option( 'description', $field );
// Scale.
$lbl = $this->field_element(
'label',
$field,
array(
'slug' => 'scale',
'value' => esc_html__( 'Scale', 'wpforms' ),
'tooltip' => esc_html__( 'Select rating scale', 'wpforms' ),
),
false
);
$fld = $this->field_element(
'select',
$field,
array(
'slug' => 'scale',
'value' => ! empty( $field['scale'] ) ? esc_attr( $field['scale'] ) : '5',
'options' => array(
'2' => '2',
'3' => '3',
'4' => '4',
'5' => '5',
'6' => '6',
'7' => '7',
'8' => '8',
'9' => '9',
'10' => '10',
),
),
false
);
$this->field_element(
'row',
$field,
array(
'slug' => 'scale',
'content' => $lbl . $fld,
)
);
// Required toggle.
$this->field_option( 'required', $field );
// Options close markup.
$this->field_option(
'basic-options',
$field,
array(
'markup' => 'close',
)
);
/*
* Advanced field options.
*/
// Options open markup.
$this->field_option(
'advanced-options',
$field,
array(
'markup' => 'open',
)
);
// Icon.
$lbl = $this->field_element(
'label',
$field,
array(
'slug' => 'icon',
'value' => esc_html__( 'Icon', 'wpforms' ),
'tooltip' => esc_html__( 'Select icon to display', 'wpforms' ),
),
false
);
$fld = $this->field_element(
'select',
$field,
array(
'slug' => 'icon',
'value' => ! empty( $field['icon'] ) ? esc_attr( $field['icon'] ) : 'star',
'options' => array(
'star' => esc_html__( 'Star', 'wpforms' ),
'heart' => esc_html__( 'Heart', 'wpforms' ),
'thumb' => esc_html__( 'Thumb', 'wpforms' ),
'smiley' => esc_html__( 'Smiley Face', 'wpforms' ),
),
),
false
);
$this->field_element(
'row',
$field,
array(
'slug' => 'icon',
'content' => $lbl . $fld,
)
);
// Icon size.
$lbl = $this->field_element(
'label',
$field,
array(
'slug' => 'icon_size',
'value' => esc_html__( 'Icon Size', 'wpforms' ),
'tooltip' => esc_html__( 'Select the size of the rating icon', 'wpforms' ),
),
false
);
$fld = $this->field_element(
'select',
$field,
array(
'slug' => 'icon_size',
'value' => ! empty( $field['icon_size'] ) ? esc_attr( $field['icon_size'] ) : 'medium',
'options' => array(
'small' => esc_html__( 'Small', 'wpforms' ),
'medium' => esc_html__( 'Medium', 'wpforms' ),
'large' => esc_html__( 'Large', 'wpforms' ),
),
),
false
);
$this->field_element(
'row',
$field,
array(
'slug' => 'icon_size',
'content' => $lbl . $fld,
)
);
// Icon color picker.
$lbl = $this->field_element(
'label',
$field,
array(
'slug' => 'icon_color',
'value' => esc_html__( 'Icon Color', 'wpforms' ),
'tooltip' => esc_html__( 'Select the color for the rating icon', 'wpforms' ),
),
false
);
$fld = $this->field_element(
'text',
$field,
array(
'slug' => 'icon_color',
'value' => ! empty( $field['icon_color'] ) ? esc_attr( $field['icon_color'] ) : '#e27730',
'class' => 'wpforms-color-picker',
),
false
);
$this->field_element(
'row',
$field,
array(
'slug' => 'icon_color',
'content' => $lbl . $fld,
'class' => 'color-picker-row',
)
);
// Custom CSS classes.
$this->field_option( 'css', $field );
// Hide label.
$this->field_option( 'label_hide', $field );
// Options close markup.
$this->field_option(
'advanced-options',
$field,
[
'markup' => 'close',
]
);
}
/**
* Field preview inside the builder.
*
* @since 1.4.4
*
* @param array $field Field settings.
*/
public function field_preview( $field ) {
// Define data.
$scale = ! empty( $field['scale'] ) ? esc_attr( $field['scale'] ) : 5;
$icon = ! empty( $field['icon'] ) ? esc_attr( $field['icon'] ) : 'star';
$icon_size = ! empty( $field['icon_size'] ) ? esc_attr( $field['icon_size'] ) : 'medium';
$icon_color = ! empty( $field['icon_color'] ) ? esc_attr( $field['icon_color'] ) : '#e27730';
$icon_class = '';
$icon_size_css = '';
// Set icon class.
switch ( $icon ) {
case 'star':
$icon_class = 'fa-star';
break;
case 'heart':
$icon_class = 'fa-heart';
break;
case 'thumb':
$icon_class = 'fa-thumbs-up';
break;
case 'smiley':
$icon_class = 'fa-smile-o';
break;
}
// Set icon size.
switch ( $icon_size ) {
case 'small':
$icon_size_css = '18';
break;
case 'medium':
$icon_size_css = '28';
break;
case 'large':
$icon_size_css = '38';
break;
}
// Label.
$this->field_preview_option( 'label', $field );
// Primary input.
for ( $i = 1; $i <= 10; $i++ ) {
printf(
'
',
$icon_class,
$icon_size,
$icon_color,
$i <= $scale ? 'inline-block' : 'none',
$icon_size_css
);
}
// Description.
$this->field_preview_option( 'description', $field );
}
/**
* Field display on the form front-end.
*
* @since 1.4.4
*
* @param array $field Field settings.
* @param array $deprecated Deprecated, don't use.
* @param array $form_data Form data and settings.
*/
public function field_display( $field, $deprecated, $form_data ) {
// Define data.
$primary = $field['properties']['inputs']['primary'];
$rating = $primary['rating'];
$svg = $rating['svg'];
$scale = ! empty( $rating['scale'] ) ? absint( $rating['scale'] ) : 5;
// Apply our customizations to the SVG.
$svg = str_replace( 'width=""', 'width="' . absint( $rating['size'] ) . '"', $svg );
$svg = str_replace( 'height=""', 'height="' . absint( $rating['size'] ) . '"', $svg );
$svg = str_replace( 'style=""', 'style="height:' . absint( $rating['size'] ) . 'px;width:' . absint( $rating['size'] ) . 'px;"', $svg );
$svg = str_replace( 'fill=""', 'fill="currentColor" color="' . wpforms_sanitize_hex_color( $rating['color'] ) . '"', $svg );
echo '
';
// Generate each rating icon/element.
for ( $i = 1; $i <= $scale; $i++ ) {
printf(
'';
}
echo '
';
}
/**
* @inheritdoc
*/
protected function get_field_populated_single_property_value( $raw_value, $input, $properties, $field ) {
if ( ! is_string( $raw_value ) ) {
return $properties;
}
$properties['inputs'][ $input ]['rating']['default'] = (int) $raw_value;
return $properties;
}
/**
* Format field.
*
* @since 1.4.4
*
* @param int $field_id Field ID.
* @param array $field_submit Submitted field value.
* @param array $form_data Form data and settings.
*/
public function format( $field_id, $field_submit, $form_data ) {
// Define data.
$name = ! empty( $form_data['fields'][ $field_id ]['label'] ) ? $form_data['fields'][ $field_id ]['label'] : '';
$value = ! empty( $field_submit ) ? absint( $field_submit ) : '';
$scale = absint( $form_data['fields'][ $field_id ]['scale'] );
if ( $value > $scale ) {
$value = '';
}
// Set final field details.
wpforms()->process->fields[ $field_id ] = array(
'name' => sanitize_text_field( $name ),
'value' => sanitize_text_field( $value ),
'id' => absint( $field_id ),
'type' => $this->type,
'scale' => sanitize_text_field( $scale ),
'icon' => sanitize_text_field( $form_data['fields'][ $field_id ]['icon'] ),
);
}
}
new WPForms_Rating_Text();