| @@ -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() { |
| @@ -56,20 +53,16 @@ | ||
| 56 | 53 | } |
| 57 | 54 | |
| 58 | 55 | /** |
| 59 | 56 | * @since 4.03.06 |
| 60 | - * | |
| 61 | - * @param array $args Field display arguments. | |
| 62 | - * | |
| 63 | - * @return int|string | |
| 64 | 57 | */ |
| 65 | 58 | protected function get_field_value( $args ) { |
| 66 | 59 | $user_ID = get_current_user_id(); |
| 67 | 60 | $user_ID = ( $user_ID ? $user_ID : '' ); |
| 68 | 61 | $posted_value = ( FrmAppHelper::is_admin() && $_POST && isset( $_POST['item_meta'][ $this->field['id'] ] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Missing |
| 69 | - $action = ( $args['action'] ?? $args['form_action'] ?? '' ); | |
| 70 | - $updating = $action === 'update'; | |
| 71 | - return is_numeric( $this->field['value'] ) || $posted_value || $updating ? $this->field['value'] : $user_ID; | |
| 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; | |
| 72 | 65 | } |
| 73 | 66 | |
| 74 | 67 | public function validate( $args ) { |
| 75 | 68 | if ( '' == $args['value'] ) { |
| @@ -75,15 +68,15 @@ | ||
| 75 | 68 | if ( '' == $args['value'] ) { |
| 76 | 69 | return array(); |
| 77 | 70 | } |
| 78 | 71 | |
| 79 | - // Make sure we have a user ID. | |
| 72 | + // make sure we have a user ID | |
| 80 | 73 | if ( ! is_numeric( $args['value'] ) ) { |
| 81 | 74 | $args['value'] = FrmAppHelper::get_user_id_param( $args['value'] ); |
| 82 | 75 | FrmEntriesHelper::set_posted_value( $this->field, $args['value'], $args ); |
| 83 | 76 | } |
| 84 | 77 | |
| 85 | - // Add user id to post variables to be saved with entry. | |
| 78 | + //add user id to post variables to be saved with entry | |
| 86 | 79 | $_POST['frm_user_id'] = $args['value']; |
| 87 | 80 | |
| 88 | 81 | return array(); |
| 89 | 82 | } |
| @@ -88,12 +81,12 @@ | ||
| 88 | 81 | return array(); |
| 89 | 82 | } |
| 90 | 83 | |
| 91 | 84 | /** |
| 92 | - * @param array|string $value | |
| 93 | - * @param array $atts | |
| 85 | + * @param $value | |
| 86 | + * @param $atts array | |
| 94 | 87 | * |
| 95 | - * @return array|string A string is returned, but the return signature should match FrmFieldType. | |
| 88 | + * @return false|mixed|string | |
| 96 | 89 | */ |
| 97 | 90 | protected function prepare_display_value( $value, $atts ) { |
| 98 | 91 | $user_info = $this->prepare_user_info_attribute( $atts ); |
| 99 | 92 | |
| @@ -106,9 +99,9 @@ | ||
| 106 | 99 | * From the get_display_name() function |
| 107 | 100 | * |
| 108 | 101 | * @since 3.0 |
| 109 | 102 | * |
| 110 | - * @param array $atts | |
| 103 | + * @param $atts | |
| 111 | 104 | * |
| 112 | 105 | * @return string |
| 113 | 106 | */ |
| 114 | 107 | private function prepare_user_info_attribute( $atts ) { |
| @@ -125,10 +118,10 @@ | ||
| 125 | 118 | return $user_info; |
| 126 | 119 | } |
| 127 | 120 | |
| 128 | 121 | /** |
| 129 | - * @param string $value | |
| 130 | - * @param array $atts | |
| 122 | + * @param $value | |
| 123 | + * @param $atts | |
| 131 | 124 | * |
| 132 | 125 | * @return int |
| 133 | 126 | */ |
| 134 | 127 | protected function prepare_import_value( $value, $atts ) { |
| @@ -137,16 +130,10 @@ | ||
| 137 | 130 | |
| 138 | 131 | /** |
| 139 | 132 | * @since 4.0.04 |
| 140 | 133 | * |
| 141 | - * @param mixed $value Field value passed by reference. | |
| 142 | - * | |
| 143 | 134 | * @return void |
| 144 | 135 | */ |
| 145 | 136 | public function sanitize_value( &$value ) { |
| 146 | - if ( '' === $value ) { | |
| 147 | - // Allow for an empty User ID. Return early to prevent it from getting set to 0. | |
| 148 | - return; | |
| 149 | - } | |
| 150 | 137 | FrmAppHelper::sanitize_value( 'intval', $value ); |
| 151 | 138 | } |
| 152 | 139 | } |