Support

Account

Home Forums Feature Requests ACF Generator php class

Solving

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/

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

The topic ‘ACF Generator php class’ is closed to new replies.