PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.16
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.16
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 / fields / FrmFieldUserID.php

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

140 lines 3.3 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 3.0
8 */
9 class FrmFieldUserID extends FrmFieldType {
10
11 /**
12 * @var string
13 * @since 3.0
14 */
15 protected $type = 'user_id';
16
17 /**
18 * @var bool
19 * @since 3.0
20 */
21 protected $has_input = false;
22
23 /**
24 * @var bool
25 * @since 3.0
26 */
27 protected $has_html = false;
28
29 /**
30 * @var bool
31 * @since 3.0
32 */
33 protected $holds_email_values = true;
34
35 /**
36 * @var bool
37 */
38 protected $array_allowed = false;
39
40
41 /**
42 * @return string
43 */
44 protected function include_form_builder_file() {
45 return FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/field-user-id.php';
46 }
47
48 public function prepare_field_html( $args ) {
49 $args = $this->fill_display_field_values( $args );
50 $value = $this->get_field_value( $args );
51
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";
53 }
54
55 /**
56 * @since 4.03.06
57 */
58 protected function get_field_value( $args ) {
59 $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;
65 }
66
67 public function validate( $args ) {
68 if ( '' == $args['value'] ) {
69 return array();
70 }
71
72 // Make sure we have a user ID.
73 if ( ! is_numeric( $args['value'] ) ) {
74 $args['value'] = FrmAppHelper::get_user_id_param( $args['value'] );
75 FrmEntriesHelper::set_posted_value( $this->field, $args['value'], $args );
76 }
77
78 // Add user id to post variables to be saved with entry.
79 $_POST['frm_user_id'] = $args['value'];
80
81 return array();
82 }
83
84 /**
85 * @param array|string $value
86 * @param array $atts
87 *
88 * @return array|string A string is returned, but the return signature should match FrmFieldType.
89 */
90 protected function prepare_display_value( $value, $atts ) {
91 $user_info = $this->prepare_user_info_attribute( $atts );
92
93 return FrmFieldsHelper::get_user_display_name( $value, $user_info, $atts );
94 }
95
96 /**
97 * Generate the user info attribute for displaying
98 * a value from the user ID
99 * From the get_display_name() function
100 *
101 * @since 3.0
102 *
103 * @param array $atts
104 *
105 * @return string
106 */
107 private function prepare_user_info_attribute( $atts ) {
108 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' );
116 }
117
118 return $user_info;
119 }
120
121 /**
122 * @param string $value
123 * @param array $atts
124 *
125 * @return int
126 */
127 protected function prepare_import_value( $value, $atts ) {
128 return FrmAppHelper::get_user_id_param( trim( $value ) );
129 }
130
131 /**
132 * @since 4.0.04
133 *
134 * @return void
135 */
136 public function sanitize_value( &$value ) {
137 FrmAppHelper::sanitize_value( 'intval', $value );
138 }
139 }
140