cloggier
↑
/wp-content/plugins/wpforms-sendinblue/src/Provider
marsupiataab
hypermuffing
cloggier
hypermuffing
marsupiataab
BaseField.php
2,723 B
cloggier
marsupiataab
DefaultField.php
2,670 B
cloggier
marsupiataab
FieldMapper.php
5,091 B
cloggier
marsupiataab
LikertScaleField.php
1,240 B
cloggier
marsupiataab
NameField.php
848 B
cloggier
marsupiataab
PasswordField.php
895 B
cloggier
marsupiataab
<?php namespace WPFormsSendinblue\Provider\CustomFields; /** * Class DefaultField. * * @since 1.0.0 */ class DefaultField extends BaseField { /** * Text format. * * @since 1.0.0 * * @return string */ protected function text() { return (string) $this->field['value']; } /** * Date format. * * @since 1.0.0 * * @return string|null */ protected function date() { $time = strtotime( $this->field['value'] ); return $time ? gmdate( 'Y-m-d', $time ) : null; } /** * Number format. * * @since 1.0.0 * * @return float|null */ protected function float() { return is_numeric( $this->field['value'] ) ? (float) $this->field['value'] : null; } /** * Category format. * * @since 1.0.0 * * @return int|null */ protected function category() { if ( empty( $this->attribute['enumeration'] ) ) { return null; } $value = $this->get_index_by_category_name(); if ( $value ) { return $value; } return $this->get_selected_index(); } /** * Boolean format. * * @since 1.0.0 * * @return bool */ protected function boolean() { return ! empty( $this->field['value'] ); } /** * Phone format. * * @since 1.0.0 * * @return string|null */ protected function phone() { return preg_replace( '/[^0-9]/', '' , $this->field['value'] ); } /** * Trying to find the index of a category by comparing the category name and value field. * * @since 1.4.0 * * @return int|null */ private function get_index_by_category_name() { // Try to find an element by label. foreach ( $this->attribute['enumeration'] as $choice ) { if ( ! isset( $choice['label'], $choice['value'] ) ) { continue; } if ( $choice['label'] === $this->field['value'] ) { return $choice['value']; } } return null; } /** * Get index of selected choice. * * @since 1.4.0 * * @return int|null */ private function get_selected_index() { if ( empty( $this->settings['choices'] ) || ! is_array( $this->settings['choices'] ) ) { return null; } $max_index = count( $this->attribute['enumeration'] ) - 1; // Get current element ID. foreach ( $this->settings['choices'] as $key => $choice ) { if ( isset( $choice['label'] ) && $this->field['value'] === $choice['label'] ) { return $key <= $max_index ? $key : null; } } return null; } /** * Multiple choice format. * * @since 1.4.0 * * @return array */ public function multiple_choice(): array { if ( ! in_array( $this->field['type'], [ 'radio', 'checkbox', 'select' ], true ) ) { return []; } return explode( "\n", $this->field['value'] ); } }
cloggier