/home/vianto5/heredit.mx/wp-content/plugins/wpforms/src/Pro/Forms/Fields/Rating
NameSizeModeActions
Field.php118370644editdlrm
Edit: /home/vianto5/heredit.mx/wp-content/plugins/wpforms/src/Pro/Forms/Fields/Rating/Field.php (11837B)
get_icon_size_css( $icon_size ); // Null 'for' value for label as there no input for it. unset( $properties['label']['attr']['for'] ); // Rating icon SVG image. $properties['inputs']['primary']['rating']['svg'] = ''; if ( ! empty( $field['icon'] ) && $field['icon'] === 'heart' ) { $properties['inputs']['primary']['rating']['svg'] = ''; } elseif ( ! empty( $field['icon'] ) && $field['icon'] === 'thumb' ) { $properties['inputs']['primary']['rating']['svg'] = ''; } elseif ( ! empty( $field['icon'] ) && $field['icon'] === 'smiley' ) { $properties['inputs']['primary']['rating']['svg'] = ''; } return $properties; } /** * Customize a format for HTML email notifications and entry details. * * @since 1.9.4 * * @param string|mixed $val The value. * @param array $field Field. * @param array $form_data Form data settings. * @param string $context Context usage. * * @return string * @noinspection PhpMissingParamTypeInspection * @noinspection PhpUnusedParameterInspection */ public function html_email_value( $val, $field, $form_data = [], $context = '' ): string { $val = (string) $val; /** * Filter to enable/disable emoji usage for the rating field. * * @since 1.4.4 * * @param bool $use_emoji Whether to use emoji or not. Default is true. */ $use_emoji = apply_filters( 'wpforms_rating_field_emoji', true ); // phpcs:ignore WPForms.PHP.ValidateHooks.InvalidHookName if ( ! empty( $field['value'] ) && $field['type'] === 'rating' && $use_emoji ) { // Determine emoji to use. switch ( $field['icon'] ) { case 'star': $emoji = '⭐'; break; case 'heart': $emoji = '❤️'; break; case 'thumb': $emoji = '👍'; break; default: $emoji = '🙂'; break; } if ( $context === 'entry-table' ) { // 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 display on the form front-end. * * @since 1.9.4 * * @param array $field Field settings. * @param array $deprecated Deprecated, don't use. * @param array $form_data Form data and settings. * * @noinspection HtmlUnknownAttribute */ 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; $render_engine = wpforms_get_render_engine(); $color = $rating['color'][ $render_engine ] ?? $rating['color']; // Apply our customizations to the SVG. $svg = str_replace( [ 'width=""', 'height=""', 'style=""', 'fill=""', ], [ 'width="' . absint( $rating['size'] ) . '"', 'height="' . absint( $rating['size'] ) . '"', 'style="height:' . absint( $rating['size'] ) . 'px;width:' . absint( $rating['size'] ) . 'px;"', 'fill="currentColor" color="' . wpforms_sanitize_hex_color( $color ) . '"', ], $svg ); $is_label_above = ! empty( $field['label_position'] ) && $field['label_position'] === 'above'; $wrapper_classes = [ 'wpforms-field-rating-wrapper', 'wpforms-field-rating-labels-position-' . ( $is_label_above ? 'above' : 'below' ), ]; echo '
'; // Display field labels above the rating items. if ( $is_label_above ) { $this->display_field_labels( $field ); } echo '
'; // Generate each rating icon/element. for ( $i = 1; $i <= $scale; $i++ ) { printf( ''; } echo '
'; // Display field labels below the rating items. if ( ! $is_label_above ) { $this->display_field_labels( $field ); } echo '
'; } /** * Display field labels. * * @since 1.9.8 * * @param array $field Field settings. */ private function display_field_labels( array $field ): void { if ( empty( $field['lowest_label'] ) && empty( $field['highest_label'] ) ) { return; } echo '
'; // Lowest rating label. printf( '%s', esc_html( $field['lowest_label'] ) ); // Highest rating label. printf( '%s', esc_html( $field['highest_label'] ) ); echo '
'; } /** * Public version of get_field_populated_single_property_value() to use by external classes. * * @since 1.9.4 * * @param string $raw_value Value from a GET param, always a string. * @param string $input Represent a subfield inside the field. Maybe empty. * @param array $properties Field properties. * @param array $field Current field specific data. * * @return array Modified field properties. */ protected function get_field_populated_single_property_value( $raw_value, $input, $properties, $field ): array { if ( ! is_string( $raw_value ) ) { return $properties; } $properties['inputs'][ $input ]['rating']['default'] = (int) $raw_value; return $properties; } /** * Format field. * * @since 1.9.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()->obj( 'process' )->fields[ $field_id ] = [ 'name' => sanitize_text_field( $name ), 'value' => sanitize_text_field( $value ), 'id' => wpforms_validate_field_id( $field_id ), 'type' => $this->type, 'scale' => sanitize_text_field( $scale ), 'icon' => sanitize_text_field( $form_data['fields'][ $field_id ]['icon'] ), ]; } }