Visibility conditions don't work with arrays

Cwicly Plugin version: 1.3.1

Hi,

This is an issue I constantly have to deal with.
Though there are different workarounds, I think it’s worth requiring a fix to make life easier :wink:

Let’s say I have an ACF file field, and that I don’t want to display it if no file has been selected.

The get_field() function will return:

  • false if no file has been selected;
  • a non empty array with data if a file has been selected.

(So, not only I don’t want to display it, but it will also cause an error when accessing indexes of false.)

The issue is that Cwicly conditions don’t seem to work when comparing such ACF field.
And when I use a code block to the same comparisons with PHP, it works perfectly.

Here is how comparison should behave according to PHP manual:
https://www.php.net/manual/en/types.comparisons.php

But nothing seems to work inside Cwicly:

  • comparing empty or non-empty field to true always seems to be false;
  • comparing empty or non-empty field with not empty always seems to be false;
  • same using PHP functions like get_field() or get_sub_field() to access fields in conditions.

The only solution that seems to work is using gettype(get_field('document')) === 'array' condition, but there’s a gap with empty but actual arrays to use it properly in all cases.

Am I missing something? Some syntax trick I’m not aware of?

What is weird is that gettype() seems to respond correctly, but not other functions!!!