PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 5.0.02
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v5.0.02
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
formidable / classes / models / FrmFieldOption.php

FrmFieldOption.php in Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More 5.0.02, at classes/models/FrmFieldOption.php

84 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) {
3 die( 'You are not allowed to call this page directly.' );
4 }
5
6 /**
7 * @since 2.03.05
8 */
9 class FrmFieldOption {
10
11 /**
12 * @var string|int
13 *
14 * @since 2.03.05
15 */
16 protected $option_key;
17
18 /**
19 * @var string|array
20 *
21 * @since 2.03.05
22 */
23 protected $option;
24
25 /**
26 * @var string
27 * @since 2.03.05
28 */
29 protected $saved_value = '';
30
31 /**
32 * @var string
33 * @since 2.03.05
34 */
35 protected $option_label = '';
36
37 public function __construct( $option_key, $option, $args = array() ) {
38 $this->option_key = $option_key;
39 $this->option = $option;
40 $this->set_option_label();
41 $this->set_saved_value();
42 }
43
44 /**
45 * Set the option label
46 *
47 * @since 2.03.05
48 */
49 private function set_option_label() {
50 if ( is_array( $this->option ) ) {
51 $this->option_label = ( isset( $this->option['label'] ) ? $this->option['label'] : reset( $this->option ) );
52 } else {
53 $this->option_label = $this->option;
54 }
55 }
56
57 /**
58 * Set the saved value
59 *
60 * @since 2.03.05
61 */
62 protected function set_saved_value() {
63 $this->saved_value = $this->option_label;
64 }
65
66 /**
67 * Print a single option
68 *
69 * @since 2.03.05
70 *
71 * @param string $selected_value
72 * @param int $truncate
73 */
74 public function print_single_option( $selected_value, $truncate ) {
75 if ( '' !== $this->saved_value ) {
76 echo '<option value="' . esc_attr( $this->saved_value ) . '"';
77 selected( esc_attr( $selected_value ), esc_attr( $this->saved_value ) );
78 // TODO: add hook that can add attributes to option text
79 echo '>';
80 echo esc_html( FrmAppHelper::truncate( $this->option_label, $truncate ) ) . '</option>';
81 }
82 }
83 }
84