PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 4.02.04
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v4.02.04
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 4.02.04, at classes/models/fields/FrmFieldUserID.php

122 lines 2.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * @since 3.0
5 */
6 class FrmFieldUserID extends FrmFieldType {
7
8 /**
9 * @var string
10 * @since 3.0
11 */
12 protected $type = 'user_id';
13
14 /**
15 * @var bool
16 * @since 3.0
17 */
18 protected $has_input = false;
19
20 /**
21 * @var bool
22 * @since 3.0
23 */
24 protected $has_html = false;
25
26 /**
27 * @var bool
28 * @since 3.0
29 */
30 protected $holds_email_values = true;
31
32 /**
33 * @return string
34 */
35 protected function include_form_builder_file() {
36 return FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/field-user-id.php';
37 }
38
39 public function prepare_field_html( $args ) {
40 $args = $this->fill_display_field_values( $args );
41
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;
47
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";
49 }
50
51 public function validate( $args ) {
52 if ( '' == $args['value'] ) {
53 return array();
54 }
55
56 // make sure we have a user ID
57 if ( ! is_numeric( $args['value'] ) ) {
58 $args['value'] = FrmAppHelper::get_user_id_param( $args['value'] );
59 FrmEntriesHelper::set_posted_value( $this->field, $args['value'], $args );
60 }
61
62 //add user id to post variables to be saved with entry
63 $_POST['frm_user_id'] = $args['value'];
64
65 return array();
66 }
67
68 /**
69 * @param $value
70 * @param $atts array
71 *
72 * @return false|mixed|string
73 */
74 protected function prepare_display_value( $value, $atts ) {
75 $user_info = $this->prepare_user_info_attribute( $atts );
76
77 return FrmFieldsHelper::get_user_display_name( $value, $user_info, $atts );
78 }
79
80 /**
81 * Generate the user info attribute for displaying
82 * a value from the user ID
83 * From the get_display_name() function
84 *
85 * @since 3.0
86 *
87 * @param $atts
88 *
89 * @return string
90 */
91 private function prepare_user_info_attribute( $atts ) {
92 if ( isset( $atts['show'] ) ) {
93 if ( $atts['show'] === 'id' ) {
94 $user_info = 'ID';
95 } else {
96 $user_info = $atts['show'];
97 }
98 } else {
99 $user_info = 'display_name';
100 }
101
102 return $user_info;
103 }
104
105 /**
106 * @param $value
107 * @param $atts
108 *
109 * @return int
110 */
111 protected function prepare_import_value( $value, $atts ) {
112 return FrmAppHelper::get_user_id_param( trim( $value ) );
113 }
114
115 /**
116 * @since 4.0.04
117 */
118 public function sanitize_value( &$value ) {
119 FrmAppHelper::sanitize_value( 'intval', $value );
120 }
121 }
122