Home › Forums › Feature Requests › ACF Generator php class
Has anybody made a php class that helps generate acf fields in php?
The thought comes to mind every time I open my custom fields file. For one of my projects its 3300 lines long! It becomes a bear to manage sometimes.
A php generator class would make it a little more compact to generate fields. something like this for example:
$generator = new AcfGenerator('field-group-id' ,'Field Group Name');
$generator->addTextField("Field Label", "optional-field-name", array("formatting" => "html"));
Which would be the same as writing out something similar to this
register_field_group(array (
'id' => 'acf_field-group-id',
'title' => 'Field Group Name',
'fields' => array (
array (
'key' => 'field_530e74135f6',
'label' => 'Field Label',
'name' => 'optional-field-name',
'type' => 'text',
'default_value' => '',
'placeholder' => '',
'prepend' => '',
'append' => '',
'formatting' => 'html',
'maxlength' => '',
),
),
'options' => array (
'position' => 'normal',
'layout' => 'default ',
'hide_on_screen' => array (
),
),
'menu_order' => 0,
));
It could be refined even more, just a quick example of what I’m thinking of.
Just wondering if anybody has started working on something like this and to see what other developers think.
I am thinking of exactly this – might end up writing one for our internal workflow. Unless anything has come about since May 2014?
@blindmikey We’re going to do something similar using the Local JSON feature, which I believe was added in ACF 5 (in Dec 2014?):
http://www.advancedcustomfields.com/resources/local-json/
Each field group gets saved into its own file, so you never have to deal with large files full of fields. Unfortunately the JSON filenames aren’t very friendly, but the workflow is so clean (since 5.3.1) that you shouldn’t need to edit fields manually very often anyway.
Also see:
http://support.advancedcustomfields.com/forums/topic/the-acf-json-workflow/
The topic ‘ACF Generator php class’ is closed to new replies.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.