Home Forums General Issues Any best practice for making coding of ACF in PHP easier?


Any best practice for making coding of ACF in PHP easier?

  • We have a repeater field to output “rows” on a website, then in the row you can add flexible content fields for the different content types. We have quite a lot of flexible content fields, with lots of options.

    We decided to code this using PHP because its easier to add and remove content blocks when we create new sites.

    The file becomes quite large and complex due to nesting arrays to create a repeater, then a flexible content field, then the flexible content layouts, then each of the layout fields themselves.

    I am trying to split things out into functions to create the necessary field arrays to make it easier to manage.

    So I just wondered if anyone else has an efficient way to create complex fields in PHP that makes it easy to create and manage.

    Here is a Gist I created of our current code, as you can see its long, but I am splitting arrays out into functions in the hope its easier to manage

    I can probably remove a few more fields and relay on defaults to reduce code.

    P.S. I know object orientated approach may help but when I’m in a rush I just create functions, but not sure if the OO approach addresses my question.

  • I don’t think anyone has a best approach. With complex field groups and building them in php it has always translated into extremely complex code. I usually do everything in OOP, it’s the habbit I’ve fallen into, and even here it becomes complex.

    I have not tried this, but you might want to take a look at it. It’s not really for me because I dislike adding layers of abstraction that I need to figure out every time I look at my code, but it may offer a different solution for you acf Component Field They also have a pro version I think.

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

The topic ‘Any best practice for making coding of ACF in PHP easier?’ is closed to new replies.