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