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