Jeradin / acf-dynamic-table-field

A Dynamic Fable field for Advanced Custom Fields
33 stars 6 forks source link

Compatibility with ACF v5 #5

Open cyberdelphos opened 8 years ago

cyberdelphos commented 8 years ago

This error appears when activating ACF PRO v5:

Warning: array_map(): Argument #2 should be an array in /wp-content/plugins/acf-dynamic-table-field-master/acf-dynamic_table_field-v5.php on line 301

Warning: array_keys() expects parameter 1 to be array, object given in /wp-content/plugins/acf-dynamic-table-field-master/acf-dynamic_table_field-v5.php on line 303

cyberdelphos commented 8 years ago

I somehow semi-solved it by changing line 286 to:

$tabledata = json_decode($value, true);

but now it shows some errors accesing the info, of the field.

Hope this helps

Jeradin commented 8 years ago

I am not able to replicate this. Is this from fresh data in the table and is there some hidden html in the cells?

Adding true to the json_decode converts objects to arrays which the field should not be able to save objects.

What version of PHP are you on?

cyberdelphos commented 8 years ago

Hello Jeradin,

No hidden html in the cells, it was data saved previously using dynamic table with ACF 4 free edition, then changed ACF "Free v4" to "PRO v5" and the array_map() warning started to appear.

After setting true on json_decode, new posts and new "dynamic table" fields worked fine.

Php version is:

php -v
PHP 5.5.9-1ubuntu4.14 (cli) (built: Oct 28 2015 01:34:46) 
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies
    with Zend OPcache v7.0.3, Copyright (c) 1999-2014, by Zend Technologies

P.D. Also, I'm using IssueM if that provides you any further info.

Jeradin commented 8 years ago

Hmm, I have not built a table in 4 and upgraded to 5, wondering why that would cause an issue.

If you remove the true and start with fresh information in a table, does it work?

EDIT: I kind of stopped doing anything with ACF4 a long time ago. I am guessing there is some different formatting in 4 as 5. I just compared the two versions and really not seeing exactly what it is. I am going to add a warning about upgrading and likely need to remove version 4 version.

cyberdelphos commented 8 years ago

Here are some relevant changes from v4 to v5 but I don't think they are causing trouble Upgrading V4 to V5, you can check it while I try your suggested test

cyberdelphos commented 8 years ago

In fact it works, if I remove the true argument, I have no problems making new tables and filling new fields with data. So the problem may seem to be while upgrading ACF from v4 to v5.

Jeradin commented 8 years ago

Thank you for testing that. I will see if I can figure out what changed and warn people. Likely not worth it writing an upgrade script.

Have a great day!