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