PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.0
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.0
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/fields/FrmFieldUserID.php +23 -46 6.326.0 View file →
@@ -9,9 +9,8 @@
9 9 class FrmFieldUserID extends FrmFieldType {
10 10
11 11 /**
12 12 * @var string
13 - *
14 13 * @since 3.0
15 14 */
16 15 protected $type = 'user_id';
17 16
@@ -16,9 +15,8 @@
16 15 protected $type = 'user_id';
17 16
18 17 /**
19 18 * @var bool
20 - *
21 19 * @since 3.0
22 20 */
23 21 protected $has_input = false;
24 22
@@ -23,9 +21,8 @@
23 21 protected $has_input = false;
24 22
25 23 /**
26 24 * @var bool
27 - *
28 25 * @since 3.0
29 26 */
30 27 protected $has_html = false;
31 28
@@ -30,19 +27,13 @@
30 27 protected $has_html = false;
31 28
32 29 /**
33 30 * @var bool
34 - *
35 31 * @since 3.0
36 32 */
37 33 protected $holds_email_values = true;
38 34
39 35 /**
40 - * @var bool
41 - */
42 - protected $array_allowed = false;
43 -
44 - /**
45 36 * @return string
46 37 */
47 38 protected function include_form_builder_file() {
48 39 return FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/field-user-id.php';
@@ -47,52 +38,39 @@
47 38 protected function include_form_builder_file() {
48 39 return FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/field-user-id.php';
49 40 }
50 41
51 - /**
52 - * @param array $args
53 - */
54 42 public function prepare_field_html( $args ) {
55 43 $args = $this->fill_display_field_values( $args );
56 44 $value = $this->get_field_value( $args );
57 45
58 - echo '<input type="hidden" name="' . esc_attr( $args['field_name'] ) . '" id="' . esc_attr( $args['html_id'] ) . '" value="' . esc_attr( $value ) . '" data-frmval="' . esc_attr( $value ) . '"/>' . "\n"; // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
46 + echo '<input type="hidden" name="' . esc_attr( $args['field_name'] ) . '" id="' . esc_attr( $args['html_id'] ) . '" value="' . esc_attr( $value ) . '" data-frmval="' . esc_attr( $value ) . '"/>' . "\n";
59 47 }
60 48
61 49 /**
62 50 * @since 4.03.06
63 - *
64 - * @param array $args Field display arguments.
65 - *
66 - * @return int|string
67 51 */
68 52 protected function get_field_value( $args ) {
69 53 $user_ID = get_current_user_id();
70 - $user_ID = $user_ID ? $user_ID : '';
71 - $posted_value = FrmAppHelper::is_admin() && $_POST && isset( $_POST['item_meta'][ $this->field['id'] ] ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
72 - $action = $args['action'] ?? $args['form_action'] ?? '';
73 - $updating = $action === 'update';
74 - return is_numeric( $this->field['value'] ) || $posted_value || $updating ? $this->field['value'] : $user_ID;
54 + $user_ID = ( $user_ID ? $user_ID : '' );
55 + $posted_value = ( FrmAppHelper::is_admin() && $_POST && isset( $_POST['item_meta'][ $this->field['id'] ] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
56 + $action = ( isset( $args['action'] ) ? $args['action'] : ( isset( $args['form_action'] ) ? $args['form_action'] : '' ) );
57 + $updating = $action == 'update';
58 + return ( is_numeric( $this->field['value'] ) || $posted_value || $updating ) ? $this->field['value'] : $user_ID;
75 59 }
76 60
77 - /**
78 - * @param array $args
79 - *
80 - * @return array
81 - */
82 61 public function validate( $args ) {
83 - // phpcs:ignore Universal.Operators.StrictComparisons
84 62 if ( '' == $args['value'] ) {
85 63 return array();
86 64 }
87 65
88 - // Make sure we have a user ID.
66 + // make sure we have a user ID
89 67 if ( ! is_numeric( $args['value'] ) ) {
90 68 $args['value'] = FrmAppHelper::get_user_id_param( $args['value'] );
91 69 FrmEntriesHelper::set_posted_value( $this->field, $args['value'], $args );
92 70 }
93 71
94 - // Add user id to post variables to be saved with entry.
72 + //add user id to post variables to be saved with entry
95 73 $_POST['frm_user_id'] = $args['value'];
96 74
97 75 return array();
98 76 }
@@ -97,15 +75,16 @@
97 75 return array();
98 76 }
99 77
100 78 /**
101 - * @param array|string $value
102 - * @param array $atts
79 + * @param $value
80 + * @param $atts array
103 81 *
104 - * @return array|string A string is returned, but the return signature should match FrmFieldType.
82 + * @return false|mixed|string
105 83 */
106 84 protected function prepare_display_value( $value, $atts ) {
107 85 $user_info = $this->prepare_user_info_attribute( $atts );
86 +
108 87 return FrmFieldsHelper::get_user_display_name( $value, $user_info, $atts );
109 88 }
110 89
111 90 /**
@@ -114,23 +93,29 @@
114 93 * From the get_display_name() function
115 94 *
116 95 * @since 3.0
117 96 *
118 - * @param array $atts
97 + * @param $atts
119 98 *
120 99 * @return string
121 100 */
122 101 private function prepare_user_info_attribute( $atts ) {
123 102 if ( isset( $atts['show'] ) ) {
124 - return $atts['show'] === 'id' ? 'ID' : $atts['show'];
103 + if ( $atts['show'] === 'id' ) {
104 + $user_info = 'ID';
105 + } else {
106 + $user_info = $atts['show'];
107 + }
108 + } else {
109 + $user_info = apply_filters( 'frm_user_id_display', 'display_name' );
125 110 }
126 111
127 - return apply_filters( 'frm_user_id_display', 'display_name' );
112 + return $user_info;
128 113 }
129 114
130 115 /**
131 - * @param string $value
132 - * @param array $atts
116 + * @param $value
117 + * @param $atts
133 118 *
134 119 * @return int
135 120 */
136 121 protected function prepare_import_value( $value, $atts ) {
@@ -138,17 +123,9 @@
138 123 }
139 124
140 125 /**
141 126 * @since 4.0.04
142 - *
143 - * @param mixed $value Field value passed by reference.
144 - *
145 - * @return void
146 127 */
147 128 public function sanitize_value( &$value ) {
148 - if ( '' === $value ) {
149 - // Allow for an empty User ID. Return early to prevent it from getting set to 0.
150 - return;
151 - }
152 129 FrmAppHelper::sanitize_value( 'intval', $value );
153 130 }
154 131 }