| @@ -8,11 +8,11 @@ | ||
| 8 | 8 | */ |
| 9 | 9 | class FrmEntryValues { |
| 10 | 10 | |
| 11 | 11 | /** |
| 12 | - * @var stdClass | |
| 12 | + * @var false|stdClass|null | |
| 13 | 13 | */ |
| 14 | - protected $entry = null; | |
| 14 | + protected $entry; | |
| 15 | 15 | |
| 16 | 16 | /** |
| 17 | 17 | * @var int |
| 18 | 18 | */ |
| @@ -48,9 +48,9 @@ | ||
| 48 | 48 | * |
| 49 | 49 | * @since 2.04 |
| 50 | 50 | * |
| 51 | 51 | * @param int|string $entry_id |
| 52 | - * @param array $atts | |
| 52 | + * @param array $atts | |
| 53 | 53 | */ |
| 54 | 54 | public function __construct( $entry_id, $atts = array() ) { |
| 55 | 55 | if ( isset( $atts['entry'] ) && is_object( $atts['entry'] ) && ! empty( $atts['entry']->metas ) ) { |
| 56 | 56 | $this->entry = $atts['entry']; |
| @@ -86,8 +86,9 @@ | ||
| 86 | 86 | /** |
| 87 | 87 | * Gets entry property. |
| 88 | 88 | * |
| 89 | 89 | * @since 5.0.16 |
| 90 | + * | |
| 90 | 91 | * @return stdClass |
| 91 | 92 | */ |
| 92 | 93 | public function get_entry() { |
| 93 | 94 | return $this->entry; |
| @@ -113,25 +114,20 @@ | ||
| 113 | 114 | * |
| 114 | 115 | * @return void |
| 115 | 116 | */ |
| 116 | 117 | protected function init_include_fields( $atts ) { |
| 118 | + // For reverse compatibility with the fields parameter. | |
| 119 | + if ( empty( $atts['include_fields'] ) && ! empty( $atts['fields'] ) ) { | |
| 120 | + if ( is_array( $atts['fields'] ) ) { | |
| 121 | + $atts['include_fields'] = ''; | |
| 117 | 122 | |
| 118 | - // For reverse compatibility with the fields parameter | |
| 119 | - if ( ! isset( $atts['include_fields'] ) || empty( $atts['include_fields'] ) ) { | |
| 123 | + foreach ( $atts['fields'] as $included_field ) { | |
| 124 | + $atts['include_fields'] .= $included_field->id . ','; | |
| 125 | + } | |
| 120 | 126 | |
| 121 | - if ( isset( $atts['fields'] ) && ! empty( $atts['fields'] ) ) { | |
| 122 | - | |
| 123 | - if ( ! is_array( $atts['fields'] ) ) { | |
| 124 | - $atts['include_fields'] = $atts['fields']; | |
| 125 | - } else { | |
| 126 | - $atts['include_fields'] = ''; | |
| 127 | - | |
| 128 | - foreach ( $atts['fields'] as $included_field ) { | |
| 129 | - $atts['include_fields'] .= $included_field->id . ','; | |
| 130 | - } | |
| 131 | - | |
| 132 | - $atts['include_fields'] = rtrim( $atts['include_fields'], ',' ); | |
| 133 | - } | |
| 127 | + $atts['include_fields'] = rtrim( $atts['include_fields'], ',' ); | |
| 128 | + } else { | |
| 129 | + $atts['include_fields'] = $atts['fields']; | |
| 134 | 130 | } |
| 135 | 131 | } |
| 136 | 132 | |
| 137 | 133 | $this->include_fields = $this->prepare_array_property( 'include_fields', $atts ); |
| @@ -175,25 +171,18 @@ | ||
| 175 | 171 | * |
| 176 | 172 | * @since 2.04 |
| 177 | 173 | * |
| 178 | 174 | * @param string $index |
| 179 | - * @param array $atts | |
| 175 | + * @param array $atts | |
| 180 | 176 | * |
| 181 | 177 | * @return array |
| 182 | 178 | */ |
| 183 | 179 | private function prepare_array_property( $index, $atts ) { |
| 184 | - if ( isset( $atts[ $index ] ) && ! empty( $atts[ $index ] ) ) { | |
| 185 | - | |
| 186 | - if ( is_array( $atts[ $index ] ) ) { | |
| 187 | - $property = $atts[ $index ]; | |
| 188 | - } else { | |
| 189 | - $property = explode( ',', $atts[ $index ] ); | |
| 190 | - } | |
| 191 | - } else { | |
| 192 | - $property = array(); | |
| 180 | + if ( ! empty( $atts[ $index ] ) ) { | |
| 181 | + return is_array( $atts[ $index ] ) ? $atts[ $index ] : explode( ',', $atts[ $index ] ); | |
| 193 | 182 | } |
| 194 | 183 | |
| 195 | - return $property; | |
| 184 | + return array(); | |
| 196 | 185 | } |
| 197 | 186 | |
| 198 | 187 | /** |
| 199 | 188 | * Set the fields property |
| @@ -265,19 +254,19 @@ | ||
| 265 | 254 | 'referrer' => '', |
| 266 | 255 | ); |
| 267 | 256 | } |
| 268 | 257 | |
| 269 | - $ip = array( | |
| 258 | + $ip = array( | |
| 270 | 259 | 'label' => __( 'IP Address', 'formidable' ), |
| 271 | 260 | 'value' => $this->entry->ip, |
| 272 | 261 | ); |
| 273 | - $browser = array( | |
| 262 | + $browser = array( | |
| 274 | 263 | 'label' => __( 'User-Agent (Browser/OS)', 'formidable' ), |
| 275 | 264 | 'value' => isset( $entry_description['browser'] ) ? FrmEntriesHelper::get_browser( $entry_description['browser'] ) : '', |
| 276 | 265 | ); |
| 277 | 266 | $referrer = array( |
| 278 | 267 | 'label' => __( 'Referrer', 'formidable' ), |
| 279 | - 'value' => isset( $entry_description['referrer'] ) ? $entry_description['referrer'] : '', | |
| 268 | + 'value' => $entry_description['referrer'] ?? '', | |
| 280 | 269 | ); |
| 281 | 270 | |
| 282 | 271 | /** |
| 283 | 272 | * Allow the referrer to be modified. |
| @@ -283,10 +272,11 @@ | ||
| 283 | 272 | * Allow the referrer to be modified. |
| 284 | 273 | * |
| 285 | 274 | * @since 5.5.1 |
| 286 | 275 | * |
| 287 | - * @param array $referrer | |
| 288 | - * @param array @entry_description | |
| 276 | + * @param array $referrer | |
| 277 | + * @param array $entry_description | |
| 278 | + * @param object $entry | |
| 289 | 279 | */ |
| 290 | 280 | $referrer = apply_filters( 'frm_user_info_referrer', $referrer, $entry_description, $this->entry ); |
| 291 | 281 | |
| 292 | 282 | $this->user_info = array( |
| @@ -317,14 +307,16 @@ | ||
| 317 | 307 | * @return bool |
| 318 | 308 | */ |
| 319 | 309 | protected function is_field_included( $field ) { |
| 320 | 310 | $is_included = true; |
| 321 | - if ( ! empty( $this->include_fields ) ) { | |
| 311 | + | |
| 312 | + if ( $this->include_fields ) { | |
| 322 | 313 | $is_included = $this->is_field_in_array( $field, $this->include_fields ); |
| 323 | 314 | } |
| 324 | 315 | |
| 325 | - if ( ! empty( $this->exclude_fields ) ) { | |
| 316 | + if ( $this->exclude_fields ) { | |
| 326 | 317 | $is_excluded = $this->is_field_in_array( $field, $this->exclude_fields ); |
| 318 | + | |
| 327 | 319 | if ( $is_excluded ) { |
| 328 | 320 | $is_included = false; |
| 329 | 321 | } |
| 330 | 322 | } |
| @@ -337,13 +329,14 @@ | ||
| 337 | 329 | * |
| 338 | 330 | * @since 2.04 |
| 339 | 331 | * |
| 340 | 332 | * @param stdClass $field |
| 341 | - * @param array $array | |
| 333 | + * @param array $array | |
| 342 | 334 | * |
| 343 | 335 | * @return bool |
| 344 | 336 | */ |
| 345 | 337 | protected function is_field_in_array( $field, $array ) { |
| 338 | + // phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict | |
| 346 | 339 | return in_array( $field->id, $array ) || in_array( (string) $field->field_key, $array, true ); |
| 347 | 340 | } |
| 348 | 341 | |
| 349 | 342 | /** |