PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 3.06.06
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v3.06.06
6.35 6.34 6.33.1 6.33 6.32.1 6.32 6.31 6.25 6.25.1 6.26 6.26.1 6.27 6.28 6.29 6.3 6.3.1 6.3.2 6.30 6.4 6.4.1 6.4.2 6.5 6.5.1 6.5.2 6.5.3 All 141 releases
← All changes | classes/models/FrmFieldOption.php +17 -40 6.273.06.06 View file →
@@ -1,8 +1,5 @@
1 1 <?php
2 -if ( ! defined( 'ABSPATH' ) ) {
3 - die( 'You are not allowed to call this page directly.' );
4 -}
5 2
6 3 /**
7 4 * @since 2.03.05
8 5 */
@@ -8,9 +5,9 @@
8 5 */
9 6 class FrmFieldOption {
10 7
11 8 /**
12 - * @var int|string
9 + * @var string|int
13 10 *
14 11 * @since 2.03.05
15 12 */
16 13 protected $option_key;
@@ -15,9 +12,9 @@
15 12 */
16 13 protected $option_key;
17 14
18 15 /**
19 - * @var array|string
16 + * @var string|array
20 17 *
21 18 * @since 2.03.05
22 19 */
23 20 protected $option;
@@ -23,9 +20,8 @@
23 20 protected $option;
24 21
25 22 /**
26 23 * @var string
27 - *
28 24 * @since 2.03.05
29 25 */
30 26 protected $saved_value = '';
31 27
@@ -30,23 +26,15 @@
30 26 protected $saved_value = '';
31 27
32 28 /**
33 29 * @var string
34 - *
35 30 * @since 2.03.05
36 31 */
37 32 protected $option_label = '';
38 33
39 - /**
40 - * @param int|string $option_key
41 - * @param array|string $option
42 - * @param array $args
43 - *
44 - * @return void
45 - */
46 34 public function __construct( $option_key, $option, $args = array() ) {
47 35 $this->option_key = $option_key;
48 - $this->option = $option;
36 + $this->option = $option;
49 37 $this->set_option_label();
50 38 $this->set_saved_value();
51 39 }
52 40
@@ -53,13 +41,15 @@
53 41 /**
54 42 * Set the option label
55 43 *
56 44 * @since 2.03.05
57 - *
58 - * @return void
59 45 */
60 46 private function set_option_label() {
61 - $this->option_label = is_array( $this->option ) ? ( $this->option['label'] ?? reset( $this->option ) ) : $this->option;
47 + if ( is_array( $this->option ) ) {
48 + $this->option_label = ( isset( $this->option['label'] ) ? $this->option['label'] : reset( $this->option ) );
49 + } else {
50 + $this->option_label = $this->option;
51 + }
62 52 }
63 53
64 54 /**
65 55 * Set the saved value
@@ -64,10 +54,8 @@
64 54 /**
65 55 * Set the saved value
66 56 *
67 57 * @since 2.03.05
68 - *
69 - * @return void
70 58 */
71 59 protected function set_saved_value() {
72 60 $this->saved_value = $this->option_label;
73 61 }
@@ -76,28 +64,17 @@
76 64 * Print a single option
77 65 *
78 66 * @since 2.03.05
79 67 *
80 - * @param string $selected_value The value of the option to be selected.
81 - * @param int $truncate Truncate the option label if true.
82 - * @param bool $use_value_as_label Use the option value as the label if true.
83 - *
84 - * @return void
68 + * @param string $selected_value
69 + * @param int $truncate
85 70 */
86 - public function print_single_option( $selected_value, $truncate, $use_value_as_label = false ) {
87 - if ( '' === $this->saved_value && ! $use_value_as_label ) {
88 - return;
71 + public function print_single_option( $selected_value, $truncate ) {
72 + if ( '' !== $this->saved_value ) {
73 + echo '<option value="' . esc_attr( $this->saved_value ) . '"';
74 + selected( esc_attr( $selected_value ), esc_attr( $this->saved_value ) );
75 + // TODO: add hook that can add attributes to option text
76 + echo '>';
77 + echo esc_html( FrmAppHelper::truncate( $this->option_label, $truncate ) ) . '</option>';
89 78 }
90 -
91 - if ( $use_value_as_label && '' === trim( $this->option_label ) ) {
92 - $label = '' !== $this->saved_value ? $this->saved_value : FrmAppHelper::get_no_label_text();
93 - } else {
94 - $label = $this->option_label;
95 - }
96 -
97 - echo '<option value="' . esc_attr( $this->saved_value ) . '"';
98 - selected( esc_attr( $selected_value ), esc_attr( $this->saved_value ) );
99 - // TODO: add hook that can add attributes to option text
100 - echo '>';
101 - echo esc_html( FrmAppHelper::truncate( $label, $truncate ) ) . '</option>';
102 79 }
103 80 }