Support

Account

Home Forums General Issues Move from PHP registered fields to ACF UI

Solving

Move from PHP registered fields to ACF UI

  • Is it possible to move fields that have been registered PHP (in the functions files) to the ACF UI so they can be edited via WP Admin?

    If so, is it possible to retain all of the existing values?

  • Getting them from PHP into ACF admin will depend on what version of ACF you are using.

    The first step is to get the field group into a format that can be imported.

    Just after you’ve created the field group in PHP you need to add some code (temporary) that will format the field group for importing and save it as a file. For ACF5 you just need to use json_encode($field_group);

    I don’t know how to tell you to format the group for ACF4. I think it uses a standard WP type of import XML file.

    http://php.net/manual/en/function.file-put-contents.php

    As far as keeping the values, as long as your field names and field keys are the same as those generated by PHP then none of your values will be lost.

  • Ok, we tried that but the output doesn’t look right.

    Here’s the code we are running: https://www.dropbox.com/s/orqr1g69mr3p8m3/acf.php?dl=0

    Any ideas?

    Thanks for the help so far John!

  • BTW, we are using ACF Pro Version 5.3.10

  • Once you have saved the json file you need to download it, remove the field group completely from your PHP and then import the field group into ACF. The regular json_encode() will look different than the ACF version because it does not include the white-space that ACF adds to the file, but you should still be able to import it.

  • Hello John,

    I am the developer working on this project. I also hold an ACF pro license under this account. The JSON exported from the code above is not working and the fields are not imported after selecting any of the resulting files. Did you run the code in your local environment? Did it work for you?

    Thank you,
    Antonios

  • Are you sure the json has the right values? For example, where is the “key” for each group? i see you are using an “id”, but…. shouldn´t be “key” ?
    Also the entire json generated must be inside [] and is not.
    Also i notice you are using ‘options’ => array(…. but in my exported json from ACF UI, that thing do not exsits, position, hide_on_screen and so on are “alone” not as part of an array.

    So, i think the array that is transformed into json is not well formated and that´s why when importing nothing happens.

    Did you test with just a small and simple array let´s say a group with just one text field and no complex location rules?

  • Sorry, I only scanned your code minimally.

    The first thing that I noticed in your code was this

    
    function register_field_group(.... 
    

    This function that you’ve created already exists in ACF and the first line of your code should be causing a fatal error trying to declare the same function more than once. I did not look at every field group, but @rgdesign is correct. The field groups that you are attempting to create in PHP do not look like they are correct to begin with. My suggestion here is to create a field group in ACF and export them to PHP to get a better idea of what they need to look like in ACF5. There are significant differences between ACF4 and ACF5. if the field groups in your code were originally done for ACF4 then they will need to be updated to work with 5.

    After registering your field groups as normal in ACF.

    
    $field_group = acf_get_field_group($group_key);
    $field_group['fields'] = acf_get_fields($group_key');
    $json = json_encode($field_group);
    file_put_contents($group_key.'.json', $json);
    

    This should create a file that can be imported. Like I said, once the group is imported you need to delete it completely from your PHP or otherwise disable php from registering the group.

Viewing 8 posts - 1 through 8 (of 8 total)

The topic ‘Move from PHP registered fields to ACF UI’ is closed to new replies.