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