StoutLogic / acf-builder

An Advanced Custom Field Configuration Builder
GNU General Public License v2.0
792 stars 61 forks source link

RecursiveTransform array_walk() expects parameter 1 to be array, int given #102

Closed vz01d closed 4 years ago

vz01d commented 4 years ago

Hi there,

I am using acf-builder for a theme and I found some issue I cannot explain myself, so hopefully someone here can.

I noticed this warning in my logs:

PHP Warning: array_walk() expects parameter 1 to be array, int given in D:\Bitnami\apache2\htdocs\wp-content\themes\fetcher\vendor\stoutlogic\acf-builder\src\Transform\RecursiveTransform.php on line 43

code to build my fields:

$postSettings = new FieldsBuilder('post_settings');
        $postSettings
            ->addTab('layout')
            ->addTrueFalse('hide_header', [
                'label' => 'Hide header',
                'instructions' => '',
                'required' => 0,
                'conditional_logic' => 0,
                'wrapper' => [
                    'width' => '',
                    'class' => '',
                    'id' => '',
                ],
                'message' => '',
                'default_value' => 0,
                'ui' => 1,
                'ui_on_text' => 'hidden',
                'ui_off_text' => 'visible',
            ])
            ->setGroupConfig('position', 'acf_after_title')
            ->setLocation('post_type', '==', 'post');

        acf_add_local_field_group($postSettings->build());

entering that function dumping the input value $config:

public function transform($config)
    {
        echo "<pre>";var_dump($config);
        array_walk($config, function(&$value, $key) {
....

I get this in return:

array(2) { [0]=> array(4) { ["type"]=> string(3) "tab" ["name"]=> string(10) "layout_tab" ["label"]=> string(6) "Layout" ["key"]=> string(16) "field_layout_tab" } [1]=> array(13) { ["type"]=> string(10) "true_false" ["name"]=> string(11) "hide_header" ["label"]=> string(11) "Hide header" ["key"]=> string(17) "field_hide_header" ["instructions"]=> string(0) "" ["required"]=> int(0) ["conditional_logic"]=> int(0) ["wrapper"]=> array(3) { ["width"]=> string(0) "" ["class"]=> string(0) "" ["id"]=> string(0) "" } ["message"]=> string(0) "" ["default_value"]=> int(0) ["ui"]=> int(1) ["ui_on_text"]=> string(6) "hidden" ["ui_off_text"]=> string(7) "visible" } }

array(4) { ["type"]=> string(3) "tab" ["name"]=> string(10) "layout_tab" ["label"]=> string(6) "Layout" ["key"]=> string(16) "field_layout_tab" }

array(13) { ["type"]=> string(10) "true_false" ["name"]=> string(11) "hide_header" ["label"]=> string(11) "Hide header" ["key"]=> string(17) "field_hide_header" ["instructions"]=> string(0) "" ["required"]=> int(0) ["conditional_logic"]=> int(0) ["wrapper"]=> array(3) { ["width"]=> string(0) "" ["class"]=> string(0) "" ["id"]=> string(0) "" } ["message"]=> string(0) "" ["default_value"]=> int(0) ["ui"]=> int(1) ["ui_on_text"]=> string(6) "hidden" ["ui_off_text"]=> string(7) "visible" }

int(0)

array(3) { ["width"]=> string(0) "" ["class"]=> string(0) "" ["id"]=> string(0) "" }

array(2) { [0]=> array(4) { ["type"]=> string(3) "tab" ["name"]=> string(10) "layout_tab" ["label"]=> string(6) "Layout" ["key"]=> string(16) "field_layout_tab" } [1]=> array(13) { ["type"]=> string(10) "true_false" ["name"]=> string(11) "hide_header" ["label"]=> string(11) "Hide header" ["key"]=> string(17) "field_hide_header" ["instructions"]=> string(0) "" ["required"]=> int(0) ["conditional_logic"]=> int(0) ["wrapper"]=> array(3) { ["width"]=> string(0) "" ["class"]=> string(0) "" ["id"]=> string(0) "" } ["message"]=> string(0) "" ["default_value"]=> int(0) ["ui"]=> int(1) ["ui_on_text"]=> string(6) "hidden" ["ui_off_text"]=> string(7) "visible" } }

array(4) { ["type"]=> string(3) "tab" ["name"]=> string(10) "layout_tab" ["label"]=> string(6) "Layout" ["key"]=> string(16) "field_layout_tab" }

array(13) { ["type"]=> string(10) "true_false" ["name"]=> string(11) "hide_header" ["label"]=> string(11) "Hide header" ["key"]=> string(17) "field_hide_header" ["instructions"]=> string(0) "" ["required"]=> int(0) ["conditional_logic"]=> int(0) ["wrapper"]=> array(3) { ["width"]=> string(0) "" ["class"]=> string(0) "" ["id"]=> string(0) "" } ["message"]=> string(0) "" ["default_value"]=> int(0) ["ui"]=> int(1) ["ui_on_text"]=> string(6) "hidden" ["ui_off_text"]=> string(7) "visible" }

array(3) { ["width"]=> string(0) "" ["class"]=> string(0) "" ["id"]=> string(0) "" }

Now I am sure a simple is_array would prevent that warning but I am still highly curious where that integer 0 is coming from.

Cheers, Sebo

vz01d commented 4 years ago

okay checking where this value output has been placed I noticed that conditional_logic was set to 0 where it should be array() instead.