Support

Account

Home Forums Feature Requests Import from PHP

Solving

Import from PHP

  • I have seen some support threads on the topic of importing from php, and it would be a really useful feature for me.

    In my development workflow, I usually export to php (and place the code in functions.php) at the beginning of the dev cycle, which helps with deploying to dev/staging/production, because we don’t need to sync up the ACF fields via the WP admin (it’s done with functions.php automatically).

    But because I use this workflow, I oftentimes find myself needing to edit or add fields at various (usually random) points in the dev cycle. Adding/editing ACF fields via php is cumbersome. It would be SUPER HELPFUL if there was a php import feature that sat next to the “php export” feature in ACF Pro.

    Any thoughts on if/when this might make it on your to-do list?

    Thanks!
    Toby

  • Hi Toby,

    I’ll add in @elliot in the conversation.

    There was once a PHP import I think (long time ago) but it got removed somewhere along the line.

  • Yes please! This would be very useful. Why have both JSON and PHP? The ability to import via PHP exports would be ideal.

  • Hi @blizzrdof77

    This is an old topic. I don’t think PHP imports will be implemented as it’s replaced by JSON. Nowadays you can export in JSON and import in JSON.

    The PHP export is now more of an “Code generator” when you want to implement the acf fields directly from code.

  • Jonathan,
    This is an old topic, but I don’t believe the core issue (if we want to call it that) has been addressed.

    While there is a JSON import function, it serves the same purpose as the old xml import functionality, correct?

    The core use case for me is when I have a few hundred lines of ACF code in my functions.php and I want to either edit an existing ACF field or add a new ACF field to an existing field group. My workflow to do that right now is to:

    1. create the field via the ACF WP admin functionality
    2. export that field via php
    3. copy the portions of the php export code that I will use
    4. paste the appropriate php code into the appropriate place in functions.php

    This is doable, but it _is_ definitely cumbersome.

    I don’t know how many people have this issue, but it is definitely an issue that deserves to be prioritized amongst other priorities (maybe it’s the lowest priority and never gets the feature build, but it should be on the list imho). 🙂

  • There isn’t an way to import field groups from PHP and like @jonathan says, this is not likely to be something that the developer builds in. Anything to do this is going to be work. There are several ways.

    The first you mentioned, create a new field, export it and copy/paste the new field.

    another way is to just copy and paste an existing field definition that is similar to the new one you want and then edit the settings, make up a field key that will be unique.

    If you want to be able to work on the field then you can export the field yourself as JSON to import it. After the code that creates your field group is done and the field group is ready do the following

    
    $path = '/abs/folder/path/where/you/want/file/saved/';
    $json = acf_json_encode($group);
    $file_path = $path.$group['key'].'.json';
    $handle = fopen($file_path, 'w');
    fwrite($handle, $json);
    fclose($handle);
    

    Something that I like to do when working on field groups is to create a local json folder in the them. This way the groups are automatically saved for me whenever I edit them. Then I save the files with the rest of the assets for a site or project. This way if I ever need to modify them I can simply import from this file and make the needed changes.

  • I’d also suggest to use this plugin which’ll make it easy to split up ACF JSON in separate locations (usually plugins). We’re currently using it in a massive project where we have 10-15 of our own plugins and most of them have their own ACF JSON files.

    https://github.com/khromov/acf-local-json-manager

  • Nice link Jonathan, I haven’t seen that before. That will be a whole lot easier than constantly copying the fields from the theme folder to my plugin folder every time I make a change.

  • John and Jonathan,
    Really interesting stuff! Thanks for sharing. I wasn’t aware of the local-json functionality (https://www.advancedcustomfields.com/resources/local-json/).

    local-json seems promising to solve the issue I describe, but it does appear that it has a way to go (thankfully, it appears that the ACF team is looking to round out its functionality).

    Thanks for sharing your ideas,
    Toby

  • @themightymo
    Just out of curiosity, what specific things do you feel lacking? I’ve not really felt I’m missing anything.

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

You must be logged in to reply to this topic.