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
formidable / classes / models / fields / FrmFieldUserID.php

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

113 lines 2.6 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 return FrmFieldsHelper::get_user_display_name( $value, $user_info, $atts );
77 }
78
79 /**
80 * Generate the user info attribute for displaying
81 * a value from the user ID
82 * From the get_display_name() function
83 *
84 * @since 3.0
85 * @param $atts
86 *
87 * @return string
88 */
89 private function prepare_user_info_attribute( $atts ) {
90 if ( isset( $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';
98 }
99
100 return $user_info;
101 }
102
103 /**
104 * @param $value
105 * @param $atts
106 *
107 * @return int
108 */
109 protected function prepare_import_value( $value, $atts ) {
110 return FrmAppHelper::get_user_id_param( trim( $value ) );
111 }
112 }
113